Skip to content

Commit e55c602

Browse files
author
Richard Jones
committed
Handle older (really older) anydbm databases in export code.
Handle really old file stores too.
1 parent 3cbfe49 commit e55c602

File tree

3 files changed

+44
-28
lines changed

3 files changed

+44
-28
lines changed

roundup/backends/back_anydbm.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
#$Id: back_anydbm.py,v 1.174 2004-11-10 22:22:58 richard Exp $
18+
#$Id: back_anydbm.py,v 1.175 2004-11-11 06:04:58 richard Exp $
1919
'''This module defines a backend that saves the hyperdatabase in a
2020
database chosen by anydbm. It is guaranteed to always be available in python
2121
versions >2.1.1 (the dumbdbm fallback in 2.1.1 and earlier has several
@@ -41,7 +41,7 @@
4141
from roundup.backends import locking
4242
from roundup.hyperdb import String, Password, Date, Interval, Link, \
4343
Multilink, DatabaseError, Boolean, Number, Node
44-
from roundup.date import Range
44+
from roundup.date import Range, Date
4545

4646
def db_exists(config):
4747
# check for the user db
@@ -2046,6 +2046,9 @@ def import_journals(self, entries):
20462046
if value is None:
20472047
pass
20482048
elif isinstance(prop, Date):
2049+
if type(value) == type(()):
2050+
print 'warning: invalid date tuple %r'%(value,)
2051+
value = Date( "2000-1-1" )
20492052
value = date.Date(value)
20502053
elif isinstance(prop, Interval):
20512054
value = date.Interval(value)

roundup/backends/blobfiles.py

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
#$Id: blobfiles.py,v 1.13 2004-06-24 06:39:07 richard Exp $
18+
#$Id: blobfiles.py,v 1.14 2004-11-11 06:04:59 richard Exp $
1919
'''This module exports file storage for roundup backends.
2020
Files are stored into a directory hierarchy.
2121
'''
@@ -39,7 +39,11 @@ class FileStorage:
3939
"""Store files in some directory structure"""
4040
def filename(self, classname, nodeid, property=None):
4141
'''Determine what the filename for the given node and optionally
42-
property is.
42+
property is.
43+
44+
Try a variety of different filenames - the file could be in the
45+
usual place, or it could be in a temp file pre-commit *or* it
46+
could be in an old-style, backwards-compatible flat directory.
4347
'''
4448
if property:
4549
name = '%s%s.%s'%(classname, nodeid, property)
@@ -50,20 +54,27 @@ def filename(self, classname, nodeid, property=None):
5054

5155
# have a separate subdir for every thousand messages
5256
subdir = str(int(nodeid) / 1000)
53-
return os.path.join(self.dir, 'files', classname, subdir, name)
57+
filename = os.path.join(self.dir, 'files', classname, subdir, name)
58+
if os.path.exists(filename):
59+
return filename
5460

55-
def filename_flat(self, classname, nodeid, property=None):
56-
'''Determine what the filename for the given node and optionally
57-
property is.
58-
'''
61+
# try .tmp
62+
filename = filename + '.tmp'
63+
if os.path.exists(filename):
64+
return filename
65+
66+
# ok, try flat (very old-style)
5967
if property:
60-
return os.path.join(self.dir, 'files', '%s%s.%s'%(classname,
68+
filename = os.path.join(self.dir, 'files', '%s%s.%s'%(classname,
6169
nodeid, property))
6270
else:
63-
# roundupdb.FileClass never specified the property name, so don't
64-
# include it
65-
return os.path.join(self.dir, 'files', '%s%s'%(classname,
71+
filename = os.path.join(self.dir, 'files', '%s%s'%(classname,
6672
nodeid))
73+
if os.path.exists(filename):
74+
return filename
75+
76+
# file just ain't there
77+
raise IOError, 'content file for %s not found'%name
6778

6879
def storefile(self, classname, nodeid, property, content):
6980
'''Store the content of the file in the database. The property may be
@@ -89,21 +100,14 @@ def storefile(self, classname, nodeid, property, content):
89100
def getfile(self, classname, nodeid, property):
90101
'''Get the content of the file in the database.
91102
'''
92-
# try a variety of different filenames - the file could be in the
93-
# usual place, or it could be in a temp file pre-commit *or* it
94-
# could be in an old-style, backwards-compatible flat directory
95103
filename = self.filename(classname, nodeid, property)
96-
flat_filename = self.filename_flat(classname, nodeid, property)
97-
for filename in (filename, filename+'.tmp', flat_filename):
98-
if os.path.exists(filename):
99-
f = open(filename, 'rb')
100-
break
101-
else:
102-
raise IOError, 'content file not found'
103-
# snarf the contents and make sure we close the file
104-
content = f.read()
105-
f.close()
106-
return content
104+
105+
f = open(filename, 'rb')
106+
try:
107+
# snarf the contents and make sure we close the file
108+
return f.read()
109+
finally:
110+
f.close()
107111

108112
def numfiles(self):
109113
'''Get number of files in storage, even across subdirectories.

test/db_test_base.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: db_test_base.py,v 1.52 2004-11-05 05:10:07 richard Exp $
18+
# $Id: db_test_base.py,v 1.53 2004-11-11 06:04:59 richard Exp $
1919

2020
import unittest, os, shutil, errno, imp, sys, time, pprint
2121

@@ -235,6 +235,15 @@ def testMultilinkChange(self):
235235
m = self.db.issue.get(nid, "nosy"); m.sort()
236236
self.assertEqual(l, m)
237237

238+
def testMultilinkOrdering(self):
239+
for i in range(10):
240+
self.db.user.create(username='foo%s'%i)
241+
i = self.db.issue.create(title="spam", nosy=['5','3','12','4'])
242+
self.db.commit()
243+
l = self.db.issue.get(i, "nosy")
244+
# all backends should return the Multilink numeric-id-sorted
245+
self.assertEqual(l, ['3', '4', '5', '12'])
246+
238247
# Date
239248
def testDateChange(self):
240249
self.assertRaises(TypeError, self.db.issue.create,

0 commit comments

Comments
 (0)