1616# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1717# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1818#
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 $
2020
2121'''Administration commands for maintaining Roundup trackers.
2222'''
@@ -1029,33 +1029,38 @@ def do_export(self, args):
10291029 # do all the classes specified
10301030 for classname in classes :
10311031 cl = self .get_class (classname )
1032+
10321033 f = open (os .path .join (dir , classname + '.csv' ), 'w' )
10331034 writer = rcsv .writer (f , rcsv .colon_separated )
1035+
10341036 properties = cl .getprops ()
10351037 propnames = properties .keys ()
10361038 propnames .sort ()
10371039 fields = propnames [:]
10381040 fields .append ('is retired' )
10391041 writer .writerow (fields )
10401042
1041- # all nodes for this class (not using list() 'cos it doesn't
1042- # include retired nodes)
1043-
1044- for nodeid in self .db .getclass (classname ).getnodeids ():
1045- # get the regular props
1046- writer .writerow (cl .export_list (propnames , nodeid ))
1043+ # all nodes for this class
1044+ for nodeid in cl .getnodeids ():
1045+ writer .writerow (cl .export_list (propnames , nodeid ))
10471046
10481047 # close this file
10491048 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 ()
10501055 return 0
10511056
10521057 def do_import (self , args ):
10531058 '''Usage: import import_dir
10541059 Import a database from the directory containing CSV files, one per
10551060 class to import.
10561061
1057- The files must define the same properties as the class (including having
1058- a "header" line with those property names.)
1062+ The files must define the same properties as the class (including
1063+ having a "header" line with those property names.)
10591064
10601065 The imported nodes will have the same nodeid as defined in the
10611066 import file, thus replacing any existing content.
@@ -1071,33 +1076,37 @@ class to import.
10711076 from roundup import hyperdb
10721077
10731078 for file in os .listdir (args [0 ]):
1079+ classname , ext = os .path .splitext (file )
10741080 # we only care about CSV files
1075- if not file . endswith ('.csv ' ):
1081+ if ext != '.csv' or classname . endswith ('-journals ' ):
10761082 continue
10771083
1078- f = open (os .path .join (args [0 ], file ))
1079-
1080- # get the classname
1081- classname = os .path .splitext (file )[0 ]
1084+ cl = self .get_class (classname )
10821085
10831086 # ensure that the properties and the CSV file headings match
1084- cl = self . get_class ( classname )
1087+ f = open ( os . path . join ( args [ 0 ], file ) )
10851088 reader = rcsv .reader (f , rcsv .colon_separated )
10861089 file_props = None
10871090 maxid = 1
1088-
10891091 # loop through the file and create a node for each entry
10901092 for r in reader :
10911093 if file_props is None :
10921094 file_props = r
10931095 continue
1094-
10951096 # do the import and figure the current highest nodeid
10961097 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 ()
10971105
10981106 # set the id counter
10991107 print 'setting' , classname , maxid + 1
11001108 self .db .setid (classname , str (maxid + 1 ))
1109+
11011110 return 0
11021111
11031112 def do_pack (self , args ):
0 commit comments