diff options
author | Robert Gogolok <gogo@cs.uni-sb.de> | 2007-12-30 19:26:51 +0000 |
---|---|---|
committer | Robert Gogolok <gogo@cs.uni-sb.de> | 2007-12-30 19:26:51 +0000 |
commit | e8c9ba57d10d174c79ac1aae9b53661ee8464d0f (patch) | |
tree | 65cb5f7b0c699e6c97eb365ec83c76155a023f7e /src/lib/Options.py | |
parent | 73ba22f7e519694dbf7010810de69b3b845f634f (diff) | |
download | bcfg2-e8c9ba57d10d174c79ac1aae9b53661ee8464d0f.tar.gz bcfg2-e8c9ba57d10d174c79ac1aae9b53661ee8464d0f.tar.bz2 bcfg2-e8c9ba57d10d174c79ac1aae9b53661ee8464d0f.zip |
Settings class to remove redundant code for parsing config file.
If a module wants to access bcfg2 settings:
from Bcfg2.Settings import settings
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@4131 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib/Options.py')
-rw-r--r-- | src/lib/Options.py | 25 |
1 files changed, 2 insertions, 23 deletions
diff --git a/src/lib/Options.py b/src/lib/Options.py index 4c97b1ca5..aab329f4d 100644 --- a/src/lib/Options.py +++ b/src/lib/Options.py @@ -2,20 +2,15 @@ __revision__ = '$Revision$' import getopt, os, sys, ConfigParser -# (option, env, cfpath, default value, option desc, boolean, arg desc) -# ((option, arg desc, opt desc), env, cfpath, default, boolean) -bootstrap = {'configfile': (('-C', '<configfile>', 'Path to config file'), - 'BCFG2_CONF', False, '/etc/bcfg2.conf', False)} class OptionFailure(Exception): pass class BasicOptionParser: '''Basic OptionParser takes input from command line arguments, environment variables, and defaults''' - def __init__(self, name, optionspec, configfile=False, dogetopt=False): + def __init__(self, name, optionspec, dogetopt=False): self.name = name self.dogetopt = dogetopt - self.configfile = configfile self.optionspec = optionspec if dogetopt: self.shortopt = '' @@ -52,13 +47,6 @@ class BasicOptionParser: print "%s Usage:" % (self.name) print self.helpmsg raise SystemExit, 1 - if self.configfile: - cf = ConfigParser.ConfigParser() - try: - cf.readfp(open(self.configfile)) - except Exception, e: - print "Failed to read configfile: %s\n%s\n" % (self.configfile, e) - raise SystemExit, 1 for key, (option, envvar, cfpath, default, boolean) in self.optionspec.iteritems(): if self.dogetopt: optinfo = [opt[1] for opt in opts if opt[0] == option[0]] @@ -77,19 +65,10 @@ class BasicOptionParser: if envvar and os.environ.has_key(envvar): ret[key] = os.environ[envvar] continue - if self.configfile and cfpath: - try: - value = apply(cf.get, cfpath) - ret[key] = value - continue - except: - pass ret[key] = default return ret class OptionParser(BasicOptionParser): '''OptionParser bootstraps option parsing, getting the value of the config file''' def __init__(self, name, ospec): - # first find the cf file - cfpath = BasicOptionParser('bootstrap', bootstrap).parse()['configfile'] - BasicOptionParser.__init__(self, name, ospec, cfpath, dogetopt=True) + BasicOptionParser.__init__(self, name, ospec, dogetopt=True) |