summaryrefslogtreecommitdiffstats
path: root/src/lib/Bcfg2/settings.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/Bcfg2/settings.py')
-rw-r--r--src/lib/Bcfg2/settings.py74
1 files changed, 25 insertions, 49 deletions
diff --git a/src/lib/Bcfg2/settings.py b/src/lib/Bcfg2/settings.py
index 9393830a8..f3697d66f 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=W0602,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']
@@ -86,14 +86,6 @@ def read_config(cfile=DEFAULT_CONFIG, repo=None, quiet=False):
HOST=setup['db_host'],
PORT=setup['db_port'])
- if HAS_DJANGO and django.VERSION[0] == 1 and django.VERSION[1] < 2:
- DATABASE_ENGINE = setup['db_engine']
- DATABASE_NAME = DATABASES['default']['NAME']
- DATABASE_USER = DATABASES['default']['USER']
- DATABASE_PASSWORD = DATABASES['default']['PASSWORD']
- DATABASE_HOST = DATABASES['default']['HOST']
- DATABASE_PORT = DATABASES['default']['PORT']
-
# dropping the version check. This was added in 1.1.2
TIME_ZONE = setup['time_zone']
@@ -110,7 +102,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
@@ -159,16 +151,10 @@ else:
}
}
-if HAS_DJANGO and django.VERSION[0] == 1 and django.VERSION[1] < 2:
- TEMPLATE_LOADERS = (
- 'django.template.loaders.filesystem.load_template_source',
- 'django.template.loaders.app_directories.load_template_source',
- )
-else:
- TEMPLATE_LOADERS = (
- 'django.template.loaders.filesystem.Loader',
- 'django.template.loaders.app_directories.Loader',
- )
+TEMPLATE_LOADERS = (
+ 'django.template.loaders.filesystem.Loader',
+ 'django.template.loaders.app_directories.Loader',
+)
#TODO - review these. auth and sessions aren't really used
MIDDLEWARE_CLASSES = (
@@ -194,20 +180,10 @@ TEMPLATE_DIRS = (
'/usr/share/python-support/python-django/django/contrib/admin/templates/',
)
-# TODO - sanitize this
-if HAS_DJANGO and django.VERSION[0] == 1 and django.VERSION[1] < 2:
- TEMPLATE_CONTEXT_PROCESSORS = (
- 'django.core.context_processors.auth',
- 'django.core.context_processors.debug',
- 'django.core.context_processors.i18n',
- 'django.core.context_processors.media',
- 'django.core.context_processors.request'
- )
-else:
- TEMPLATE_CONTEXT_PROCESSORS = (
- 'django.contrib.auth.context_processors.auth',
- 'django.core.context_processors.debug',
- 'django.core.context_processors.i18n',
- 'django.core.context_processors.media',
- 'django.core.context_processors.request'
- )
+TEMPLATE_CONTEXT_PROCESSORS = (
+ 'django.contrib.auth.context_processors.auth',
+ 'django.core.context_processors.debug',
+ 'django.core.context_processors.i18n',
+ 'django.core.context_processors.media',
+ 'django.core.context_processors.request'
+)