Skip to content

Commit 766e3e6

Browse files
author
Richard Jones
committed
Fixed:
. handling of None for Date/Interval/Password values in export/import . handling of journal values in export/import Also played with metakit backend some, fixing some of the unit tests breakages. Hrm.
1 parent 6785188 commit 766e3e6

File tree

7 files changed

+173
-105
lines changed

7 files changed

+173
-105
lines changed

CHANGES.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
This file contains the changes to the Roundup system over time. The entries
22
are given with the most recent entry first.
33

4+
2002-09-?? 0.5.0 ????
5+
. handling of None for Date/Interval/Password values in export/import
6+
. handling of journal values in export/import
7+
48
2002-09-13 0.5.0 beta2
59
. all backends now have a .close() method, and it's used everywhere
610
. fixed bug in detectors __init__

roundup/backends/back_anydbm.py

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
#$Id: back_anydbm.py,v 1.77 2002-09-12 07:23:23 richard Exp $
18+
#$Id: back_anydbm.py,v 1.78 2002-09-13 08:20:07 richard Exp $
1919
'''
2020
This module defines a backend that saves the hyperdatabase in a database
2121
chosen by anydbm. It is guaranteed to always be available in python
@@ -154,7 +154,7 @@ def determine_db_type(self, path):
154154
if os.path.exists(path):
155155
db_type = whichdb.whichdb(path)
156156
if not db_type:
157-
raise hyperdb.DatabaseError, "Couldn't identify database type"
157+
raise DatabaseError, "Couldn't identify database type"
158158
elif os.path.exists(path+'.db'):
159159
# if the path ends in '.db', it's a dbm database, whether
160160
# anydbm says it's dbhash or not!
@@ -182,7 +182,7 @@ def opendb(self, name, mode):
182182
try:
183183
dbm = __import__(db_type)
184184
except ImportError:
185-
raise hyperdb.DatabaseError, \
185+
raise DatabaseError, \
186186
"Couldn't open database - the required module '%s'"\
187187
" is not available"%db_type
188188
if __debug__:
@@ -447,7 +447,8 @@ def getnodeids(self, classname, db=None):
447447
#
448448
# Journal
449449
#
450-
def addjournal(self, classname, nodeid, action, params):
450+
def addjournal(self, classname, nodeid, action, params, creator=None,
451+
creation=None):
451452
''' Journal the Action
452453
'action' may be:
453454
@@ -457,9 +458,9 @@ def addjournal(self, classname, nodeid, action, params):
457458
'''
458459
if __debug__:
459460
print >>hyperdb.DEBUG, 'addjournal', (self, classname, nodeid,
460-
action, params)
461+
action, params, creator, creation)
461462
self.transactions.append((self.doSaveJournal, (classname, nodeid,
462-
action, params)))
463+
action, params, creator, creation)))
463464

464465
def getjournal(self, classname, nodeid):
465466
''' get the journal for id
@@ -603,28 +604,22 @@ def getCachedJournalDB(self, classname):
603604
self.databases[db_name] = self.opendb(db_name, 'c')
604605
return self.databases[db_name]
605606

606-
def doSaveJournal(self, classname, nodeid, action, params):
607-
# handle supply of the special journalling parameters (usually
608-
# supplied on importing an existing database)
607+
def doSaveJournal(self, classname, nodeid, action, params, creator,
608+
creation):
609+
# serialise the parameters now if necessary
609610
if isinstance(params, type({})):
610-
if params.has_key('creator'):
611-
journaltag = self.user.get(params['creator'], 'username')
612-
del params['creator']
613-
else:
614-
journaltag = self.journaltag
615-
if params.has_key('created'):
616-
journaldate = params['created'].serialise()
617-
del params['created']
618-
else:
619-
journaldate = date.Date().serialise()
620-
if params.has_key('activity'):
621-
del params['activity']
622-
623-
# serialise the parameters now
624611
if action in ('set', 'create'):
625612
params = self.serialise(classname, params)
613+
614+
# handle supply of the special journalling parameters (usually
615+
# supplied on importing an existing database)
616+
if creator:
617+
journaltag = creator
626618
else:
627619
journaltag = self.journaltag
620+
if creation:
621+
journaldate = creation.serialise()
622+
else:
628623
journaldate = date.Date().serialise()
629624

