Mercurial > p > roundup > code
comparison roundup/admin.py @ 2496:682eefe8ef23
WIP
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Thu, 24 Jun 2004 06:39:07 +0000 |
| parents | ea7fb2f416db |
| children | d084aea1910f |
comparison
equal
deleted
inserted
replaced
| 2494:ea7fb2f416db | 2496:682eefe8ef23 |
|---|---|
| 14 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | 14 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 15 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" | 15 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" |
| 16 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, | 16 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, |
| 17 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | 17 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
| 18 # | 18 # |
| 19 # $Id: admin.py,v 1.73 2004-06-23 23:19:07 richard Exp $ | 19 # $Id: admin.py,v 1.74 2004-06-24 06:39:04 richard Exp $ |
| 20 | 20 |
| 21 '''Administration commands for maintaining Roundup trackers. | 21 '''Administration commands for maintaining Roundup trackers. |
| 22 ''' | 22 ''' |
| 23 __docformat__ = 'restructuredtext' | 23 __docformat__ = 'restructuredtext' |
| 24 | 24 |
| 1035 | 1035 |
| 1036 f = open(os.path.join(dir, classname+'.csv'), 'w') | 1036 f = open(os.path.join(dir, classname+'.csv'), 'w') |
| 1037 writer = rcsv.writer(f, rcsv.colon_separated) | 1037 writer = rcsv.writer(f, rcsv.colon_separated) |
| 1038 | 1038 |
| 1039 properties = cl.getprops() | 1039 properties = cl.getprops() |
| 1040 propnames = properties.keys() | 1040 propnames = cl.export_propnames() |
| 1041 propnames.sort() | |
| 1042 fields = propnames[:] | 1041 fields = propnames[:] |
| 1043 fields.append('is retired') | 1042 fields.append('is retired') |
| 1044 writer.writerow(fields) | 1043 writer.writerow(fields) |
| 1045 | 1044 |
| 1046 # all nodes for this class | 1045 # all nodes for this class |
| 1047 for nodeid in cl.getnodeids(): | 1046 for nodeid in cl.getnodeids(): |
| 1048 writer.writerow(cl.export_list(propnames, nodeid)) | 1047 writer.writerow(cl.export_list(propnames, nodeid)) |
| 1048 if hasattr(cl, 'export_files'): | |
| 1049 cl.export_files(dir, nodeid) | |
| 1049 | 1050 |
| 1050 # close this file | 1051 # close this file |
| 1051 f.close() | 1052 f.close() |
| 1052 | 1053 |
| 1053 # export the journals | 1054 # export the journals |
| 1081 raise UsageError, _('Not enough arguments supplied') | 1082 raise UsageError, _('Not enough arguments supplied') |
| 1082 if rcsv.error: | 1083 if rcsv.error: |
| 1083 raise UsageError, _(rcsv.error) | 1084 raise UsageError, _(rcsv.error) |
| 1084 from roundup import hyperdb | 1085 from roundup import hyperdb |
| 1085 | 1086 |
| 1086 for file in os.listdir(args[0]): | 1087 # directory to import from |
| 1088 dir = args[0] | |
| 1089 | |
| 1090 # import all the files | |
| 1091 for file in os.listdir(dir): | |
| 1087 classname, ext = os.path.splitext(file) | 1092 classname, ext = os.path.splitext(file) |
| 1088 # we only care about CSV files | 1093 # we only care about CSV files |
| 1089 if ext != '.csv' or classname.endswith('-journals'): | 1094 if ext != '.csv' or classname.endswith('-journals'): |
| 1090 continue | 1095 continue |
| 1091 | 1096 |
| 1092 cl = self.get_class(classname) | 1097 cl = self.get_class(classname) |
| 1093 | 1098 |
| 1094 # ensure that the properties and the CSV file headings match | 1099 # ensure that the properties and the CSV file headings match |
| 1095 f = open(os.path.join(args[0], file)) | 1100 f = open(os.path.join(dir, file)) |
| 1096 reader = rcsv.reader(f, rcsv.colon_separated) | 1101 reader = rcsv.reader(f, rcsv.colon_separated) |
| 1097 file_props = None | 1102 file_props = None |
| 1098 maxid = 1 | 1103 maxid = 1 |
| 1099 # loop through the file and create a node for each entry | 1104 # loop through the file and create a node for each entry |
| 1100 for r in reader: | 1105 for r in reader: |
| 1101 if file_props is None: | 1106 if file_props is None: |
| 1102 file_props = r | 1107 file_props = r |
| 1103 continue | 1108 continue |
| 1104 # do the import and figure the current highest nodeid | 1109 # do the import and figure the current highest nodeid |
| 1105 maxid = max(maxid, int(cl.import_list(file_props, r))) | 1110 nodeid = int(cl.import_list(file_props, r)) |
| 1111 if hasattr(cl, 'import_files'): | |
| 1112 cl.import_files(dir, nodeid) | |
| 1113 maxid = max(maxid, nodeid) | |
| 1114 | |
| 1106 f.close() | 1115 f.close() |
| 1107 | 1116 |
| 1108 # import the journals | 1117 # import the journals |
| 1109 f = open(os.path.join(args[0], classname + '-journals.csv')) | 1118 f = open(os.path.join(args[0], classname + '-journals.csv')) |
| 1110 reader = rcsv.reader(f, rcsv.colon_separated) | 1119 reader = rcsv.reader(f, rcsv.colon_separated) |
