Skip to content

Commit fff0c29

Browse files
author
Richard Jones
committed
fixes to import/export
1 parent e05769a commit fff0c29

File tree

4 files changed

+79
-56
lines changed

4 files changed

+79
-56
lines changed

roundup/admin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1717
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1818
#
19-
# $Id: admin.py,v 1.39 2003-02-26 23:42:49 richard Exp $
19+
# $Id: admin.py,v 1.40 2003-02-28 03:33:46 richard Exp $
2020

2121
'''Administration commands for maintaining Roundup trackers.
2222
'''
@@ -925,7 +925,7 @@ def do_export(self, args):
925925
# all nodes for this class (not using list() 'cos it doesn't
926926
# include retired nodes)
927927

928-
for nodeid in self.db.getnodeids(classname):
928+
for nodeid in self.db.getclass(classname).getnodeids():
929929
# get the regular props
930930
print >>f, p.join(cl.export_list(propnames, nodeid))
931931
return 0

roundup/backends/back_anydbm.py

Lines changed: 30 additions & 28 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.106 2003-02-26 23:42:50 richard Exp $
18+
#$Id: back_anydbm.py,v 1.107 2003-02-28 03:33:46 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
@@ -448,28 +448,6 @@ def countnodes(self, classname, db=None):
448448
count = count + len(db.keys())
449449
return count
450450

451-
def getnodeids(self, classname, db=None):
452-
if __debug__:
453-
print >>hyperdb.DEBUG, 'getnodeids', (self, classname, db)
454-
455-
res = []
456-
457-
# start off with the new nodes
458-
if self.newnodes.has_key(classname):
459-
res += self.newnodes[classname].keys()
460-
461-
if db is None:
462-
db = self.getclassdb(classname)
463-
res = res + db.keys()
464-
465-
# remove the uncommitted, destroyed nodes
466-
if self.destroyednodes.has_key(classname):
467-
for nodeid in self.destroyednodes[classname].keys():
468-
if db.has_key(nodeid):
469-
res.remove(nodeid)
470-
471-
return res
472-
473451

474452
#
475453
# Files - special node properties
@@ -1435,7 +1413,7 @@ def lookup(self, keyvalue):
14351413
raise TypeError, 'No key property set for class %s'%self.classname
14361414
cldb = self.db.getclassdb(self.classname)
14371415
try:
1438-
for nodeid in self.db.getnodeids(self.classname, cldb):
1416+
for nodeid in self.getnodeids(cldb):
14391417
node = self.db.getnode(self.classname, nodeid, cldb)
14401418
if node.has_key(self.db.RETIRED_FLAG):
14411419
continue
@@ -1474,7 +1452,7 @@ def find(self, **propspec):
14741452
cldb = self.db.getclassdb(self.classname)
14751453
l = []
14761454
try:
1477-
for id in self.db.getnodeids(self.classname, db=cldb):
1455+
for id in self.getnodeids(db=cldb):
14781456
node = self.db.getnode(self.classname, id, db=cldb)
14791457
if node.has_key(self.db.RETIRED_FLAG):
14801458
continue
@@ -1518,7 +1496,7 @@ def stringFind(self, **requirements):
15181496
l = []
15191497
cldb = self.db.getclassdb(self.classname)
15201498
try:
1521-
for nodeid in self.db.getnodeids(self.classname, cldb):
1499+
for nodeid in self.getnodeids(cldb):
15221500
node = self.db.getnode(self.classname, nodeid, cldb)
15231501
if node.has_key(self.db.RETIRED_FLAG):
15241502
continue
@@ -1540,7 +1518,7 @@ def list(self):
15401518
cn = self.classname
15411519
cldb = self.db.getclassdb(cn)
15421520
try:
1543-
for nodeid in self.db.getnodeids(cn, cldb):
1521+
for nodeid in self.getnodeids(cldb):
15441522
node = self.db.getnode(cn, nodeid, cldb)
15451523
if node.has_key(self.db.RETIRED_FLAG):
15461524
continue
@@ -1550,6 +1528,30 @@ def list(self):
15501528
l.sort()
15511529
return l
15521530

