comparison roundup/admin.py @ 3179:88dbe6b3d891

merge removal of rcsv
author Richard Jones <richard@users.sourceforge.net>
date Tue, 15 Feb 2005 00:23:30 +0000
parents 7c438646531a
children 6d0b5937ee0d
comparison
equal deleted inserted replaced
3176:18ad9d702a5b 3179:88dbe6b3d891
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.86 2004-12-08 03:18:46 richard Exp $ 19 # $Id: admin.py,v 1.87 2005-02-15 00:23:30 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
25 import sys, os, getpass, getopt, re, UserDict, shutil, rfc822 25 import sys, os, getpass, getopt, re, UserDict, shutil, rfc822
26 from roundup import date, hyperdb, roundupdb, init, password, token, rcsv 26 from roundup import date, hyperdb, roundupdb, init, password, token, csv
27 from roundup import __version__ as roundup_version 27 from roundup import __version__ as roundup_version
28 import roundup.instance 28 import roundup.instance
29 from roundup.configuration import CoreConfig 29 from roundup.configuration import CoreConfig
30 from roundup.i18n import _ 30 from roundup.i18n import _
31 31
1038 destination directory. 1038 destination directory.
1039 ''' 1039 '''
1040 # grab the directory to export to 1040 # grab the directory to export to
1041 if len(args) < 1: 1041 if len(args) < 1:
1042 raise UsageError, _('Not enough arguments supplied') 1042 raise UsageError, _('Not enough arguments supplied')
1043 if rcsv.error:
1044 raise UsageError, _(rcsv.error)
1045 1043
1046 dir = args[-1] 1044 dir = args[-1]
1047 1045
1048 # get the list of classes to export 1046 # get the list of classes to export
1049 if len(args) == 2: 1047 if len(args) == 2:
1050 classes = args[0].split(',') 1048 classes = args[0].split(',')
1051 else: 1049 else:
1052 classes = self.db.classes.keys() 1050 classes = self.db.classes.keys()
1053 1051
1052 class colon_separated(csv.excel):
1053 delimiter = ':'
1054
1054 # do all the classes specified 1055 # do all the classes specified
1055 for classname in classes: 1056 for classname in classes:
1056 cl = self.get_class(classname) 1057 cl = self.get_class(classname)
1057 1058
1058 f = open(os.path.join(dir, classname+'.csv'), 'w') 1059 f = open(os.path.join(dir, classname+'.csv'), 'w')
1059 writer = rcsv.writer(f, rcsv.colon_separated) 1060 writer = csv.writer(f, colon_separated)
1060 1061
1061 properties = cl.getprops() 1062 properties = cl.getprops()
1062 propnames = cl.export_propnames() 1063 propnames = cl.export_propnames()
1063 fields = propnames[:] 1064 fields = propnames[:]
1064 fields.append('is retired') 1065 fields.append('is retired')
1073 # close this file 1074 # close this file
1074 f.close() 1075 f.close()
1075 1076
1076 # export the journals 1077 # export the journals
1077 jf = open(os.path.join(dir, classname+'-journals.csv'), 'w') 1078 jf = open(os.path.join(dir, classname+'-journals.csv'), 'w')
1078 journals = rcsv.writer(jf, rcsv.colon_separated) 1079 journals = csv.writer(jf, colon_separated)
1079 map(journals.writerow, cl.export_journals()) 1080 map(journals.writerow, cl.export_journals())
1080 jf.close() 1081 jf.close()
1081 return 0 1082 return 0
1082 1083
1083 def do_import(self, args): 1084 def do_import(self, args):
1100 create a new database using the imported data, then create a new 1101 create a new database using the imported data, then create a new
1101 database (or, tediously, retire all the old data.) 1102 database (or, tediously, retire all the old data.)
1102 ''' 1103 '''
1103 if len(args) < 1: 1104 if len(args) < 1:
1104 raise UsageError, _('Not enough arguments supplied') 1105 raise UsageError, _('Not enough arguments supplied')
1105 if rcsv.error:
1106 raise UsageError, _(rcsv.error)
1107 from roundup import hyperdb 1106 from roundup import hyperdb
1108 1107
1109 # directory to import from 1108 # directory to import from
1110 dir = args[0] 1109 dir = args[0]
1110
1111 class colon_separated(csv.excel):
1112 delimiter = ':'
1111 1113
1112 # import all the files 1114 # import all the files
1113 for file in os.listdir(dir): 1115 for file in os.listdir(dir):
1114 classname, ext = os.path.splitext(file) 1116 classname, ext = os.path.splitext(file)
1115 # we only care about CSV files 1117 # we only care about CSV files
1118 1120
1119 cl = self.get_class(classname) 1121 cl = self.get_class(classname)
1120 1122
1121 # ensure that the properties and the CSV file headings match 1123 # ensure that the properties and the CSV file headings match
1122 f = open(os.path.join(dir, file), 'rU') 1124 f = open(os.path.join(dir, file), 'rU')
1123 reader = rcsv.reader(f, rcsv.colon_separated) 1125 reader = csv.reader(f, csv.colon_separated)
1124 file_props = None 1126 file_props = None
1125 maxid = 1 1127 maxid = 1
1126 # loop through the file and create a node for each entry 1128 # loop through the file and create a node for each entry
1127 for r in reader: 1129 for r in reader:
1128 if file_props is None: 1130 if file_props is None:
1136 1138
1137 f.close() 1139 f.close()
1138 1140
1139 # import the journals 1141 # import the journals
1140 f = open(os.path.join(args[0], classname + '-journals.csv'), 'rU') 1142 f = open(os.path.join(args[0], classname + '-journals.csv'), 'rU')
1141 reader = rcsv.reader(f, rcsv.colon_separated) 1143 reader = csv.reader(f, csv.colon_separated)
1142 cl.import_journals(reader) 1144 cl.import_journals(reader)
1143 f.close() 1145 f.close()
1144 1146
1145 # set the id counter 1147 # set the id counter
1146 print 'setting', classname, maxid+1 1148 print 'setting', classname, maxid+1

Roundup Issue Tracker: http://roundup-tracker.org/