1616# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1717# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1818#
19- # $Id: admin.py,v 1.102 2006-07-17 14:47:23 schlatterbeck Exp $
19+ # $Id: admin.py,v 1.103 2006-08-11 05:00:19 richard Exp $
2020
2121'''Administration commands for maintaining Roundup trackers.
2222'''
@@ -1055,10 +1055,13 @@ def do_restore(self, args):
10551055 return 0
10561056
10571057 def do_export (self , args ):
1058- "" '''Usage: export [class[,class]] export_dir
1058+ "" '''Usage: export [[-] class[,class]] export_dir
10591059 Export the database to colon-separated-value files.
1060+ To exclude the files (e.g. for the msg or file class),
1061+ use the exporttables command.
10601062
1061- Optionally limit the export to just the names classes.
1063+ Optionally limit the export to just the named classes
1064+ or exclude the named classes, if the 1st argument starts with '-'.
10621065
10631066 This action exports the current data from the database into
10641067 colon-separated-value files that are placed in the nominated
@@ -1072,7 +1075,11 @@ def do_export(self, args):
10721075
10731076 # get the list of classes to export
10741077 if len (args ) == 2 :
1075- classes = args [0 ].split (',' )
1078+ if args [0 ].startswith ('-' ):
1079+ classes = [ c for c in self .db .classes .keys ()
1080+ if not c in args [0 ][1 :].split (',' ) ]
1081+ else :
1082+ classes = args [0 ].split (',' )
10761083 else :
10771084 classes = self .db .classes .keys ()
10781085
@@ -1098,6 +1105,9 @@ class colon_separated(csv.excel):
10981105
10991106 # all nodes for this class
11001107 for nodeid in cl .getnodeids ():
1108+ if self .verbose :
1109+ sys .stdout .write ('Exporting %s - %s\r ' % (classname , nodeid ))
1110+ sys .stdout .flush ()
11011111 if self .verbose :
11021112 sys .stdout .write ('Exporting %s - %s\r ' % (classname , nodeid ))
11031113 sys .stdout .flush ()
@@ -1107,6 +1117,80 @@ class colon_separated(csv.excel):
11071117
11081118 # close this file
11091119 f .close ()
1120+ if self .verbose :
1121+ sys .stdout .write ("\n Exporting Journal for %s\n " % classname )
1122+ sys .stdout .flush ()
1123+ journals = csv .writer (jf , colon_separated )
1124+ map (journals .writerow , cl .export_journals ())
1125+ jf .close ()
1126+ return 0
1127+
1128+ def do_exporttables (self , args ):
1129+ "" '''Usage: exporttables [[-]class[,class]] export_dir
1130+ Export the database to colon-separated-value files, excluding the
1131+ files below $TRACKER_HOME/db/files/ (which can be archived separately).
1132+ To include the files, use the export command.
1133+
1134+ Optionally limit the export to just the named classes
1135+ or exclude the named classes, if the 1st argument starts with '-'.
1136+
1137+ This action exports the current data from the database into
1138+ colon-separated-value files that are placed in the nominated
1139+ destination directory.
1140+ '''
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 ("\n Exporting Journal for %s\n " % classname )
1193+ sys .stdout .flush ()
11101194
11111195 # export the journals
11121196 jf = open (os .path .join (dir , classname + '-journals.csv' ), 'wb' )
0 commit comments