From bd98c1b65ff4e7980b3a48268b3f34f6f7fe80d6 Mon Sep 17 00:00:00 2001 From: richard Date: Fri, 28 Feb 2003 03:33:46 +0000 Subject: [PATCH] fixes to import/export git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@1561 57a73879-2fb5-44c3-a270-3262357dd7e2 --- roundup/admin.py | 4 +-- roundup/backends/back_anydbm.py | 58 +++++++++++++++++--------------- roundup/backends/back_metakit.py | 38 ++++++++++++++++----- roundup/backends/rdbms_common.py | 35 +++++++++---------- 4 files changed, 79 insertions(+), 56 deletions(-) diff --git a/roundup/admin.py b/roundup/admin.py index 8b90e46..6877973 100644 --- a/roundup/admin.py +++ b/roundup/admin.py @@ -16,7 +16,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -# $Id: admin.py,v 1.39 2003-02-26 23:42:49 richard Exp $ +# $Id: admin.py,v 1.40 2003-02-28 03:33:46 richard Exp $ '''Administration commands for maintaining Roundup trackers. ''' @@ -925,7 +925,7 @@ Command help: # all nodes for this class (not using list() 'cos it doesn't # include retired nodes) - for nodeid in self.db.getnodeids(classname): + for nodeid in self.db.getclass(classname).getnodeids(): # get the regular props print >>f, p.join(cl.export_list(propnames, nodeid)) return 0 diff --git a/roundup/backends/back_anydbm.py b/roundup/backends/back_anydbm.py index dfacf2f..8a30e25 100644 --- a/roundup/backends/back_anydbm.py +++ b/roundup/backends/back_anydbm.py @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -#$Id: back_anydbm.py,v 1.106 2003-02-26 23:42:50 richard Exp $ +#$Id: back_anydbm.py,v 1.107 2003-02-28 03:33:46 richard Exp $ ''' This module defines a backend that saves the hyperdatabase in a database chosen by anydbm. It is guaranteed to always be available in python @@ -448,28 +448,6 @@ class Database(FileStorage, hyperdb.Database, roundupdb.Database): count = count + len(db.keys()) return count - def getnodeids(self, classname, db=None): - if __debug__: - print >>hyperdb.DEBUG, 'getnodeids', (self, classname, db) - - res = [] - - # start off with the new nodes - if self.newnodes.has_key(classname): - res += self.newnodes[classname].keys() - - if db is None: - db = self.getclassdb(classname) - res = res + db.keys() - - # remove the uncommitted, destroyed nodes - if self.destroyednodes.has_key(classname): - for nodeid in self.destroyednodes[classname].keys(): - if db.has_key(nodeid): - res.remove(nodeid) - - return res - # # Files - special node properties @@ -1435,7 +1413,7 @@ class Class(hyperdb.Class): raise TypeError, 'No key property set for class %s'%self.classname cldb = self.db.getclassdb(self.classname) try: - for nodeid in self.db.getnodeids(self.classname, cldb): + for nodeid in self.getnodeids(cldb): node = self.db.getnode(self.classname, nodeid, cldb) if node.has_key(self.db.RETIRED_FLAG): continue @@ -1474,7 +1452,7 @@ class Class(hyperdb.Class): cldb = self.db.getclassdb(self.classname) l = [] try: - for id in self.db.getnodeids(self.classname, db=cldb): + for id in self.getnodeids(db=cldb): node = self.db.getnode(self.classname, id, db=cldb) if node.has_key(self.db.RETIRED_FLAG): continue @@ -1518,7 +1496,7 @@ class Class(hyperdb.Class): l = [] cldb = self.db.getclassdb(self.classname) try: - for nodeid in self.db.getnodeids(self.classname, cldb): + for nodeid in self.getnodeids(cldb): node = self.db.getnode(self.classname, nodeid, cldb) if node.has_key(self.db.RETIRED_FLAG): continue @@ -1540,7 +1518,7 @@ class Class(hyperdb.Class): cn = self.classname cldb = self.db.getclassdb(cn) try: - for nodeid in self.db.getnodeids(cn, cldb): + for nodeid in self.getnodeids(cldb): node = self.db.getnode(cn, nodeid, cldb) if node.has_key(self.db.RETIRED_FLAG): continue @@ -1550,6 +1528,30 @@ class Class(hyperdb.Class): l.sort() return l + def getnodeids(self, db=None): + ''' Return a list of ALL nodeids + ''' + if __debug__: + print >>hyperdb.DEBUG, 'getnodeids', (self, self.classname, db) + + res = [] + + # start off with the new nodes + if self.db.newnodes.has_key(classname): + res += self.db.newnodes[classname].keys() + + if db is None: + db = self.db.getclassdb(classname) + res = res + db.keys() + + # remove the uncommitted, destroyed nodes + if self.db.destroyednodes.has_key(classname): + for nodeid in self.db.destroyednodes[classname].keys(): + if db.has_key(nodeid): + res.remove(nodeid) + + return res + def filter(self, search_matches, filterspec, sort=(None,None), group=(None,None), num_re = re.compile('^\d+$')): ''' Return a list of the ids of the active nodes in this class that @@ -1635,7 +1637,7 @@ class Class(hyperdb.Class): cldb = self.db.getclassdb(cn) try: # TODO: only full-scan once (use items()) - for nodeid in self.db.getnodeids(cn, cldb): + for nodeid in self.getnodeids(cldb): node = self.db.getnode(cn, nodeid, cldb) if node.has_key(self.db.RETIRED_FLAG): continue diff --git a/roundup/backends/back_metakit.py b/roundup/backends/back_metakit.py index 3cdcca8..fd88d21 100755 --- a/roundup/backends/back_metakit.py +++ b/roundup/backends/back_metakit.py @@ -610,7 +610,7 @@ class Class: try: v = int(value) except ValueError: - raise TypeError, "%s (%s) is not numeric" % (key, repr(value)) + raise TypeError, "%s (%s) is not numeric"%(key, repr(value)) setattr(row, key, v) changes[key] = oldvalue propvalues[key] = value @@ -619,7 +619,7 @@ class Class: if value is None: bv = 0 elif value not in (0,1): - raise TypeError, "%s (%s) is not boolean" % (key, repr(value)) + raise TypeError, "%s (%s) is not boolean"%(key, repr(value)) else: bv = value setattr(row, key, bv) @@ -818,6 +818,12 @@ class Class: l.append(str(row.id)) return l + def getnodeids(self): + l = [] + for row in self.getview(): + l.append(str(row.id)) + return l + def count(self): return len(self.getview()) @@ -1098,11 +1104,12 @@ class Class: view = self.getview(1) for i in range(len(propnames)): value = eval(proplist[i]) + if not value: + continue propname = propnames[i] prop = properties[propname] if propname == 'id': - newid = value - value = int(value) + newid = value = int(value) elif isinstance(prop, hyperdb.Date): value = int(calendar.timegm(value)) elif isinstance(prop, hyperdb.Interval): @@ -1111,20 +1118,33 @@ class Class: value = int(value) elif isinstance(prop, hyperdb.Boolean): value = int(value) - elif isinstance(prop, hyperdb.Link): + elif isinstance(prop, hyperdb.Link) and value: value = int(value) elif isinstance(prop, hyperdb.Multilink): - value = map(int, value) + # we handle multilinks separately + continue d[propname] = value # is the item retired? if int(proplist[-1]): d['_isdel'] = 1 - # XXX this is BROKEN for reasons I don't understand! - ndx = view.append(d) + view.append(d) + ndx = view.find(id=newid) + row = view[ndx] + for i in range(len(propnames)): + value = eval(proplist[i]) + propname = propnames[i] + prop = properties[propname] + if not isinstance(prop, hyperdb.Multilink): + continue + sv = getattr(row, propname) + for entry in value: + sv.append(int(entry)) + + self.db.dirty = 1 creator = d.get('creator', 0) creation = d.get('creation', 0) - self.db.addjournal(self.classname, newid, _CREATE, {}, creator, + self.db.addjournal(self.classname, str(newid), _CREATE, {}, creator, creation) return newid diff --git a/roundup/backends/rdbms_common.py b/roundup/backends/rdbms_common.py index 375f12a..55a400b 100644 --- a/roundup/backends/rdbms_common.py +++ b/roundup/backends/rdbms_common.py @@ -1,4 +1,4 @@ -# $Id: rdbms_common.py,v 1.37 2003-02-27 11:07:36 richard Exp $ +# $Id: rdbms_common.py,v 1.38 2003-02-28 03:33:46 richard Exp $ ''' Relational database (SQL) backend common code. Basics: @@ -715,21 +715,6 @@ class Database(FileStorage, hyperdb.Database, roundupdb.Database): self.cursor.execute(sql) return self.cursor.fetchone()[0] - def getnodeids(self, classname, retired=0): - ''' Retrieve all the ids of the nodes for a particular Class. - - Set retired=None to get all nodes. Otherwise it'll get all the - retired or non-retired nodes, depending on the flag. - ''' - # flip the sense of the flag if we don't want all of them - if retired is not None: - retired = not retired - sql = 'select id from _%s where __retired__ <> %s'%(classname, self.arg) - if __debug__: - print >>hyperdb.DEBUG, 'getnodeids', (self, sql, retired) - self.cursor.execute(sql, (retired,)) - return [x[0] for x in self.cursor.fetchall()] - def addjournal(self, classname, nodeid, action, params, creator=None, creation=None): ''' Journal the Action @@ -1690,7 +1675,23 @@ class Class(hyperdb.Class): def list(self): ''' Return a list of the ids of the active nodes in this class. ''' - return self.db.getnodeids(self.classname, retired=0) + return self.getnodeids(retired=0) + + def getnodeids(self, retired=None): + ''' Retrieve all the ids of the nodes for a particular Class. + + Set retired=None to get all nodes. Otherwise it'll get all the + retired or non-retired nodes, depending on the flag. + ''' + # flip the sense of the flag if we don't want all of them + if retired is not None: + retired = not retired + sql = 'select id from _%s where __retired__ <> %s'%(self.classname, + self.db.arg) + if __debug__: + print >>hyperdb.DEBUG, 'getnodeids', (self, sql, retired) + self.db.cursor.execute(sql, (retired,)) + return [x[0] for x in self.db.cursor.fetchall()] def filter(self, search_matches, filterspec, sort=(None,None), group=(None,None)): -- 2.30.2