Code

- more logger fixes, sorry for the noise.
[roundup.git] / roundup / backends / back_anydbm.py
index 3962a637f3429b4e5dfa485f9b9348cddce23ab4..463a43f56011f4fd43b2e5936d88f6bbfc0e5106 100644 (file)
@@ -24,7 +24,7 @@ __docformat__ = 'restructuredtext'
 
 import os, marshal, re, weakref, string, copy, time, shutil, logging
 
-from roundup.anypy.dbm_ import anydbm, whichdb
+from roundup.anypy.dbm_ import anydbm, whichdb, key_in
 
 from roundup import hyperdb, date, password, roundupdb, security, support
 from roundup.support import reversed
@@ -176,7 +176,7 @@ class Database(FileStorage, hyperdb.Database, roundupdb.Database):
     def clear(self):
         """Delete all database contents
         """
-        logging.getLogger('hyperdb').info('clear')
+        logging.getLogger('roundup.hyperdb').info('clear')
         for cn in self.classes:
             for dummy in 'nodes', 'journals':
                 path = os.path.join(self.dir, 'journals.%s'%cn)
@@ -224,7 +224,7 @@ class Database(FileStorage, hyperdb.Database, roundupdb.Database):
         # whichdb() function to do this
         if not db_type or hasattr(anydbm, 'whichdb'):
             if __debug__:
