Code

help for winzip users
[roundup.git] / roundup / backends / back_bsddb3.py
index f894047ea6c2ea9710e19a6d1711495e33f4c6c1..dbf8675e42b8e5684f6afa249de3021d07c50ed3 100644 (file)
 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 # 
-#$Id: back_bsddb3.py,v 1.18 2002-10-03 06:56:29 richard Exp $
-'''
-This module defines a backend that saves the hyperdatabase in BSDDB3.
+#$Id: back_bsddb3.py,v 1.22 2004-02-11 23:55:08 richard Exp $
+'''This module defines a backend that saves the hyperdatabase in BSDDB3.
 '''
+__docformat__ = 'restructuredtext'
 
 import bsddb3, os, marshal
 from roundup import hyperdb, date
@@ -74,24 +74,54 @@ class Database(Database):
     #
     def getjournal(self, classname, nodeid):
         ''' get the journal for id
+
+            Raise IndexError if the node doesn't exist (as per history()'s
+            API)
         '''
+        if __debug__:
+            print >>hyperdb.DEBUG, 'getjournal', (self, classname, nodeid)
+
+        # our journal result
+        res = []
+
+        # add any journal entries for transactions not committed to the
+        # database
+        for method, args in self.transactions:
+            if method != self.doSaveJournal:
+                continue
+            (cache_classname, cache_nodeid, cache_action, cache_params,
+                cache_creator, cache_creation) = args
+            if cache_classname == classname and cache_nodeid == nodeid:
+                if not cache_creator:
+                    cache_creator = self.getuid()
+                if not cache_creation:
+                    cache_creation = date.Date()
+                res.append((cache_nodeid, cache_creation, cache_creator,
+                    cache_action, cache_params))
+
         # attempt to open the journal - in some rare cases, the journal may
         # not exist
         try:
             db = bsddb3.btopen(os.path.join(self.dir, 'journals.%s'%classname),
                 'r')
         except bsddb3._db.DBNoSuchFileError:
+            if res:
+                # we have unsaved journal entries, return them
+                return res
             raise IndexError, 'no such %s %s'%(classname, nodeid)
         # more handling of bad journals
         if not db.has_key(nodeid):
+            db.close()
+            if res:
+                # we have some unsaved journal entries, be happy!
+                return res
             raise IndexError, 'no such %s %s'%(classname, nodeid)
         journal = marshal.loads(db[nodeid])
-        res = []
-        for entry in journal:
-            (nodeid, date_stamp, user, action, params) = entry
-            date_obj = date.Date(date_stamp)
-            res.append((nodeid, date_obj, user, action, params))
         db.close()
+
+        # add all the saved journal entries for this node
+        for nodeid, date_stamp, user, action, params in journal:
+            res.append((nodeid, date.Date(date_stamp), user, action, params))
         return res
 
     def getCachedJournalDB(self, classname):