630625
# create the journal entry
@@ -889,7 +884,9 @@ def export_list(self, propnames, nodeid):
889884
proptype = properties[prop]
890885
value = self.get(nodeid, prop)
891886
# "marshal" data where needed
892-
if isinstance(proptype, hyperdb.Date):
887+
if value is None:
888+
pass
889+
elif isinstance(proptype, hyperdb.Date):
893890
value = value.get_tuple()
894891
elif isinstance(proptype, hyperdb.Interval):
895892
value = value.get_tuple()
@@ -924,6 +921,9 @@ def import_list(self, propnames, proplist):
924921
if propname == 'id':
925922
newid = value
926923
continue
924+
elif value is None:
925+
# don't set Nones
926+
continue
927927
elif isinstance(prop, hyperdb.Date):
928928
value = date.Date(value)
929929
elif isinstance(prop, hyperdb.Interval):
@@ -932,12 +932,26 @@ def import_list(self, propnames, proplist):
932932
pwd = password.Password()
933933
pwd.unpack(value)
934934
value = pwd
935-
if value is not None:
936-
d[propname] = value
935+
d[propname] = value
936+
937+
# extract the extraneous journalling gumpf and nuke it
938+
if d.has_key('creator'):
939+
creator = d['creator']
940+
del d['creator']
941+
else:
942+
creator = None
943+
if d.has_key('creation'):
944+
creation = d['creation']
945+
del d['creation']
946+
else:
947+
creation = None
948+
if d.has_key('activity'):
949+
del d['activity']
937950

938-
# add
951+
# add the node and journal
939952
self.db.addnode(self.classname, newid, d)
940-
self.db.addjournal(self.classname, newid, 'create', d)
953+
self.db.addjournal(self.classname, newid, 'create', d, creator,
954+
creation)
941955
return newid
942956

943957
def get(self, nodeid, propname, default=_marker, cache=1):
@@ -1825,7 +1839,7 @@ def import_list(self, propnames, proplist):
18251839

18261840
# extract the "content" property from the proplist
18271841
i = propnames.index('content')
1828-
content = proplist[i]
1842+
content = eval(proplist[i])
18291843
del propnames[i]
18301844
del proplist[i]
18311845

roundup/backends/back_bsddb.py

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
#$Id: back_bsddb.py,v 1.23 2002-09-10 00:11:50 richard Exp $
18+
#$Id: back_bsddb.py,v 1.24 2002-09-13 08:20:11 richard Exp $
1919
'''
2020
This module defines a backend that saves the hyperdatabase in BSDDB.
2121
'''
@@ -107,24 +107,3 @@ def getCachedJournalDB(self, classname):
107107
self.databases[db_name] = db
108108
return db
109109

110-
def doSaveJournal(self, classname, nodeid, action, params):
111-
# serialise first
112-
if action in ('set', 'create'):
113-
params = self.serialise(classname, params)
114-
115-
entry = (nodeid, date.Date().get_tuple(), self.journaltag, action,
116-
params)
117-
118-
if __debug__:
119-
print >>hyperdb.DEBUG, 'doSaveJournal', entry
120-
121-
db = self.getCachedJournalDB(classname)
122-
123-
if db.has_key(nodeid):
124-
s = db[nodeid]
125-
l = marshal.loads(s)
126-
l.append(entry)
127-
else:
128-
l = [entry]
129-
130-
db[nodeid] = marshal.dumps(l)

roundup/backends/back_bsddb3.py

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
#$Id: back_bsddb3.py,v 1.16 2002-09-10 00:11:50 richard Exp $
18+
#$Id: back_bsddb3.py,v 1.17 2002-09-13 08:20:12 richard Exp $
1919

2020
import bsddb3, os, marshal
2121
from roundup import hyperdb, date
@@ -103,24 +103,3 @@ def getCachedJournalDB(self, classname):
103103
self.databases[db_name] = db
104104
return db
105105

106-
def doSaveJournal(self, classname, nodeid, action, params):
107-
# serialise first
108-
if action in ('set', 'create'):
109-
params = self.serialise(classname, params)
110-
111-
entry = (nodeid, date.Date().get_tuple(), self.journaltag, action,
112-
params)
113-
114-
if __debug__:
115-
print >>hyperdb.DEBUG, 'doSaveJournal', entry
116-
117-
db = self.getCachedJournalDB(classname)
118-
119-
if db.has_key(nodeid):
120-
s = db[nodeid]
121-
l = marshal.loads(s)
122-
l.append(entry)
123-
else:
124-
l = [entry]
125-
126-
db[nodeid] = marshal.dumps(l)

roundup/backends/back_gadfly.py

