Skip to content

Commit 5e07d46

Browse files
author
Richard Jones
committed
fixed back_bsddb so it passed the journal tests
... it didn't seem happy using the back_anydbm _open method, which is odd. Yet another occurrance of whichdb not being able to recognise older bsddb databases. Yadda yadda. Made the HYPERDBDEBUG stuff more sane in the process.
1 parent a8c4d1c commit 5e07d46

File tree

5 files changed

+68
-35
lines changed

5 files changed

+68
-35
lines changed

CHANGES.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Feature:
1818
Fixed:
1919
. handle attachments with no name (eg tnef)
2020
. fixed setting nosy as argument in subject line
21-
21+
. fixed back_bsddb so it passed the journal tests
2222

2323
2002-01-16 - 0.4.0b2
2424
Fixed:

roundup/backends/back_anydbm.py

Lines changed: 30 additions & 29 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.26 2002-01-22 05:18:38 rochecompaan Exp $
18+
#$Id: back_anydbm.py,v 1.27 2002-01-22 07:21:13 richard 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
@@ -26,8 +26,6 @@
2626
import whichdb, anydbm, os, marshal
2727
from roundup import hyperdb, date, password
2828

29-
DEBUG=os.environ.get('HYPERDBDEBUG', '')
30-
3129
#
3230
# Now the database
3331
#
@@ -71,13 +69,13 @@ def __repr__(self):
7169
def __getattr__(self, classname):
7270
"""A convenient way of calling self.getclass(classname)."""
7371
if self.classes.has_key(classname):
74-
if DEBUG:
72+
if hyperdb.DEBUG:
7573
print '__getattr__', (self, classname)
7674
return self.classes[classname]
7775
raise AttributeError, classname
7876

7977
def addclass(self, cl):
80-
if DEBUG:
78+
if hyperdb.DEBUG:
8179
print 'addclass', (self, cl)
8280
cn = cl.classname
8381
if self.classes.has_key(cn):
@@ -86,7 +84,7 @@ def addclass(self, cl):
8684

