index 90cf05e461f17b9a0cb2268e97e08b9749f9e026..463a43f56011f4fd43b2e5936d88f6bbfc0e5106 100644 (file)
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
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)
# 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')
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)
"""
# 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
""" 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):
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
"""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]):
# 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
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()
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)))
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 = []
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()
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
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)
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:
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
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))