Lines changed: 90 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: back_gadfly.py,v 1.18 2002-09-12 07:23:23 richard Exp $
1+
# $Id: back_gadfly.py,v 1.19 2002-09-13 08:20:13 richard Exp $
22
__doc__ = '''
33
About Gadfly
44
============
@@ -659,41 +659,37 @@ def getnodeids(self, classname, retired=0):
659659
cursor.execute(sql, (retired,))
660660
return [x[0] for x in cursor.fetchall()]
661661

662-
def addjournal(self, classname, nodeid, action, params):
662+
def addjournal(self, classname, nodeid, action, params, creator=None,
663+
creation=None):
663664
''' Journal the Action
664665
'action' may be:
665666
666667
'create' or 'set' -- 'params' is a dictionary of property values
667668
'link' or 'unlink' -- 'params' is (classname, nodeid, propname)
668669
'retire' -- 'params' is None
669670
'''
671+
# serialise the parameters now if necessary
670672
if isinstance(params, type({})):
671-
if params.has_key('creator'):
672-
journaltag = self.user.get(params['creator'], 'username')
673-
del params['creator']
674-
else:
675-
journaltag = self.journaltag
676-
if params.has_key('created'):
677-
journaldate = params['created'].serialise()
678-
del params['created']
679-
else:
680-
journaldate = date.Date().serialise()
681-
if params.has_key('activity'):
682-
del params['activity']
683-
684-
# serialise the parameters now
685673
if action in ('set', 'create'):
686674
params = self.serialise(classname, params)
675+
676+
# handle supply of the special journalling parameters (usually
677+
# supplied on importing an existing database)
678+
if creator:
679+
journaltag = creator
687680
else:
688681
journaltag = self.journaltag
682+
if creation:
683+
journaldate = creation.serialise()
684+
else:
689685
journaldate = date.Date().serialise()
690686

691687
# create the journal entry
692688
cols = ','.join('nodeid date tag action params'.split())
693689
entry = (nodeid, journaldate, journaltag, action, params)
694690

695691
if __debug__:
696-
print >>hyperdb.DEBUG, 'doSaveJournal', entry
692+
print >>hyperdb.DEBUG, 'addjournal', entry
697693

698694
# do the insert
699695
cursor = self.conn.cursor()
@@ -999,6 +995,82 @@ def create(self, **propvalues):
999995

1000996
return newid
1001997

998+
def export_list(self, propnames, nodeid):
999+
''' Export a node - generate a list of CSV-able data in the order
1000+
specified by propnames for the given node.
1001+
'''
1002+
properties = self.getprops()
1003+
l = []
1004+
for prop in propnames:
1005+
proptype = properties[prop]
1006+
value = self.get(nodeid, prop)
1007+
# "marshal" data where needed
1008+
if value is None:
1009+
pass
1010+
elif isinstance(proptype, hyperdb.Date):
1011+
value = value.get_tuple()
1012+
elif isinstance(proptype, hyperdb.Interval):
1013+
value = value.get_tuple()
1014+
elif isinstance(proptype, hyperdb.Password):
1015+
value = str(value)
1016+
l.append(repr(value))
1017+
return l
1018+
1019+
def import_list(self, propnames, proplist):
1020+
''' Import a node - all information including "id" is present and
1021+
should not be sanity checked. Triggers are not triggered. The
1022+
journal should be initialised using the "creator" and "created"
1023+
information.
1024+
1025+
Return the nodeid of the node imported.
1026+
'''
1027+
if self.db.journaltag is None:
1028+
raise DatabaseError, 'Database open read-only'
1029+
properties = self.getprops()
1030+
1031+
# make the new node's property map
1032+
d = {}
1033+
for i in range(len(propnames)):
1034+
# Use eval to reverse the repr() used to output the CSV
1035+
value = eval(proplist[i])
1036+
1037+
# Figure the property for this column
1038+
propname = propnames[i]
1039+
prop = properties[propname]
1040+
1041+
# "unmarshal" where necessary
1042+
if propname == 'id':
1043+
newid = value
1044+
continue
1045+
elif value is None:
1046+
# don't set Nones
1047+
continue
1048+
elif isinstance(prop, hyperdb.Date):
1049+
value = date.Date(value)
1050+
elif isinstance(prop, hyperdb.Interval):
1051+
value = date.Interval(value)
1052+
elif isinstance(prop, hyperdb.Password):
1053+
pwd = password.Password()
1054+
pwd.unpack(value)
1055+
value = pwd
1056+
d[propname] = value
1057+
1058+
# extract the extraneous journalling gumpf and nuke it
1059+
if d.has_key('creator'):
1060+
creator = d['creator']
1061+
del d['creator']
1062+
if d.has_key('creation'):
1063+
creation = d['creation']
1064+
del d['creation']
1065+
if d.has_key('activity'):
1066+
del d['activity']
1067+
1068+
# add the node and journal
1069+
self.db.addnode(self.classname, newid, d)
1070+
self.db.addjournal(self.classname, newid, 'create', d, creator,
1071+
creation)
1072+
return newid
1073+
10021074
_marker = []
10031075
def get(self, nodeid, propname, default=_marker, cache=1):
10041076
'''Get the value of a property on an existing node of this class.
@@ -1676,7 +1748,7 @@ def import_list(self, propnames, proplist):
16761748

16771749
# extract the "content" property from the proplist
16781750
i = propnames.index('content')
1679-
content = proplist[i]
1751+
content = eval(proplist[i])
16801752
del propnames[i]
16811753
del proplist[i]
16821754

0 commit comments

Comments
 (0)