Code

- Remove implementations of Class.getnode from back_anydbm and rdbms_common,
[roundup.git] / roundup / backends / back_anydbm.py
index 0eaf60593f2816a38fe93eac8675de340d67e4c8..d6aebc43da3d022ad9d1a4cc8123de59a2cccdb8 100644 (file)
@@ -15,7 +15,7 @@
 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 # 
-#$Id: back_anydbm.py,v 1.126 2003-09-06 20:01:10 jlgijsbers Exp $
+#$Id: back_anydbm.py,v 1.132 2003-11-16 18:41:40 jlgijsbers Exp $
 '''
 This module defines a backend that saves the hyperdatabase in a database
 chosen by anydbm. It is guaranteed to always be available in python
@@ -23,7 +23,17 @@ versions >2.1.1 (the dumbdbm fallback in 2.1.1 and earlier has several
 serious bugs, and is not available)
 '''
 
-import whichdb, anydbm, os, marshal, re, weakref, string, copy
+try:
+    import anydbm, sys
+    # dumbdbm only works in python 2.1.2+
+    if sys.version_info < (2,1,2):
+        import dumbdbm
+        assert anydbm._defaultmod != dumbdbm
+        del dumbdbm
+except AssertionError:
+    print "WARNING: you should upgrade to python 2.1.3"
+
+import whichdb, os, marshal, re, weakref, string, copy
 from roundup import hyperdb, date, password, roundupdb, security
 from blobfiles import FileStorage
 from sessions import Sessions, OneTimeKeys
@@ -87,7 +97,10 @@ class Database(FileStorage, hyperdb.Database, roundupdb.Database):
         # reindex the db if necessary
         if self.indexer.should_reindex():
             self.reindex()
-        self.figure_curuserid()
+
+    def refresh_database(self):
+        "Rebuild the database"
+        self.reindex()
 
     def reindex(self):
         for klass in self.classes.values():
@@ -243,7 +256,7 @@ class Database(FileStorage, hyperdb.Database, roundupdb.Database):
             # add in the "calculated" properties (dupe so we don't affect
             # calling code's node assumptions)
             node = node.copy()
-            node['creator'] = self.curuserid
+            node['creator'] = self.getuid()
             node['creation'] = node['activity'] = date.Date()
 
         self.newnodes.setdefault(classname, {})[nodeid] = 1
@@ -489,7 +502,7 @@ class Database(FileStorage, hyperdb.Database, roundupdb.Database):
                 cache_creator, cache_creation) = args
             if cache_classname == classname and cache_nodeid == nodeid:
                 if not cache_creator:
-                    cache_creator = self.curuserid
+                    cache_creator = self.getuid()
                 if not cache_creation:
                     cache_creation = date.Date()
                 res.append((cache_nodeid, cache_creation, cache_creator,
@@ -503,7 +516,11 @@ class Database(FileStorage, hyperdb.Database, roundupdb.Database):
             if str(error) == "need 'c' or 'n' flag to open new db":
                 raise IndexError, 'no such %s %s'%(classname, nodeid)
             elif error.args[0] != 2:
+                # this isn't a "not found" error, be alarmed!
                 raise
+            if res:
+                # we have unsaved journal entries, return them
+                return res
             raise IndexError, 'no such %s %s'%(classname, nodeid)
         try:
             journal = marshal.loads(db[nodeid])
@@ -565,15 +582,16 @@ class Database(FileStorage, hyperdb.Database, roundupdb.Database):
         # keep a handle to all the database files opened
         self.databases = {}
 
-        # now, do all the transactions
-        reindex = {}
-        for method, args in self.transactions:
-            reindex[method(*args)] = 1
-
-        # now close all the database files
-        for db in self.databases.values():
-            db.close()
-        del self.databases
+        try:
+            # now, do all the transactions
+            reindex = {}
+            for method, args in self.transactions:
+                reindex[method(*args)] = 1
+        finally:
+            # make sure we close all the database files
+            for db in self.databases.values():
+                db.close()
+            del self.databases
 
         # reindex the nodes that request it
         for classname, nodeid in filter(None, reindex.keys()):
@@ -636,7 +654,7 @@ class Database(FileStorage, hyperdb.Database, roundupdb.Database):
         if creator:
             journaltag = creator
         else:
-            journaltag = self.curuserid
+            journaltag = self.getuid()
         if creation:
             journaldate = creation.serialise()
         else:
@@ -922,7 +940,7 @@ class Class(hyperdb.Class):
             l.append(repr(value))
 
         # append retired flag
-        l.append(self.is_retired(nodeid))
+        l.append(repr(self.is_retired(nodeid)))
 
         return l
 
@@ -1056,7 +1074,7 @@ class Class(hyperdb.Class):
                         # user's been retired, return admin
                         return '1'
             else:
-                return self.db.curuserid
+                return self.db.getuid()
 
         # get the property (raises KeyErorr if invalid)
         prop = self.properties[propname]
@@ -1076,17 +1094,6 @@ class Class(hyperdb.Class):
 
         return d[propname]
 
-    # not in spec
-    def getnode(self, nodeid, cache=1):
-        ''' Return a convenience wrapper for the node.
-
-        'nodeid' must be the id of an existing node of this class or an
-        IndexError is raised.
-
-        'cache' exists for backwards compatibility, and is not used.
-        '''
-        return Node(self, nodeid)
-
     def set(self, nodeid, **propvalues):
         '''Modify a property on an existing node of this class.