-                logging.getLogger('hyperdb').debug(
+                logging.getLogger('roundup.hyperdb').debug(
                     "opendb anydbm.open(%r, 'c')"%path)
             return anydbm.open(path, 'c')
 
@@ -236,7 +236,7 @@ class Database(FileStorage, hyperdb.Database, roundupdb.Database):
             raise hyperdb.DatabaseError(_("Couldn't open database - the "
                 "required module '%s' is not available")%db_type)
         if __debug__:
-            logging.getLogger('hyperdb').debug(
+            logging.getLogger('roundup.hyperdb').debug(
                 "opendb %r.open(%r, %r)"%(db_type, path, mode))
         return dbm.open(path, mode)
 
@@ -248,7 +248,7 @@ class Database(FileStorage, hyperdb.Database, roundupdb.Database):
         """
         # open the ids DB - create if if doesn't exist
         db = self.opendb('_ids', 'c')
-        if classname in db:
+        if key_in(db, classname):
             newid = db[classname] = str(int(db[classname]) + 1)
         else:
             # the count() bit is transitional - older dbs won't start at 1
@@ -297,7 +297,8 @@ class Database(FileStorage, hyperdb.Database, roundupdb.Database):
         """ perform the saving of data specified by the set/addnode
         """
         if __debug__:
-            logging.getLogger('hyperdb').debug('save %s%s %r'%(classname, nodeid, node))
+            logging.getLogger('roundup.hyperdb').debug(
+                'save %s%s %r'%(classname, nodeid, node))
         self.transactions.append((self.doSaveNode, (classname, nodeid, node)))
 
     def getnode(self, classname, nodeid, db=None, cache=1):
@@ -310,19 +311,21 @@ class Database(FileStorage, hyperdb.Database, roundupdb.Database):
         cache_dict = self.cache.setdefault(classname, {})
         if nodeid in cache_dict:
             if __debug__:
-                logging.getLogger('hyperdb').debug('get %s%s cached'%(classname, nodeid))
+                logging.getLogger('roundup.hyperdb').debug(
+                    'get %s%s cached'%(classname, nodeid))
                 self.stats['cache_hits'] += 1
             return cache_dict[nodeid]
 
         if __debug__:
             self.stats['cache_misses'] += 1
             start_t = time.time()
-            logging.getLogger('hyperdb').debug('get %s%s'%(classname, nodeid))
+            logging.getLogger('roundup.hyperdb').debug(
+                'get %s%s'%(classname, nodeid))
 
         # get from the database and save in the cache
         if db is None:
             db = self.getclassdb(classname)
-        if nodeid not in db:
+        if not key_in(db, nodeid):
             raise IndexError("no such %s %s"%(classname, nodeid))
 
         # check the uncommitted, destroyed nodes
@@ -349,7 +352,8 @@ class Database(FileStorage, hyperdb.Database, roundupdb.Database):
         """Remove a node from the database. Called exclusively by the
            destroy() method on Class.
         """
-        logging.getLogger('hyperdb').info('destroy %s%s'%(classname, nodeid))
+        logging.getLogger('roundup.hyperdb').info(
+            'destroy %s%s'%(classname, nodeid))
 
         # remove from cache and newnodes if it's there
         if (classname in self.cache and nodeid in self.cache[classname]):
@@ -435,7 +439,7 @@ class Database(FileStorage, hyperdb.Database, roundupdb.Database):
         # not in the cache - check the database
         if db is None:
             db = self.getclassdb(classname)
-        return nodeid in db
+        return key_in(db, nodeid)
 
     def countnodes(self, classname, db=None):
         count = 0
@@ -472,7 +476,8 @@ class Database(FileStorage, hyperdb.Database, roundupdb.Database):
             the current user.
         """
         if __debug__:
-            logging.getLogger('hyperdb').debug('addjournal %s%s %s %r %s %r'%(classname,
+            logging.getLogger('roundup.hyperdb').debug(
+                'addjournal %s%s %s %r %s %r'%(classname,
                 nodeid, action, params, creator, creation))
         if creator is None:
             creator = self.getuid()
@@ -482,8 +487,8 @@ class Database(FileStorage, hyperdb.Database, roundupdb.Database):
     def setjournal(self, classname, nodeid, journal):
         """Set the journal to the "journal" list."""
         if __debug__:
-            logging.getLogger('hyperdb').debug('setjournal %s%s %r'%(classname,
-                nodeid, journal))
+            logging.getLogger('roundup.hyperdb').debug(
+                'setjournal %s%s %r'%(classname, nodeid, journal))
         self.transactions.append((self.doSetJournal, (classname, nodeid,
             journal)))
 
@@ -552,7 +557,7 @@ class Database(FileStorage, hyperdb.Database, roundupdb.Database):
             db_type = self.determine_db_type(path)
             db = self.opendb(db_name, 'w')
 
-            for key in db:
+            for key in db.keys():
                 # get the journal for this db entry
                 journal = marshal.loads(db[key])
                 l = []
@@ -569,8 +574,8 @@ class Database(FileStorage, hyperdb.Database, roundupdb.Database):
                         packed += 1
                 db[key] = marshal.dumps(l)
 
-                logging.getLogger('hyperdb').info('packed %d %s items'%(packed,
-                    classname))
+                logging.getLogger('roundup.hyperdb').info(
+                    'packed %d %s items'%(packed, classname))
 
             if db_type == 'gdbm':
                 db.reorganize()
@@ -592,7 +597,7 @@ class Database(FileStorage, hyperdb.Database, roundupdb.Database):
 
         The only backend this seems to affect is postgres.
         """
-        logging.getLogger('hyperdb').info('commit %s transactions'%(
+        logging.getLogger('roundup.hyperdb').info('commit %s transactions'%(
             len(self.transactions)))
 
         # keep a handle to all the database files opened
@@ -679,7 +684,7 @@ class Database(FileStorage, hyperdb.Database, roundupdb.Database):
         db = self.getCachedJournalDB(classname)
 
         # now insert the journal entry
-        if nodeid in db:
+        if key_in(db, nodeid):
             # append to existing
             s = db[nodeid]
             l = marshal.loads(s)
@@ -704,18 +709,18 @@ class Database(FileStorage, hyperdb.Database, roundupdb.Database):
     def doDestroyNode(self, classname, nodeid):
         # delete from the class database
         db = self.getCachedClassDB(classname)
-        if nodeid in db:
+        if key_in(db, nodeid):
             del db[nodeid]
 
         # delete from the database
         db = self.getCachedJournalDB(classname)
-        if nodeid in db:
+        if key_in(db, nodeid):
             del db[nodeid]
 
     def rollback(self):
         """ Reverse all actions from the current transaction.
         """
-        logging.getLogger('hyperdb').info('rollback %s transactions'%(
+        logging.getLogger('roundup.hyperdb').info('rollback %s transactions'%(
             len(self.transactions)))
 
         for method, args in self.transactions:
@@ -1530,12 +1535,12 @@ class Class(hyperdb.Class):
             db = self.db.getclassdb(self.classname)
             must_close = True
         try:
-            res.extend(db)
+            res.extend(db.keys())
 
             # remove the uncommitted, destroyed nodes
             if self.classname in self.db.destroyednodes:
                 for nodeid in self.db.destroyednodes[self.classname]:
-                    if nodeid in db:
+                    if key_in(db, nodeid):
                         res.remove(nodeid)
 
             # check retired flag
@@ -1630,12 +1635,14 @@ class Class(hyperdb.Class):
                     pass
 
             elif isinstance(propclass, hyperdb.Boolean):
-                if type(v) != type([]):
+                if type(v) == type(""):
                     v = v.split(',')
+                if type(v) != type([]):
+                    v = [v]
                 bv = []
                 for val in v:
                     if type(val) is type(''):
-                        bv.append(val.lower() in ('yes', 'true', 'on', '1'))
+                        bv.append(propclass.from_raw (val))
                     else:
                         bv.append(val)
                 l.append((OTHER, k, bv))
@@ -1647,7 +1654,10 @@ class Class(hyperdb.Class):
 
             elif isinstance(propclass, hyperdb.Number):
                 if type(v) != type([]):
-                    v = v.split(',')
+                    try :
+                        v = v.split(',')
+                    except AttributeError :
+                        v = [v]
                 l.append((OTHER, k, [float(val) for val in v]))
 
         filterspec = l