comparison roundup/admin.py @ 3178:2ac85e66e9bb maint-0.8

remove rcsv
author Richard Jones <richard@users.sourceforge.net>
date Tue, 15 Feb 2005 00:22:24 +0000
parents accb3b411ef6
children afb69535a3a1
comparison
equal deleted inserted replaced
3177:d2592d790fd8 3178:2ac85e66e9bb
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.85 2004-11-09 23:12:11 richard Exp $ 19 # $Id: admin.py,v 1.85.2.1 2005-02-15 00:22:23 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
1035 destination directory. 1035 destination directory.
1036 ''' 1036 '''
1037 # grab the directory to export to 1037 # grab the directory to export to
1038 if len(args) < 1: 1038 if len(args) < 1:
1039 raise UsageError, _('Not enough arguments supplied') 1039 raise UsageError, _('Not enough arguments supplied')
1040 if rcsv.error:
1041 raise UsageError, _(rcsv.error)
1042 1040
1043 dir = args[-1] 1041 dir = args[-1]
1044 1042
1045 # get the list of classes to export 1043 # get the list of classes to export
1046 if len(args) == 2: 1044 if len(args) == 2:
1047 classes = args[0].split(',') 1045 classes = args[0].split(',')
1048 else: 1046 else:
1049 classes = self.db.classes.keys() 1047 classes = self.db.classes.keys()
1050 1048
1049 class colon_separated(csv.excel):
1050 delimiter = ':'
1051
1051 # do all the classes specified 1052 # do all the classes specified
1052 for classname in classes: 1053 for classname in classes:
1053 cl = self.get_class(classname) 1054 cl = self.get_class(classname)
1054 1055
1055 f = open(os.path.join(dir, classname+'.csv'), 'w') 1056 f = open(os.path.join(dir, classname+'.csv'), 'w')
1056 writer = rcsv.writer(f, rcsv.colon_separated) 1057 writer = csv.writer(f, colon_separated)
1057 1058
1058 properties = cl.getprops() 1059 properties = cl.getprops()
1059 propnames = cl.export_propnames() 1060 propnames = cl.export_propnames()
1060 fields = propnames[:] 1061 fields = propnames[:]
1061 fields.append('is retired') 1062 fields.append('is retired')
1070 # close this file 1071 # close this file
1071 f.close() 1072 f.close()
1072 1073
1073 # export the journals 1074 # export the journals
1074 jf = open(os.path.join(dir, classname+'-journals.csv'), 'w') 1075 jf = open(os.path.join(dir, classname+'-journals.csv'), 'w')
1075 journals = rcsv.writer(jf, rcsv.colon_separated) 1076 journals = csv.writer(jf, colon_separated)
1076 map(journals.writerow, cl.export_journals()) 1077 map(journals.writerow, cl.export_journals())
1077 jf.close() 1078 jf.close()
1078 return 0 1079 return 0
1079 1080
1080 def do_import(self, args): 1081 def do_import(self, args):
1097 create a new database using the imported data, then create a new 1098 create a new database using the imported data, then create a new
1098 database (or, tediously, retire all the old data.) 1099 database (or, tediously, retire all the old data.)
1099 ''' 1100 '''
1100 if len(args) < 1: 1101 if len(args) < 1:
1101 raise UsageError, _('Not enough arguments supplied') 1102 raise UsageError, _('Not enough arguments supplied')
1102 if rcsv.error:
1103 raise UsageError, _(rcsv.error)
1104 from roundup import hyperdb 1103 from roundup import hyperdb
1105 1104
1106 # directory to import from 1105 # directory to import from
1107 dir = args[0] 1106 dir = args[0]
1107
1108 class colon_separated(csv.excel):
1109 delimiter = ':'
1108 1110
1109 # import all the files 1111 # import all the files
1110 for file in os.listdir(dir): 1112 for file in os.listdir(dir):
1111 classname, ext = os.path.splitext(file) 1113 classname, ext = os.path.splitext(file)
1112 # we only care about CSV files 1114 # we only care about CSV files
1115 1117
1116 cl = self.get_class(classname) 1118 cl = self.get_class(classname)
1117 1119
1118 # ensure that the properties and the CSV file headings match 1120 # ensure that the properties and the CSV file headings match
1119 f = open(os.path.join(dir, file), 'rU') 1121 f = open(os.path.join(dir, file), 'rU')
1120 reader = rcsv.reader(f, rcsv.colon_separated) 1122 reader = csv.reader(f, csv.colon_separated)
1121 file_props = None 1123 file_props = None
1122 maxid = 1 1124 maxid = 1
1123 # loop through the file and create a node for each entry 1125 # loop through the file and create a node for each entry
1124 for r in reader: 1126 for r in reader:
1125 if file_props is None: 1127 if file_props is None:
1133 1135
1134 f.close() 1136 f.close()
1135 1137
1136 # import the journals 1138 # import the journals
1137 f = open(os.path.join(args[0], classname + '-journals.csv'), 'rU') 1139 f = open(os.path.join(args[0], classname + '-journals.csv'), 'rU')
1138 reader = rcsv.reader(f, rcsv.colon_separated) 1140 reader = csv.reader(f, csv.colon_separated)
1139 cl.import_journals(reader) 1141 cl.import_journals(reader)
1140 f.close() 1142 f.close()
1141 1143
1142 # set the id counter 1144 # set the id counter
1143 print 'setting', classname, maxid+1 1145 print 'setting', classname, maxid+1

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