From ebe7542db7217c2fac3d7111e80f94caedfb69e2 Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Wed, 16 Jan 2013 13:28:06 -0500 Subject: added module-level OptionParser to avoid passing it as an argument or global all over --- src/lib/Bcfg2/settings.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'src/lib/Bcfg2/settings.py') diff --git a/src/lib/Bcfg2/settings.py b/src/lib/Bcfg2/settings.py index 190bdff58..da6e2036e 100644 --- a/src/lib/Bcfg2/settings.py +++ b/src/lib/Bcfg2/settings.py @@ -39,20 +39,20 @@ def _default_config(): """ get the default config file. returns /etc/bcfg2-web.conf, UNLESS /etc/bcfg2.conf exists AND /etc/bcfg2-web.conf does not exist. """ - optinfo = dict(cfile=Bcfg2.Options.CFILE, - web_cfile=Bcfg2.Options.WEB_CFILE) - setup = Bcfg2.Options.OptionParser(optinfo, quiet=True) - setup.parse(sys.argv[1:], do_getopt=False) - if (not os.path.exists(setup['web_cfile']) and - os.path.exists(setup['cfile'])): - return setup['cfile'] + setup = Bcfg2.Options.get_option_parser() + setup.add_option("configfile", Bcfg2.Options.CFILE) + setup.add_option("web_configfile", Bcfg2.Options.WEB_CFILE) + setup.reparse(argv=sys.argv[1:], do_getopt=False) + if (not os.path.exists(setup['web_configfile']) and + os.path.exists(setup['configfile'])): + return setup['configfile'] else: - return setup['web_cfile'] + return setup['web_configfile'] DEFAULT_CONFIG = _default_config() -def read_config(cfile=DEFAULT_CONFIG, repo=None, quiet=False): +def read_config(cfile=DEFAULT_CONFIG, repo=None): """ read the config file and set django settings based on it """ # pylint: disable=W0603 global DATABASE_ENGINE, DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD, \ @@ -65,15 +65,15 @@ def read_config(cfile=DEFAULT_CONFIG, repo=None, quiet=False): (cfile, DEFAULT_CONFIG)) cfile = DEFAULT_CONFIG - optinfo = Bcfg2.Options.DATABASE_COMMON_OPTIONS - optinfo['repo'] = Bcfg2.Options.SERVER_REPOSITORY # when setting a different config file, it has to be set in either # sys.argv or in the OptionSet() constructor AS WELL AS the argv # that's passed to setup.parse() argv = [Bcfg2.Options.CFILE.cmd, cfile, Bcfg2.Options.WEB_CFILE.cmd, cfile] - setup = Bcfg2.Options.OptionParser(optinfo, argv=argv, quiet=quiet) - setup.parse(argv) + setup = Bcfg2.Options.get_option_parser() + setup.add_options(Bcfg2.Options.DATABASE_COMMON_OPTIONS) + setup.add_option("repo", Bcfg2.Options.SERVER_REPOSITORY) + setup.reparse(argv=argv) if repo is None: repo = setup['repo'] @@ -110,7 +110,7 @@ def read_config(cfile=DEFAULT_CONFIG, repo=None, quiet=False): # initialize settings from /etc/bcfg2-web.conf or /etc/bcfg2.conf, or # set up basic defaults. this lets manage.py work in all cases -read_config(quiet=True) +read_config() ADMINS = (('Root', 'root')) MANAGERS = ADMINS -- cgit v1.2.3-1-g7c22