Mercurial > p > roundup > code
comparison roundup/admin.py @ 2175:723098a10677
Export and import now include journals (incompatible with export < 0.7)
Need to check setting of activity in RDBMS imports.
Metakit import is quite possibly very busted in setjournal() - I didn't
even try to figure how to *clear the previous journal* for the journal
being imported.
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Fri, 02 Apr 2004 05:58:45 +0000 |
| parents | 3f6024ab2c7a |
| children | e1a481838a32 |
comparison
equal
deleted
inserted
replaced
| 2174:e19b391b6b95 | 2175:723098a10677 |
|---|---|
| 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.63 2004-03-21 23:39:08 richard Exp $ | 19 # $Id: admin.py,v 1.64 2004-04-02 05:58:43 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 |
| 1027 classes = self.db.classes.keys() | 1027 classes = self.db.classes.keys() |
| 1028 | 1028 |
| 1029 # do all the classes specified | 1029 # do all the classes specified |
| 1030 for classname in classes: | 1030 for classname in classes: |
| 1031 cl = self.get_class(classname) | 1031 cl = self.get_class(classname) |
| 1032 | |
| 1032 f = open(os.path.join(dir, classname+'.csv'), 'w') | 1033 f = open(os.path.join(dir, classname+'.csv'), 'w') |
| 1033 writer = rcsv.writer(f, rcsv.colon_separated) | 1034 writer = rcsv.writer(f, rcsv.colon_separated) |
| 1035 | |
| 1034 properties = cl.getprops() | 1036 properties = cl.getprops() |
| 1035 propnames = properties.keys() | 1037 propnames = properties.keys() |
| 1036 propnames.sort() | 1038 propnames.sort() |
| 1037 fields = propnames[:] | 1039 fields = propnames[:] |
| 1038 fields.append('is retired') | 1040 fields.append('is retired') |
| 1039 writer.writerow(fields) | 1041 writer.writerow(fields) |
| 1040 | 1042 |
| 1041 # all nodes for this class (not using list() 'cos it doesn't | 1043 # all nodes for this class |
| 1042 # include retired nodes) | 1044 for nodeid in cl.getnodeids(): |
| 1043 | 1045 writer.writerow(cl.export_list(propnames, nodeid)) |
| 1044 for nodeid in self.db.getclass(classname).getnodeids(): | |
| 1045 # get the regular props | |
| 1046 writer.writerow (cl.export_list(propnames, nodeid)) | |
| 1047 | 1046 |
| 1048 # close this file | 1047 # close this file |
| 1049 f.close() | 1048 f.close() |
| 1049 | |
| 1050 # export the journals | |
| 1051 jf = open(os.path.join(dir, classname+'-journals.csv'), 'w') | |
| 1052 journals = rcsv.writer(jf, rcsv.colon_separated) | |
| 1053 map(journals.writerow, cl.export_journals()) | |
| 1054 jf.close() | |
| 1050 return 0 | 1055 return 0 |
| 1051 | 1056 |
| 1052 def do_import(self, args): | 1057 def do_import(self, args): |
| 1053 '''Usage: import import_dir | 1058 '''Usage: import import_dir |
| 1054 Import a database from the directory containing CSV files, one per | 1059 Import a database from the directory containing CSV files, one per |
| 1055 class to import. | 1060 class to import. |
| 1056 | 1061 |
| 1057 The files must define the same properties as the class (including having | 1062 The files must define the same properties as the class (including |
| 1058 a "header" line with those property names.) | 1063 having a "header" line with those property names.) |
| 1059 | 1064 |
| 1060 The imported nodes will have the same nodeid as defined in the | 1065 The imported nodes will have the same nodeid as defined in the |
| 1061 import file, thus replacing any existing content. | 1066 import file, thus replacing any existing content. |
| 1062 | 1067 |
| 1063 The new nodes are added to the existing database - if you want to | 1068 The new nodes are added to the existing database - if you want to |
| 1069 if rcsv.error: | 1074 if rcsv.error: |
| 1070 raise UsageError, _(rcsv.error) | 1075 raise UsageError, _(rcsv.error) |
| 1071 from roundup import hyperdb | 1076 from roundup import hyperdb |
| 1072 | 1077 |
| 1073 for file in os.listdir(args[0]): | 1078 for file in os.listdir(args[0]): |
| 1079 classname, ext = os.path.splitext(file) | |
| 1074 # we only care about CSV files | 1080 # we only care about CSV files |
| 1075 if not file.endswith('.csv'): | 1081 if ext != '.csv' or classname.endswith('-journals'): |
| 1076 continue | 1082 continue |
| 1077 | 1083 |
| 1084 cl = self.get_class(classname) | |
| 1085 | |
| 1086 # ensure that the properties and the CSV file headings match | |
| 1078 f = open(os.path.join(args[0], file)) | 1087 f = open(os.path.join(args[0], file)) |
| 1079 | |
| 1080 # get the classname | |
| 1081 classname = os.path.splitext(file)[0] | |
| 1082 | |
| 1083 # ensure that the properties and the CSV file headings match | |
| 1084 cl = self.get_class(classname) | |
| 1085 reader = rcsv.reader(f, rcsv.colon_separated) | 1088 reader = rcsv.reader(f, rcsv.colon_separated) |
| 1086 file_props = None | 1089 file_props = None |
| 1087 maxid = 1 | 1090 maxid = 1 |
| 1088 | |
| 1089 # loop through the file and create a node for each entry | 1091 # loop through the file and create a node for each entry |
| 1090 for r in reader: | 1092 for r in reader: |
| 1091 if file_props is None: | 1093 if file_props is None: |
| 1092 file_props = r | 1094 file_props = r |
| 1093 continue | 1095 continue |
| 1094 | |
| 1095 # do the import and figure the current highest nodeid | 1096 # do the import and figure the current highest nodeid |
| 1096 maxid = max(maxid, int(cl.import_list(file_props, r))) | 1097 maxid = max(maxid, int(cl.import_list(file_props, r))) |
| 1098 f.close() | |
| 1099 | |
| 1100 # import the journals | |
| 1101 f = open(os.path.join(args[0], classname + '-journals.csv')) | |
| 1102 reader = rcsv.reader(f, rcsv.colon_separated) | |
| 1103 cl.import_journals(reader) | |
| 1104 f.close() | |
| 1097 | 1105 |
| 1098 # set the id counter | 1106 # set the id counter |
| 1099 print 'setting', classname, maxid+1 | 1107 print 'setting', classname, maxid+1 |
| 1100 self.db.setid(classname, str(maxid+1)) | 1108 self.db.setid(classname, str(maxid+1)) |
| 1109 | |
| 1101 return 0 | 1110 return 0 |
| 1102 | 1111 |
| 1103 def do_pack(self, args): | 1112 def do_pack(self, args): |
| 1104 '''Usage: pack period | date | 1113 '''Usage: pack period | date |
| 1105 | 1114 |
