diff options
author | Joey Hagedorn <hagedorn@mcs.anl.gov> | 2006-11-21 17:18:40 +0000 |
---|---|---|
committer | Joey Hagedorn <hagedorn@mcs.anl.gov> | 2006-11-21 17:18:40 +0000 |
commit | 1a8219748cd79c5e83c064460945f46c011048e8 (patch) | |
tree | 5942dc4cac7e6929a83bd335f4f0e25c068018a7 | |
parent | f0f03fc0bc128a68fd41464daeb37dbb119c9ac4 (diff) | |
download | bcfg2-1a8219748cd79c5e83c064460945f46c011048e8.tar.gz bcfg2-1a8219748cd79c5e83c064460945f46c011048e8.tar.bz2 bcfg2-1a8219748cd79c5e83c064460945f46c011048e8.zip |
New Reports: Let importscript accept -C flag to determine location of bcfg2.conf file (like other tools)
Importscript.py now reads bcfg2.conf for location of statistics.xml and clients.xml file, removing requirement for extra command line flags.
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@2509 ce84e21b-d406-0410-9b95-82705330c041
-rwxr-xr-x | reports/brpt/importscript.py | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/reports/brpt/importscript.py b/reports/brpt/importscript.py index df55fae33..252fce886 100755 --- a/reports/brpt/importscript.py +++ b/reports/brpt/importscript.py @@ -27,17 +27,20 @@ from getopt import getopt, GetoptError from datetime import datetime from time import strptime, sleep from django.db import connection, backend +import ConfigParser if __name__ == '__main__': somewhatverbose = False verbose = False veryverbose = False + try: opts, args = getopt(argv[1:], "hvudc:s:", ["help", "verbose", "updates" ,"debug", "clients=", "stats="]) except GetoptError, mesg: # print help information and exit: - print "%s\nUsage:\nimportscript.py [-h] [-v] [-u] [-d] -c <clients-file> -s <statistics-file>" % (mesg) + print "%s\nUsage:\nimportscript.py [-h] [-v] [-u] [-d] [-C bcfg2 config file] [-c clients-file] [-s statistics-file]" % (mesg) raise SystemExit, 2 + opts.append(("1","1"))#this requires the loop run at least once for o, a in opts: if o in ("-h", "--help"): print "Usage:\nimportscript.py [-h] [-v] -c <clients-file> -s <statistics-file> \n" @@ -45,9 +48,18 @@ if __name__ == '__main__': print "v : verbose; print messages on record insertion/skip" print "u : updates; print status messages as items inserted semi-verbose" print "d : debug; print most SQL used to manipulate database" + print "C : path to bcfg2.conf config file." print "c : clients.xml file" print "s : statistics.xml file" raise SystemExit + if o in ("-C"): + cpath = a + else: + cpath = "/etc/bcfg2.conf" + + cf = ConfigParser.ConfigParser() + cf.read([cpath]) + if o in ("-v", "--verbose"): verbose = True if o in ("-u", "--updates"): @@ -56,8 +68,21 @@ if __name__ == '__main__': veryverbose = True if o in ("-c", "--clients"): clientspath = a + else: + try: + clientspath = "%s/Metadata/clients.xml"%cf.get('server', 'repository') + except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): + print "Could not read bcfg2.conf; exiting" + raise SystemExit, 1 + if o in ("-s", "--stats"): statpath = a + else: + try: + statpath = "%s/etc/statistics.xml"%cf.get('server', 'repository') + except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): + print "Could not read bcfg2.conf; exiting" + raise SystemExit, 1 '''Reads Data & Config files''' try: |