Skip to content

Commit 215bfe5

Browse files
author
Richard Jones
committed
merge from HEAD
1 parent e1bf7c5 commit 215bfe5

File tree

2 files changed

+34
-27
lines changed

2 files changed

+34
-27
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.146.2.19 2004-11-10 22:26:07 richard Exp $
18+
#$Id: back_anydbm.py,v 1.146.2.20 2004-11-11 06:09:43 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
#
4747
# Now the database
@@ -2074,6 +2074,9 @@ def import_journals(self, entries):
20742074
if value is None:
20752075
pass
20762076
elif isinstance(prop, Date):
2077+
if type(value) == type(()):
2078+
print 'warning: invalid date tuple %r'%(value,)
2079+
value = Date( "2000-1-1" )
20772080
value = date.Date(value)
20782081
elif isinstance(prop, Interval):
20792082
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.12.2.2 2004-10-15 01:10:22 richard Exp $
18+
#$Id: blobfiles.py,v 1.12.2.3 2004-11-11 06:09:43 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.

0 commit comments

Comments
 (0)