X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=roundup%2Fbackends%2Fback_bsddb.py;h=6f7aa9d7a15dd5a153282e3c9185b7878cab6109;hb=f33816f46bf6fec4906e05ad93a8fbc493fdda98;hp=61ed0619e1cb522ea95fa92eb688c7ade6ed4fae;hpb=eac706a774241b4357c5d12ecf42e9a8686a5ce9;p=roundup.git diff --git a/roundup/backends/back_bsddb.py b/roundup/backends/back_bsddb.py index 61ed061..6f7aa9d 100644 --- a/roundup/backends/back_bsddb.py +++ b/roundup/backends/back_bsddb.py @@ -15,21 +15,21 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -#$Id: back_bsddb.py,v 1.14 2002-01-22 07:21:13 richard Exp $ +#$Id: back_bsddb.py,v 1.24 2002-09-13 08:20:11 richard Exp $ ''' This module defines a backend that saves the hyperdatabase in BSDDB. ''' import bsddb, os, marshal -from roundup import hyperdb, date, password +from roundup import hyperdb, date # these classes are so similar, we just use the anydbm methods -import back_anydbm +from back_anydbm import Database, Class, FileClass, IssueClass # # Now the database # -class Database(back_anydbm.Database): +class Database(Database): """A database for storing records containing flexible data types.""" # # Class DBs @@ -49,24 +49,24 @@ class Database(back_anydbm.Database): if os.path.exists(path): return bsddb.btopen(path, mode) else: - return bsddb.btopen(path, 'n') + return bsddb.btopen(path, 'c') - def _opendb(self, name, mode): + def opendb(self, name, mode): '''Low-level database opener that gets around anydbm/dbm eccentricities. ''' - if hyperdb.DEBUG: - print self, '_opendb', (self, name, mode) + if __debug__: + print >>hyperdb.DEBUG, self, 'opendb', (self, name, mode) # determine which DB wrote the class file path = os.path.join(os.getcwd(), self.dir, name) if not os.path.exists(path): - if hyperdb.DEBUG: - print "_opendb bsddb.open(%r, 'n')"%path - return bsddb.btopen(path, 'n') + if __debug__: + print >>hyperdb.DEBUG, "opendb bsddb.open(%r, 'c')"%path + return bsddb.btopen(path, 'c') # open the database with the correct module - if hyperdb.DEBUG: - print "_opendb bsddb.open(%r, %r)"%(path, mode) + if __debug__: + print >>hyperdb.DEBUG, "opendb bsddb.open(%r, %r)"%(path, mode) return bsddb.btopen(path, mode) # @@ -82,93 +82,28 @@ class Database(back_anydbm.Database): 'r') except bsddb.error, error: if error.args[0] != 2: raise - return [] - # mor handling of bad journals - if not db.has_key(nodeid): return [] + raise IndexError, 'no such %s %s'%(classname, nodeid) + # more handling of bad journals + if not db.has_key(nodeid): + raise IndexError, 'no such %s %s'%(classname, nodeid) journal = marshal.loads(db[nodeid]) res = [] for entry in journal: - (nodeid, date_stamp, self.journaltag, action, params) = entry + (nodeid, date_stamp, user, action, params) = entry date_obj = date.Date(date_stamp) - res.append((nodeid, date_obj, self.journaltag, action, params)) + res.append((nodeid, date_obj, user, action, params)) db.close() return res - def _doSaveJournal(self, classname, nodeid, action, params): - entry = (nodeid, date.Date().get_tuple(), self.journaltag, action, - params) - db = bsddb.btopen(os.path.join(self.dir, 'journals.%s'%classname), 'c') - if db.has_key(nodeid): - s = db[nodeid] - l = marshal.loads(db[nodeid]) - l.append(entry) + def getCachedJournalDB(self, classname): + ''' get the journal db, looking in our cache of databases for commit + ''' + # get the database handle + db_name = 'journals.%s'%classname + if self.databases.has_key(db_name): + return self.databases[db_name] else: - l = [entry] - db[nodeid] = marshal.dumps(l) - db.close() + db = bsddb.btopen(os.path.join(self.dir, db_name), 'c') + self.databases[db_name] = db + return db -# -#$Log: not supported by cvs2svn $ -#Revision 1.13 2001/12/10 22:20:01 richard -#Enabled transaction support in the bsddb backend. It uses the anydbm code -#where possible, only replacing methods where the db is opened (it uses the -#btree opener specifically.) -#Also cleaned up some change note generation. -#Made the backends package work with pydoc too. -# -#Revision 1.12 2001/11/21 02:34:18 richard -#Added a target version field to the extended issue schema -# -#Revision 1.11 2001/10/09 23:58:10 richard -#Moved the data stringification up into the hyperdb.Class class' get, set -#and create methods. This means that the data is also stringified for the -#journal call, and removes duplication of code from the backends. The -#backend code now only sees strings. -# -#Revision 1.10 2001/10/09 07:25:59 richard -#Added the Password property type. See "pydoc roundup.password" for -#implementation details. Have updated some of the documentation too. -# -#Revision 1.9 2001/08/12 06:32:36 richard -#using isinstance(blah, Foo) now instead of isFooType -# -#Revision 1.8 2001/08/07 00:24:42 richard -#stupid typo -# -#Revision 1.7 2001/08/07 00:15:51 richard -#Added the copyright/license notice to (nearly) all files at request of -#Bizar Software. -# -#Revision 1.6 2001/07/30 02:36:23 richard -#Handle non-existence of db files in the other backends (code from anydbm). -# -#Revision 1.5 2001/07/30 01:41:36 richard -#Makes schema changes mucho easier. -# -#Revision 1.4 2001/07/23 08:25:33 richard -#more handling of bad journals -# -#Revision 1.3 2001/07/23 08:20:44 richard -#Moved over to using marshal in the bsddb and anydbm backends. -#roundup-admin now has a "freshen" command that'll load/save all nodes (not -# retired - mod hyperdb.Class.list() so it lists retired nodes) -# -#Revision 1.2 2001/07/23 07:56:05 richard -#Storing only marshallable data in the db - no nasty pickled class references. -# -#Revision 1.1 2001/07/23 07:22:13 richard -#*sigh* some databases have _foo.so as their underlying implementation. -#This time for sure, Rocky. -# -#Revision 1.1 2001/07/23 07:15:57 richard -#Moved the backends into the backends package. Anydbm hasn't been tested at all. -# -#Revision 1.1 2001/07/23 06:23:41 richard -#moved hyper_bsddb.py to the new backends package as bsddb.py -# -#Revision 1.2 2001/07/22 12:09:32 richard -#Final commit of Grande Splite -# -#Revision 1.1 2001/07/22 11:58:35 richard -#More Grande Splite -#