1531+
def getnodeids(self, db=None):
1532+
''' Return a list of ALL nodeids
1533+
'''
1534+
if __debug__:
1535+
print >>hyperdb.DEBUG, 'getnodeids', (self, self.classname, db)
1536+
1537+
res = []
1538+
1539+
# start off with the new nodes
1540+
if self.db.newnodes.has_key(classname):
1541+
res += self.db.newnodes[classname].keys()
1542+
1543+
if db is None:
1544+
db = self.db.getclassdb(classname)
1545+
res = res + db.keys()
1546+
1547+
# remove the uncommitted, destroyed nodes
1548+
if self.db.destroyednodes.has_key(classname):
1549+
for nodeid in self.db.destroyednodes[classname].keys():
1550+
if db.has_key(nodeid):
1551+
res.remove(nodeid)
1552+
1553+
return res
1554+
15531555
def filter(self, search_matches, filterspec, sort=(None,None),
15541556
group=(None,None), num_re = re.compile('^\d+$')):
15551557
''' Return a list of the ids of the active nodes in this class that
@@ -1635,7 +1637,7 @@ def filter(self, search_matches, filterspec, sort=(None,None),
16351637
cldb = self.db.getclassdb(cn)
16361638
try:
16371639
# TODO: only full-scan once (use items())
1638-
for nodeid in self.db.getnodeids(cn, cldb):
1640+
for nodeid in self.getnodeids(cldb):
16391641
node = self.db.getnode(cn, nodeid, cldb)
16401642
if node.has_key(self.db.RETIRED_FLAG):
16411643
continue

roundup/backends/back_metakit.py

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ def set(self, nodeid, **propvalues):
610610
try:
611611
v = int(value)
612612
except ValueError:
613-
raise TypeError, "%s (%s) is not numeric" % (key, repr(value))
613+
raise TypeError, "%s (%s) is not numeric"%(key, repr(value))
614614
setattr(row, key, v)
615615
changes[key] = oldvalue
616616
propvalues[key] = value
@@ -619,7 +619,7 @@ def set(self, nodeid, **propvalues):
619619
if value is None:
620620
bv = 0
621621
elif value not in (0,1):
622-
raise TypeError, "%s (%s) is not boolean" % (key, repr(value))
622+
raise TypeError, "%s (%s) is not boolean"%(key, repr(value))
623623
else:
624624
bv = value
625625
setattr(row, key, bv)
@@ -818,6 +818,12 @@ def list(self):
818818
l.append(str(row.id))
819819
return l
820820

821+
def getnodeids(self):
822+
l = []
823+
for row in self.getview():
824+
l.append(str(row.id))
825+
return l
826+
821827
def count(self):
822828
return len(self.getview())
823829

@@ -1098,11 +1104,12 @@ def import_list(self, propnames, proplist):
10981104
view = self.getview(1)
10991105
for i in range(len(propnames)):
11001106
value = eval(proplist[i])
1107+
if not value:
1108+
continue
11011109
propname = propnames[i]
11021110
prop = properties[propname]
11031111
if propname == 'id':
1104-
newid = value
1105-
value = int(value)
1112+
newid = value = int(value)
11061113
elif isinstance(prop, hyperdb.Date):
11071114
value = int(calendar.timegm(value))
11081115
elif isinstance(prop, hyperdb.Interval):
@@ -1111,20 +1118,33 @@ def import_list(self, propnames, proplist):
11111118
value = int(value)
11121119
elif isinstance(prop, hyperdb.Boolean):
11131120
value = int(value)
1114-
elif isinstance(prop, hyperdb.Link):
1121+
elif isinstance(prop, hyperdb.Link) and value:
11151122
value = int(value)
11161123
elif isinstance(prop, hyperdb.Multilink):
1117-
value = map(int, value)
1124+
# we handle multilinks separately
1125+
continue
11181126
d[propname] = value
11191127
# is the item retired?
11201128
if int(proplist[-1]):
11211129
d['_isdel'] = 1
1122-
# XXX this is BROKEN for reasons I don't understand!
1123-
ndx = view.append(d)
1130+
view.append(d)
11241131

1132+
ndx = view.find(id=newid)
1133+
row = view[ndx]
1134+
for i in range(len(propnames)):
1135+
value = eval(proplist[i])
1136+
propname = propnames[i]
1137+
prop = properties[propname]
1138+
if not isinstance(prop, hyperdb.Multilink):
1139+
continue
1140+
sv = getattr(row, propname)
1141+
for entry in value:
1142+
sv.append(int(entry))
1143+
1144+
self.db.dirty = 1
11251145
creator = d.get('creator', 0)
11261146
creation = d.get('creation', 0)
1127-
self.db.addjournal(self.classname, newid, _CREATE, {}, creator,
1147+
self.db.addjournal(self.classname, str(newid), _CREATE, {}, creator,
11281148
creation)
11291149
return newid
11301150

roundup/backends/rdbms_common.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: rdbms_common.py,v 1.37 2003-02-27 11:07:36 richard Exp $
1+
# $Id: rdbms_common.py,v 1.38 2003-02-28 03:33:46 richard Exp $
22
''' Relational database (SQL) backend common code.
33
44
Basics:
@@ -715,21 +715,6 @@ def countnodes(self, classname):
715715
self.cursor.execute(sql)
716716
return self.cursor.fetchone()[0]
717717

718-
def getnodeids(self, classname, retired=0):
719-
''' Retrieve all the ids of the nodes for a particular Class.
720-
721-
Set retired=None to get all nodes. Otherwise it'll get all the
722-
retired or non-retired nodes, depending on the flag.
723-
'''
724-
# flip the sense of the flag if we don't want all of them
725-
if retired is not None:
726-
retired = not retired
727-
sql = 'select id from _%s where __retired__ <> %s'%(classname, self.arg)
728-
if __debug__:
729-
print >>hyperdb.DEBUG, 'getnodeids', (self, sql, retired)
730-
self.cursor.execute(sql, (retired,))
731-
return [x[0] for x in self.cursor.fetchall()]
732-
733718
def addjournal(self, classname, nodeid, action, params, creator=None,
734719
creation=None):
735720
''' Journal the Action
@@ -1690,7 +1675,23 @@ def stringFind(self, **requirements):
16901675
def list(self):
16911676
''' Return a list of the ids of the active nodes in this class.
16921677
'''
1693-
return self.db.getnodeids(self.classname, retired=0)
1678+
return self.getnodeids(retired=0)
1679+
1680+
def getnodeids(self, retired=None):
1681+
''' Retrieve all the ids of the nodes for a particular Class.
1682+
1683+
Set retired=None to get all nodes. Otherwise it'll get all the
1684+
retired or non-retired nodes, depending on the flag.
1685+
'''
1686+
# flip the sense of the flag if we don't want all of them
1687+
if retired is not None:
1688+
retired = not retired
1689+
sql = 'select id from _%s where __retired__ <> %s'%(self.classname,
1690+
self.db.arg)
1691+
if __debug__:
1692+
print >>hyperdb.DEBUG, 'getnodeids', (self, sql, retired)
1693+
self.db.cursor.execute(sql, (retired,))
1694+
return [x[0] for x in self.db.cursor.fetchall()]
16941695

16951696
def filter(self, search_matches, filterspec, sort=(None,None),
16961697
group=(None,None)):

0 commit comments

Comments
 (0)