8785
def getclasses(self):
8886
"""Return a list of the names of all existing classes."""
89-
if DEBUG:
87+
if hyperdb.DEBUG:
9088
print 'getclasses', (self,)
9189
l = self.classes.keys()
9290
l.sort()
@@ -97,7 +95,7 @@ def getclass(self, classname):
9795
9896
If 'classname' is not a valid class name, a KeyError is raised.
9997
"""
100-
if DEBUG:
98+
if hyperdb.DEBUG:
10199
print 'getclass', (self, classname)
102100
return self.classes[classname]
103101

@@ -107,7 +105,7 @@ def getclass(self, classname):
107105
def clear(self):
108106
'''Delete all database contents
109107
'''
110-
if DEBUG:
108+
if hyperdb.DEBUG:
111109
print 'clear', (self,)
112110
for cn in self.classes.keys():
113111
for type in 'nodes', 'journals':
@@ -121,15 +119,15 @@ def getclassdb(self, classname, mode='r'):
121119
''' grab a connection to the class db that will be used for
122120
multiple actions
123121
'''
124-
if DEBUG:
122+
if hyperdb.DEBUG:
125123
print 'getclassdb', (self, classname, mode)
126124
return self._opendb('nodes.%s'%classname, mode)
127125

128126
def _opendb(self, name, mode):
129127
'''Low-level database opener that gets around anydbm/dbm
130128
eccentricities.
131129
'''
132-
if DEBUG:
130+
if hyperdb.DEBUG:
133131
print '_opendb', (self, name, mode)
134132
# determine which DB wrote the class file
135133
db_type = ''
@@ -145,7 +143,7 @@ def _opendb(self, name, mode):
145143

146144
# new database? let anydbm pick the best dbm
147145
if not db_type:
148-
if DEBUG:
146+
if hyperdb.DEBUG:
149147
print "_opendb anydbm.open(%r, 'n')"%path
150148
return anydbm.open(path, 'n')
151149

@@ -156,7 +154,7 @@ def _opendb(self, name, mode):
156154
raise hyperdb.DatabaseError, \
157155
"Couldn't open database - the required module '%s'"\
158156
"is not available"%db_type
159-
if DEBUG:
157+
if hyperdb.DEBUG:
160158
print "_opendb %r.open(%r, %r)"%(db_type, path, mode)
161159
return dbm.open(path, mode)
162160

@@ -166,7 +164,7 @@ def _opendb(self, name, mode):
166164
def addnode(self, classname, nodeid, node):
167165
''' add the specified node to its class's db
168166
'''
169-
if DEBUG:
167+
if hyperdb.DEBUG:
170168
print 'addnode', (self, classname, nodeid, node)
171169
self.newnodes.setdefault(classname, {})[nodeid] = 1
172170
self.cache.setdefault(classname, {})[nodeid] = node
@@ -175,7 +173,7 @@ def addnode(self, classname, nodeid, node):
175173
def setnode(self, classname, nodeid, node):
176174
''' change the specified node
177175
'''
178-
if DEBUG:
176+
if hyperdb.DEBUG:
179177
print 'setnode', (self, classname, nodeid, node)
180178
self.dirtynodes.setdefault(classname, {})[nodeid] = 1
181179
# can't set without having already loaded the node
@@ -185,15 +183,15 @@ def setnode(self, classname, nodeid, node):
185183
def savenode(self, classname, nodeid, node):
186184
''' perform the saving of data specified by the set/addnode
187185
'''
188-
if DEBUG:
186+
if hyperdb.DEBUG:
189187
print 'savenode', (self, classname, nodeid, node)
190188
self.transactions.append((self._doSaveNode, (classname, nodeid, node)))
191189

192190
def getnode(self, classname, nodeid, db=None, cache=1):
193191
''' get a node from the database
194192
'''
195-
if DEBUG:
196-
print 'getnode', (self, classname, nodeid, cldb)
193+
if hyperdb.DEBUG:
194+
print 'getnode', (self, classname, nodeid, db)
197195
if cache:
198196
# try the cache
199197
cache = self.cache.setdefault(classname, {})
@@ -213,8 +211,8 @@ def getnode(self, classname, nodeid, db=None, cache=1):
213211
def hasnode(self, classname, nodeid, db=None):
214212
''' determine if the database has a given node
215213
'''
216-
if DEBUG:
217-
print 'hasnode', (self, classname, nodeid, cldb)
214+
if hyperdb.DEBUG:
215+
print 'hasnode', (self, classname, nodeid, db)
218216
# try the cache
219217
cache = self.cache.setdefault(classname, {})
220218
if cache.has_key(nodeid):
@@ -227,8 +225,8 @@ def hasnode(self, classname, nodeid, db=None):
227225
return res
228226

229227
def countnodes(self, classname, db=None):
230-
if DEBUG:
231-
print 'countnodes', (self, classname, cldb)
228+
if hyperdb.DEBUG:
229+
print 'countnodes', (self, classname, db)
232230
# include the new nodes not saved to the DB yet
233231
count = len(self.newnodes.get(classname, {}))
234232

@@ -239,7 +237,7 @@ def countnodes(self, classname, db=None):
239237
return count
240238

241239
def getnodeids(self, classname, db=None):
242-
if DEBUG:
240+
if hyperdb.DEBUG:
243241
print 'getnodeids', (self, classname, db)
244242
# start off with the new nodes
245243
res = self.newnodes.get(classname, {}).keys()
@@ -294,15 +292,15 @@ def addjournal(self, classname, nodeid, action, params):
294292
'link' or 'unlink' -- 'params' is (classname, nodeid, propname)
295293
'retire' -- 'params' is None
296294
'''
297-
if DEBUG:
295+
if hyperdb.DEBUG:
298296
print 'addjournal', (self, classname, nodeid, action, params)
299297
self.transactions.append((self._doSaveJournal, (classname, nodeid,
300298
action, params)))
301299

302300
def getjournal(self, classname, nodeid):
303301
''' get the journal for id
304302
'''
305-
if DEBUG:
303+
if hyperdb.DEBUG:
306304
print 'getjournal', (self, classname, nodeid)
307305
# attempt to open the journal - in some rare cases, the journal may
308306
# not exist
@@ -322,7 +320,7 @@ def getjournal(self, classname, nodeid):
322320

323321
def pack(self, pack_before):
324322
''' delete all journal entries before 'pack_before' '''
325-
if DEBUG:
323+
if hyperdb.DEBUG:
326324
print 'packjournal', (self, pack_before)
327325

328326
pack_before = pack_before.get_tuple()
@@ -375,7 +373,7 @@ def pack(self, pack_before):
375373
def commit(self):
376374
''' Commit the current transactions.
377375
'''
378-
if DEBUG:
376+
if hyperdb.DEBUG:
379377
print 'commit', (self,)
380378
# TODO: lock the DB
381379

@@ -399,7 +397,7 @@ def commit(self):
399397
self.transactions = []
400398

401399
def _doSaveNode(self, classname, nodeid, node):
402-
if DEBUG:
400+
if hyperdb.DEBUG:
403401
print '_doSaveNode', (self, classname, nodeid, node)
404402

405403
# get the database handle
@@ -413,7 +411,7 @@ def _doSaveNode(self, classname, nodeid, node):
413411
db[nodeid] = marshal.dumps(node)
414412

415413
def _doSaveJournal(self, classname, nodeid, action, params):
416-
if DEBUG:
414+
if hyperdb.DEBUG:
417415
print '_doSaveJournal', (self, classname, nodeid, action, params)
418416
entry = (nodeid, date.Date().get_tuple(), self.journaltag, action,
419417
params)
@@ -441,7 +439,7 @@ def _doStoreFile(self, name, **databases):
441439
def rollback(self):
442440
''' Reverse all actions from the current transaction.
443441
'''
444-
if DEBUG:
442+
if hyperdb.DEBUG:
445443
print 'rollback', (self, )
446444
for method, args in self.transactions:
447445
# delete temporary files
@@ -455,6 +453,9 @@ def rollback(self):
455453

456454
#
457455
#$Log: not supported by cvs2svn $
456+
#Revision 1.26 2002/01/22 05:18:38 rochecompaan
457+
#last_set_entry was referenced before assignment
458+
#
458459
#Revision 1.25 2002/01/22 05:06:08 rochecompaan
459460
#We need to keep the last 'set' entry in the journal to preserve
460461
#information on 'activity' for nodes.

roundup/backends/back_bsddb.py

Lines changed: 26 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: back_bsddb.py,v 1.13 2001-12-10 22:20:01 richard Exp $
18+
#$Id: back_bsddb.py,v 1.14 2002-01-22 07:21:13 richard Exp $
1919
'''
2020
This module defines a backend that saves the hyperdatabase in BSDDB.
2121
'''
@@ -51,6 +51,24 @@ def getclassdb(self, classname, mode='r'):
5151
else:
5252
return bsddb.btopen(path, 'n')
5353

54+
def _opendb(self, name, mode):
55+
'''Low-level database opener that gets around anydbm/dbm
56+
eccentricities.
57+
'''
58+
if hyperdb.DEBUG:
59+
print self, '_opendb', (self, name, mode)
60+
# determine which DB wrote the class file
61+
path = os.path.join(os.getcwd(), self.dir, name)
62+
if not os.path.exists(path):
63+
if hyperdb.DEBUG:
64+
print "_opendb bsddb.open(%r, 'n')"%path
65+
return bsddb.btopen(path, 'n')
66+
67+
# open the database with the correct module
68+
if hyperdb.DEBUG:
69+
print "_opendb bsddb.open(%r, %r)"%(path, mode)
70+
return bsddb.btopen(path, mode)
71+
5472
#
5573
# Journal
5674
#
@@ -91,6 +109,13 @@ def _doSaveJournal(self, classname, nodeid, action, params):
91109

92110
#
93111
#$Log: not supported by cvs2svn $
112+
#Revision 1.13 2001/12/10 22:20:01 richard
113+
#Enabled transaction support in the bsddb backend. It uses the anydbm code
114+
#where possible, only replacing methods where the db is opened (it uses the
115+
#btree opener specifically.)
116+
#Also cleaned up some change note generation.
117+
#Made the backends package work with pydoc too.
118+
#
94119
#Revision 1.12 2001/11/21 02:34:18 richard
95120
#Added a target version field to the extended issue schema
96121
#

roundup/hyperdb.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,19 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: hyperdb.py,v 1.52 2002-01-21 16:33:19 rochecompaan Exp $
18+
# $Id: hyperdb.py,v 1.53 2002-01-22 07:21:13 richard Exp $
1919

2020
__doc__ = """
2121
Hyperdatabase implementation, especially field types.
2222
"""
2323

2424
# standard python modules
25-
import cPickle, re, string, weakref
25+
import cPickle, re, string, weakref, os
2626

2727
# roundup modules
2828
import date, password
2929

30+
DEBUG = os.environ.get('HYPERDBDEBUG', '')
3031

3132
#
3233
# Types
@@ -1065,6 +1066,9 @@ def Choice(name, *options):
10651066

10661067
#
10671068
# $Log: not supported by cvs2svn $
1069+
# Revision 1.52 2002/01/21 16:33:19 rochecompaan
1070+
# You can now use the roundup-admin tool to pack the database
1071+
#
10681072
# Revision 1.51 2002/01/21 03:01:29 richard
10691073
# brief docco on the do_journal argument
10701074
#

test/test_db.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: test_db.py,v 1.17 2002-01-22 05:06:09 rochecompaan Exp $
18+
# $Id: test_db.py,v 1.18 2002-01-22 07:21:13 richard Exp $
1919

2020
import unittest, os, shutil
2121

@@ -246,7 +246,6 @@ def testPack(self):
246246
self.db.commit()
247247
self.db.issue.set('1', status='3')
248248
self.db.commit()
249-
250249
pack_before = date.Date(". + 1d")
251250
self.db.pack(pack_before)
252251
journal = self.db.getjournal('issue', '1')
@@ -347,6 +346,10 @@ def suite():
347346

348347
#
349348
# $Log: not supported by cvs2svn $
349+
# Revision 1.17 2002/01/22 05:06:09 rochecompaan
350+
# We need to keep the last 'set' entry in the journal to preserve
351+
# information on 'activity' for nodes.
352+
#
350353
# Revision 1.16 2002/01/21 16:33:20 rochecompaan
351354
# You can now use the roundup-admin tool to pack the database
352355
#

0 commit comments

Comments
 (0)