Skip to content

Commit 29069cc

Browse files
author
Richard Jones
committed
fix importing into anydbm backend [SF#1512939]
also, refactored last patch
1 parent 2ecc8d1 commit 29069cc

File tree

2 files changed

+15
-68
lines changed

2 files changed

+15
-68
lines changed

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ Fixed:
3131
- fix error during mailgw bouncing message (sf bug 1413501)
3232
- hyperdb handling of empty raw values for Multilink and Password (sf bug
3333
1507814)
34+
- don't int() ids (sf bug 1512939)
35+
- fix importing into anydbm backend (sf bug 1512939)
3436

3537

3638
2006-04-27 1.1.2

roundup/admin.py

Lines changed: 13 additions & 68 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.103 2006-08-11 05:00:19 richard Exp $
19+
# $Id: admin.py,v 1.104 2006-08-11 05:10:15 richard Exp $
2020

2121
'''Administration commands for maintaining Roundup trackers.
2222
'''
@@ -1054,7 +1054,7 @@ def do_restore(self, args):
10541054
raise UsageError, _('no such %(classname)s node "%(nodeid)s"')%locals()
10551055
return 0
10561056

1057-
def do_export(self, args):
1057+
def do_export(self, args, export_files=True):
10581058
""'''Usage: export [[-]class[,class]] export_dir
10591059
Export the database to colon-separated-value files.
10601060
To exclude the files (e.g. for the msg or file class),
@@ -1094,6 +1094,10 @@ class colon_separated(csv.excel):
10941094
for classname in classes:
10951095
cl = self.get_class(classname)
10961096

1097+
if not export_files and hasattr(cl, 'export_files'):
1098+
sys.stdout.write('Exporting %s WITHOUT the files\r\n'%
1099+
classname)
1100+
10971101
f = open(os.path.join(dir, classname+'.csv'), 'wb')
10981102
writer = csv.writer(f, colon_separated)
10991103

@@ -1112,11 +1116,14 @@ class colon_separated(csv.excel):
11121116
sys.stdout.write('Exporting %s - %s\r'%(classname, nodeid))
11131117
sys.stdout.flush()
11141118
writer.writerow(cl.export_list(propnames, nodeid))
1115-
if hasattr(cl, 'export_files'):
1119+
if export_files and hasattr(cl, 'export_files'):
11161120
cl.export_files(dir, nodeid)
11171121

11181122
# close this file
11191123
f.close()
1124+
1125+
# export the journals
1126+
jf = open(os.path.join(dir, classname+'-journals.csv'), 'wb')
11201127
if self.verbose:
11211128
sys.stdout.write("\nExporting Journal for %s\n" % classname)
11221129
sys.stdout.flush()
@@ -1138,69 +1145,7 @@ def do_exporttables(self, args):
11381145
colon-separated-value files that are placed in the nominated
11391146
destination directory.
11401147
'''
1141-
# grab the directory to export to
1142-
if len(args) < 1:
1143-
raise UsageError, _('Not enough arguments supplied')
1144-
1145-
dir = args[-1]
1146-
1147-
# get the list of classes to export
1148-
if len(args) == 2:
1149-
if args[0].startswith('-'):
1150-
classes = [ c for c in self.db.classes.keys()
1151-
if not c in args[0][1:].split(',') ]
1152-
else:
1153-
classes = args[0].split(',')
1154-
else:
1155-
classes = self.db.classes.keys()
1156-
1157-
class colon_separated(csv.excel):
1158-
delimiter = ':'
1159-
1160-
# make sure target dir exists
1161-
if not os.path.exists(dir):
1162-
os.makedirs(dir)
1163-
1164-
# do all the classes specified
1165-
for classname in classes:
1166-
cl = self.get_class(classname)
1167-
if hasattr(cl, 'export_files'):
1168-
sys.stdout.write('Exporting %s WITHOUT the files\r\n' % classname)
1169-
1170-
f = open(os.path.join(dir, classname+'.csv'), 'wb')
1171-
writer = csv.writer(f, colon_separated)
1172-
1173-
properties = cl.getprops()
1174-
propnames = cl.export_propnames()
1175-
fields = propnames[:]
1176-
fields.append('is retired')
1177-
writer.writerow(fields)
1178-
1179-
# all nodes for this class
1180-
for nodeid in cl.getnodeids():
1181-
if self.verbose:
1182-
sys.stdout.write('Exporting %s - %s\r'%(classname, nodeid))
1183-
sys.stdout.flush()
1184-
writer.writerow(cl.export_list(propnames, nodeid))
1185-
1186-
# close this file
1187-
f.close()
1188-
1189-
# export the journals
1190-
jf = open(os.path.join(dir, classname+'-journals.csv'), 'wb')
1191-
if self.verbose:
1192-
sys.stdout.write("\nExporting Journal for %s\n" % classname)
1193-
sys.stdout.flush()
1194-
1195-
# export the journals
1196-
jf = open(os.path.join(dir, classname+'-journals.csv'), 'wb')
1197-
if self.verbose:
1198-
sys.stdout.write("\nExporting Journal for %s\n" % classname)
1199-
sys.stdout.flush()
1200-
journals = csv.writer(jf, colon_separated)
1201-
map(journals.writerow, cl.export_journals())
1202-
jf.close()
1203-
return 0
1148+
return self.do_export(args, export_files=False)
12041149

12051150
def do_import(self, args):
12061151
""'''Usage: import import_dir
@@ -1257,10 +1202,10 @@ class colon_separated(csv.excel):
12571202
sys.stdout.flush()
12581203

12591204
# do the import and figure the current highest nodeid
1260-
nodeid = int(cl.import_list(file_props, r))
1205+
nodeid = cl.import_list(file_props, r)
12611206
if hasattr(cl, 'import_files'):
12621207
cl.import_files(dir, nodeid)
1263-
maxid = max(maxid, nodeid)
1208+
maxid = max(maxid, int(nodeid))
12641209
print
12651210
f.close()
12661211

0 commit comments

Comments
 (0)