Skip to content

Commit 7438585

Browse files
author
Engelbert Gruber
committed
use blobfiles in back_anydbm which is used in back_bsddb.
change test_db as dirlist does not work for subdirectories. ATTENTION: blobfiles now creates subdirectories for files.
1 parent f48d66c commit 7438585

File tree

5 files changed

+41
-47
lines changed

5 files changed

+41
-47
lines changed

CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ are given with the most recent entry first.
33

44
2002-02-?? - 0.4.1
55
Feature:
6+
. use blobfiles in back_anydbm which is used in back_bsddb.
7+
change test_db as dirlist does not work for subdirectories.
8+
ATTENTION: blobfiles now creates subdirectories for files.
69
. add module blobfiles in backends with file access functions.
710
. roundup db catch only IOError in getfile.
811
. roundup db catches retrieving not existing files.

MIGRATION.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ This file contains information for users upgrading from:
99
0.3.x -> 0.4.x
1010
0.2.x -> 0.3.x
1111

12+
From CVS
13+
========
14+
15+
Files storage
16+
-------------
17+
18+
Messages and files from newly created issues will be put into subdierectories
19+
in thousands e.g. msg123 will be put into files/msg/0/msg123, file2003
20+
will go into files/file/2/file2003. Previous messages are still found, but
21+
could be put into this structure.
1222

1323
Migrating from 0.4.0 to 0.4.1
1424
=============================

README.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ in general:
5151
. more back-ends
5252
hyperdb:
5353
. more efficient reverse lookups
54-
roundupdb:
55-
. split the file storage into multiple dirs?
5654
roundup-server:
5755
. check the source file timestamps before reloading
5856
cgi_client

roundup/backends/back_anydbm.py

Lines changed: 7 additions & 32 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.28 2002-02-16 09:14:17 richard Exp $
18+
#$Id: back_anydbm.py,v 1.29 2002-02-25 14:34:31 grubert Exp $
1919
'''
2020
This module defines a backend that saves the hyperdatabase in a database
2121
chosen by anydbm. It is guaranteed to always be available in python
@@ -25,11 +25,12 @@
2525

2626
import whichdb, anydbm, os, marshal
2727
from roundup import hyperdb, date, password
28+
from blobfiles import FileStorage
2829

2930
#
3031
# Now the database
3132
#
32-
class Database(hyperdb.Database):
33+
class Database(FileStorage, hyperdb.Database):
3334
"""A database for storing records containing flexible data types.
3435
3536
Transaction stuff TODO:
@@ -250,36 +251,7 @@ def getnodeids(self, classname, db=None):
250251

251252
#
252253
# Files - special node properties
253-
#
254-
def filename(self, classname, nodeid, property=None):
255-
'''Determine what the filename for the given node and optionally property is.
256-
'''
257-
# TODO: split into multiple files directories
258-
if property:
259-
return os.path.join(self.dir, 'files', '%s%s.%s'%(classname,
260-
nodeid, property))
261-
else:
262-
# roundupdb.FileClass never specified the property name, so don't include it
263-
return os.path.join(self.dir, 'files', '%s%s'%(classname,
264-
nodeid))
265-
266-
def storefile(self, classname, nodeid, property, content):
267-
'''Store the content of the file in the database. The property may be None, in
268-
which case the filename does not indicate which property is being saved.
269-
'''
270-
name = self.filename(classname, nodeid, property)
271-
open(name + '.tmp', 'wb').write(content)
272-
self.transactions.append((self._doStoreFile, (name, )))
273-
274-
def getfile(self, classname, nodeid, property):
275-
'''Store the content of the file in the database.
276-
'''
277-
filename = self.filename(classname, nodeid, property)
278-
try:
279-
return open(filename, 'rb').read()
280-
except:
281-
return open(filename+'.tmp', 'rb').read()
282-
254+
# inherited from FileStorage
283255

284256
#
285257
# Journal
@@ -453,6 +425,9 @@ def rollback(self):
453425

454426
#
455427
#$Log: not supported by cvs2svn $
428+
#Revision 1.28 2002/02/16 09:14:17 richard
429+
# . #514854 ] History: "User" is always ticket creator
430+
#
456431
#Revision 1.27 2002/01/22 07:21:13 richard
457432
#. fixed back_bsddb so it passed the journal tests
458433
#

test/test_db.py

Lines changed: 21 additions & 13 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: test_db.py,v 1.18 2002-01-22 07:21:13 richard Exp $
18+
# $Id: test_db.py,v 1.19 2002-02-25 14:34:31 grubert Exp $
1919

2020
import unittest, os, shutil
2121

@@ -99,12 +99,9 @@ def testChanges(self):
9999
self.db.status.history('2')
100100

101101
def testTransactions(self):
102+
# remember the number of items we started
102103
num_issues = len(self.db.issue.list())
103-
files_dir = os.path.join('_test_dir', 'files')
104-
if os.path.exists(files_dir):
105-
num_files = len(os.listdir(files_dir))
106-
else:
107-
num_files = 0
104+
num_files = self.db.numfiles()
108105
self.db.issue.create(title="don't commit me!", status='1')
109106
self.assertNotEqual(num_issues, len(self.db.issue.list()))
110107
self.db.rollback()
@@ -117,15 +114,18 @@ def testTransactions(self):
117114
self.assertNotEqual(num_issues, len(self.db.issue.list()))
118115
self.db.file.create(name="test", type="text/plain", content="hi")
119116
self.db.rollback()
120-
self.assertEqual(num_files, len(os.listdir(files_dir)))
121-
self.db.file.create(name="test", type="text/plain", content="hi")
122-
self.db.commit()
123-
self.assertNotEqual(num_files, len(os.listdir(files_dir)))
124-
num_files2 = len(os.listdir(files_dir))
117+
self.assertEqual(num_files, self.db.numfiles())
118+
for i in range(10):
119+
self.db.file.create(name="test", type="text/plain",
120+
content="hi %d"%(i))
121+
self.db.commit()
122+
num_files2 = self.db.numfiles()
123+
self.assertNotEqual(num_files, num_files2)
125124
self.db.file.create(name="test", type="text/plain", content="hi")
126125
self.db.rollback()
127-
self.assertNotEqual(num_files, len(os.listdir(files_dir)))
128-
self.assertEqual(num_files2, len(os.listdir(files_dir)))
126+
self.assertNotEqual(num_files, self.db.numfiles())
127+
self.assertEqual(num_files2, self.db.numfiles())
128+
129129

130130

131131
def testExceptions(self):
@@ -346,6 +346,14 @@ def suite():
346346

347347
#
348348
# $Log: not supported by cvs2svn $
349+
# Revision 1.18 2002/01/22 07:21:13 richard
350+
# . fixed back_bsddb so it passed the journal tests
351+
#
352+
# ... it didn't seem happy using the back_anydbm _open method, which is odd.
353+
# Yet another occurrance of whichdb not being able to recognise older bsddb
354+
# databases. Yadda yadda. Made the HYPERDBDEBUG stuff more sane in the
355+
# process.
356+
#
349357
# Revision 1.17 2002/01/22 05:06:09 rochecompaan
350358
# We need to keep the last 'set' entry in the journal to preserve
351359
# information on 'activity' for nodes.

0 commit comments

Comments
 (0)