Code

Ran it through pychecker, made fixes
[roundup.git] / roundup / hyperdb.py
index 9a2406aa2b8e7a8d892e9845503453e258f06621..9aa575ac63813004cce38c19c62f53cf26501a31 100644 (file)
 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 # 
-# $Id: hyperdb.py,v 1.51 2002-01-21 03:01:29 richard Exp $
+# $Id: hyperdb.py,v 1.58 2002-02-27 03:23:16 richard Exp $
 
 __doc__ = """
 Hyperdatabase implementation, especially field types.
 """
 
 # standard python modules
-import cPickle, re, string, weakref
+import re, string, weakref, os
 
 # roundup modules
 import date, password
 
+DEBUG = os.environ.get('HYPERDBDEBUG', '')
 
 #
 # Types
@@ -211,6 +212,11 @@ transaction.
         '''
         raise NotImplementedError
 
+    def pack(self, pack_before):
+        ''' pack the database
+        '''
+        raise NotImplementedError
+
     def commit(self):
         ''' Commit the current transactions.
 
@@ -499,6 +505,13 @@ class Class:
             # the writeable properties.
             prop = self.properties[key]
 
+            # if the value's the same as the existing value, no sense in
+            # doing anything
+            if node.has_key(key) and value == node[key]:
+                del propvalues[key]
+                continue
+
+            # do stuff based on the prop type
             if isinstance(prop, Link):
                 link_class = self.properties[key].classname
                 # if it isn't a number, it's a key
@@ -592,6 +605,11 @@ class Class:
 
             node[key] = value
 
+        # nothing to do?
+        if not propvalues:
+            return
+
+        # do the set, and journal it
         self.db.setnode(self.classname, nodeid, node)
         self.db.addjournal(self.classname, nodeid, 'set', propvalues)
 
@@ -627,6 +645,10 @@ class Class:
         return self.db.getjournal(self.classname, nodeid)
 
     # Locating nodes:
+    def hasnode(self, nodeid):
+        '''Determine if the given nodeid actually exists
+        '''
+        return self.db.hasnode(self.classname, nodeid)
 
     def setkey(self, propname):
         """Select a String property of this class to be the key property.
@@ -840,7 +862,7 @@ class Class:
                     else:
                         continue
                     break
-                elif t == 2 and not v.search(node[k]):
+                elif t == 2 and (node[k] is None or not v.search(node[k])):
                     # RE search
                     break
                 elif t == 6 and node[k] != v:
@@ -1052,14 +1074,46 @@ class Node:
         return self.cl.retire(self.nodeid)
 
 
-def Choice(name, *options):
-    cl = Class(db, name, name=hyperdb.String(), order=hyperdb.String())
+def Choice(name, db, *options):
+    '''Quick helper to create a simple class with choices
+    '''
+    cl = Class(db, name, name=String(), order=String())
     for i in range(len(options)):
-        cl.create(name=option[i], order=i)
+        cl.create(name=options[i], order=i)
     return hyperdb.Link(name)
 
 #
 # $Log: not supported by cvs2svn $
+# Revision 1.57  2002/02/20 05:23:24  richard
+# Didn't accomodate new values for new properties
+#
+# Revision 1.56  2002/02/20 05:05:28  richard
+#  . Added simple editing for classes that don't define a templated interface.
+#    - access using the admin "class list" interface
+#    - limited to admin-only
+#    - requires the csv module from object-craft (url given if it's missing)
+#
+# Revision 1.55  2002/02/15 07:27:12  richard
+# Oops, precedences around the way w0rng.
+#
+# Revision 1.54  2002/02/15 07:08:44  richard
+#  . Alternate email addresses are now available for users. See the MIGRATION
+#    file for info on how to activate the feature.
+#
+# Revision 1.53  2002/01/22 07:21:13  richard
+# . 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.
+#
+# Revision 1.52  2002/01/21 16:33:19  rochecompaan
+# You can now use the roundup-admin tool to pack the database
+#
+# Revision 1.51  2002/01/21 03:01:29  richard
+# brief docco on the do_journal argument
+#
 # Revision 1.50  2002/01/19 13:16:04  rochecompaan
 # Journal entries for link and multilink properties can now be switched on
 # or off.