19c19
< # $Id$
---
> # $Id: admin.py,v 1.102 2006/07/17 14:47:23 schlatterbeck Exp $
1058c1058
<         ""'''Usage: export [class[,class]] export_dir
---
>         ""'''Usage: export [[-]class[,class]] export_dir
1059a1060,1061
>         To exclude the files (e.g. for the msg or file class),
>         use the exporttables command.
1061c1063,1064
<         Optionally limit the export to just the names classes.
---
>         Optionally limit the export to just the named classes
>         or exclude the named classes, if the 1st argument starts with '-'.
1075c1078,1082
<             classes = args[0].split(',')
---
>             if args[0].startswith('-'):
>                 classes = [ c for c in self.db.classes.keys()
>                             if not c in args[0][1:].split(',') ]
>             else:
>                 classes = args[0].split(',')
1100a1108,1110
>                 if self.verbose:
>                     sys.stdout.write('Exporting %s - %s\r'%(classname, nodeid))
>                     sys.stdout.flush()
1109a1120,1193
>             if self.verbose:
>                 sys.stdout.write("\nExporting Journal for %s\n" % classname)
>                 sys.stdout.flush()
>             journals = csv.writer(jf, colon_separated)
>             map(journals.writerow, cl.export_journals())
>             jf.close()
>         return 0
> 
>     def do_exporttables(self, args):
>         ""'''Usage: exporttables [[-]class[,class]] export_dir
>         Export the database to colon-separated-value files, excluding the
>         files below $TRACKER_HOME/db/files/ (which can be archived separately).
>         To include the files, use the export command.
> 
>         Optionally limit the export to just the named classes
>         or exclude the named classes, if the 1st argument starts with '-'.
> 
>         This action exports the current data from the database into
>         colon-separated-value files that are placed in the nominated
>         destination directory.
>         '''
>         # grab the directory to export to
>         if len(args) < 1:
>             raise UsageError, _('Not enough arguments supplied')
> 
>         dir = args[-1]
> 
>         # get the list of classes to export
>         if len(args) == 2:
>             if args[0].startswith('-'):
>                 classes = [ c for c in self.db.classes.keys()
>                             if not c in args[0][1:].split(',') ]
>             else:
>                 classes = args[0].split(',')
>         else:
>             classes = self.db.classes.keys()
> 
>         class colon_separated(csv.excel):
>             delimiter = ':'
> 
>         # make sure target dir exists
>         if not os.path.exists(dir):
>             os.makedirs(dir)
> 
>         # do all the classes specified
>         for classname in classes:
>             cl = self.get_class(classname)
>             if hasattr(cl, 'export_files'):
>                 sys.stdout.write('Exporting %s WITHOUT the files\r\n' % classname)
> 
>             f = open(os.path.join(dir, classname+'.csv'), 'wb')
>             writer = csv.writer(f, colon_separated)
> 
>             properties = cl.getprops()
>             propnames = cl.export_propnames()
>             fields = propnames[:]
>             fields.append('is retired')
>             writer.writerow(fields)
> 
>             # all nodes for this class
>             for nodeid in cl.getnodeids():
>                 if self.verbose:
>                     sys.stdout.write('Exporting %s - %s\r'%(classname, nodeid))
>                     sys.stdout.flush()
>                 writer.writerow(cl.export_list(propnames, nodeid))
> 
>             # close this file
>             f.close()
> 
>             # export the journals
>             jf = open(os.path.join(dir, classname+'-journals.csv'), 'wb')
>             if self.verbose:
>                 sys.stdout.write("\nExporting Journal for %s\n" % classname)
>                 sys.stdout.flush()
1165,1166c1249,1251
<                 sys.stdout.write('Importing %s - %d\r'%(classname, n))
<                 sys.stdout.flush()
---
>                 if self.verbose:
>                     sys.stdout.write('Importing %s - %s\r'%(classname, n))
>                     sys.stdout.flush()
1402c1487
<             opts, args = getopt.getopt(sys.argv[1:], 'i:u:hcdsS:v')
---
>             opts, args = getopt.getopt(sys.argv[1:], 'i:u:hcdsS:vV')

 	  	 
