Skip to content

Commit 12116cc

Browse files
author
Richard Jones
committed
relaxed CVS importing (feature [SF#693277])
1 parent f585769 commit 12116cc

File tree

5 files changed

+71
-31
lines changed

5 files changed

+71
-31
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Feature:
4040
file serving
4141
- added Node.get() method
4242
- nicer page titles (sf feature 65197)
43+
- relaxed CVS importing (sf feature 693277)
4344

4445

4546
Fixed:

roundup/admin.py

Lines changed: 15 additions & 11 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.41 2003-03-06 06:06:49 richard Exp $
19+
# $Id: admin.py,v 1.42 2003-03-06 07:33:29 richard Exp $
2020

2121
'''Administration commands for maintaining Roundup trackers.
2222
'''
@@ -921,7 +921,9 @@ def do_export(self, args):
921921
properties = cl.getprops()
922922
propnames = properties.keys()
923923
propnames.sort()
924-
print >> f, p.join(propnames)
924+
l = propnames[:]
925+
l.append('is retired')
926+
print >> f, p.join(l)
925927

926928
# all nodes for this class (not using list() 'cos it doesn't
927929
# include retired nodes)
@@ -965,14 +967,16 @@ class to import.
965967
cl = self.get_class(classname)
966968
p = csv.parser(field_sep=':')
967969
file_props = p.parse(f.readline())
968-
properties = cl.getprops()
969-
propnames = properties.keys()
970-
propnames.sort()
971-
m = file_props[:]
972-
m.sort()
973-
if m != propnames:
974-
raise UsageError, _('Import file doesn\'t define the same '
975-
'properties as "%(arg0)s".')%{'arg0': args[0]}
970+
971+
# XXX we don't _really_ need to do this...
972+
# properties = cl.getprops()
973+
# propnames = properties.keys()
974+
# propnames.sort()
975+
# m = file_props[:]
976+
# m.sort()
977+
# if m != propnames:
978+
# raise UsageError, _('Import file doesn\'t define the same '
979+
# 'properties as "%(arg0)s".')%{'arg0': args[0]}
976980

977981
# loop through the file and create a node for each entry
978982
maxid = 1
@@ -989,7 +993,7 @@ class to import.
989993
raise ValueError, "Unexpected EOF during CSV parse"
990994

991995
# do the import and figure the current highest nodeid
992-
maxid = max(maxid, int(cl.import_list(propnames, l)))
996+
maxid = max(maxid, int(cl.import_list(file_props, l)))
993997

994998
print 'setting', classname, maxid+1
995999
self.db.setid(classname, str(maxid+1))

roundup/backends/back_anydbm.py

Lines changed: 16 additions & 9 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.108 2003-03-03 21:05:17 richard Exp $
18+
#$Id: back_anydbm.py,v 1.109 2003-03-06 07:33:29 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
@@ -920,22 +920,29 @@ def import_list(self, propnames, proplist):
920920

921921
# make the new node's property map
922922
d = {}
923+
newid = None
923924
for i in range(len(propnames)):
924-
# Use eval to reverse the repr() used to output the CSV
925-
value = eval(proplist[i])
926-
927925
# Figure the property for this column
928926
propname = propnames[i]
929-
prop = properties[propname]
927+
928+
# Use eval to reverse the repr() used to output the CSV
929+
value = eval(proplist[i])
930930

931931
# "unmarshal" where necessary
932932
if propname == 'id':
933933
newid = value
934934
continue
935+
elif propname == 'is retired':
936+
# is the item retired?
937+
if int(value):
938+
d[self.db.RETIRED_FLAG] = 1
939+
continue
935940
elif value is None:
936941
# don't set Nones
937942
continue
938-
elif isinstance(prop, hyperdb.Date):
943+
944+
prop = properties[propname]
945+
if isinstance(prop, hyperdb.Date):
939946
value = date.Date(value)
940947
elif isinstance(prop, hyperdb.Interval):
941948
value = date.Interval(value)
@@ -945,9 +952,9 @@ def import_list(self, propnames, proplist):
945952
value = pwd
946953
d[propname] = value
947954

948-
# check retired flag
949-
if int(proplist[-1]):
950-
d[self.db.RETIRED_FLAG] = 1
955+
# get a new id if necessary
956+
if newid is None:
957+
newid = self.db.newid(self.classname)
951958

952959
# add the node and journal
953960
self.db.addnode(self.classname, newid, d)

roundup/backends/back_metakit.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,11 +1106,18 @@ def import_list(self, propnames, proplist):
11061106
value = eval(proplist[i])
11071107
if not value:
11081108
continue
1109+
11091110
propname = propnames[i]
1110-
prop = properties[propname]
11111111
if propname == 'id':
11121112
newid = value = int(value)
1113-
elif isinstance(prop, hyperdb.Date):
1113+
elif propname == 'is retired':
1114+
# is the item retired?
1115+
if int(value):
1116+
d['_isdel'] = 1
1117+
continue
1118+
1119+
prop = properties[propname]
1120+
if isinstance(prop, hyperdb.Date):
11141121
value = int(calendar.timegm(value))
11151122
elif isinstance(prop, hyperdb.Interval):
11161123
value = str(date.Interval(value))
@@ -1124,16 +1131,23 @@ def import_list(self, propnames, proplist):
11241131
# we handle multilinks separately
11251132
continue
11261133
d[propname] = value
1127-
# is the item retired?
1128-
if int(proplist[-1]):
1129-
d['_isdel'] = 1
1134+
1135+
# possibly make a new node
1136+
if not d.has_key('id'):
1137+
d['id'] = newid = self.maxid
1138+
self.maxid += 1
1139+
1140+
# save off the node
11301141
view.append(d)
11311142

1143+
# fix up multilinks
11321144
ndx = view.find(id=newid)
11331145
row = view[ndx]
11341146
for i in range(len(propnames)):
11351147
value = eval(proplist[i])
11361148
propname = propnames[i]
1149+
if propname == 'is retired':
1150+
continue
11371151
prop = properties[propname]
11381152
if not isinstance(prop, hyperdb.Multilink):
11391153
continue

roundup/backends/rdbms_common.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: rdbms_common.py,v 1.39 2003-03-06 06:03:51 richard Exp $
1+
# $Id: rdbms_common.py,v 1.40 2003-03-06 07:33:29 richard Exp $
22
''' Relational database (SQL) backend common code.
33
44
Basics:
@@ -450,8 +450,10 @@ def addnode(self, classname, nodeid, node):
450450

451451
# default the non-multilink columns
452452
for col, prop in cl.properties.items():
453-
if not isinstance(col, Multilink):
454-
if not node.has_key(col):
453+
if not node.has_key(col):
454+
if isinstance(prop, Multilink):
455+
node[col] = []
456+
else:
455457
node[col] = None
456458

457459
# clear this node out of the cache if it's in there
@@ -1100,19 +1102,27 @@ def import_list(self, propnames, proplist):
11001102

11011103
# make the new node's property map
11021104
d = {}
1105+
retire = 0
1106+
newid = None
11031107
for i in range(len(propnames)):
11041108
# Use eval to reverse the repr() used to output the CSV
11051109
value = eval(proplist[i])
11061110

11071111
# Figure the property for this column
11081112
propname = propnames[i]
1109-
prop = properties[propname]
11101113

11111114
# "unmarshal" where necessary
11121115
if propname == 'id':
11131116
newid = value
11141117
continue
1115-
elif value is None:
1118+
elif propname == 'is retired':
1119+
# is the item retired?
1120+
if int(value):
1121+
retire = 1
1122+
continue
1123+
1124+
prop = properties[propname]
1125+
if value is None:
11161126
# don't set Nones
11171127
continue
11181128
elif isinstance(prop, hyperdb.Date):
@@ -1125,8 +1135,12 @@ def import_list(self, propnames, proplist):
11251135
value = pwd
11261136
d[propname] = value
11271137

1138+
# get a new id if necessary
1139+
if newid is None:
1140+
newid = self.db.newid(self.classname)
1141+
11281142
# retire?
1129-
if int(proplist[-1]):
1143+
if retire:
11301144
# use the arg for __retired__ to cope with any odd database type
11311145
# conversion (hello, sqlite)
11321146
sql = 'update _%s set __retired__=%s where id=%s'%(self.classname,

0 commit comments

Comments
 (0)