diff --git a/marconi/common/config.py b/marconi/common/config.py index 9d92d659d..5b9bda1e1 100644 --- a/marconi/common/config.py +++ b/marconi/common/config.py @@ -100,46 +100,42 @@ def _init(): for k, v in opts.items(): conf.register_cli_opt(_make_opt(k, v)) - @staticmethod - def set_cli(args): - """ - Save the CLI arguments. - - :param args: a list of CLI arguments in strings - """ - - my.args = [] - my.args.extend(args) - - @staticmethod - def load(config_file=None): - """Load the configurations from a config file. - - If the file name is not supplied, look for - - /etc/%project/%project.conf - - and - - ~/.%project/%project.conf - - :param config_file: the name of an alternative config file - """ - - if config_file is None: - conf(args=my.args, project=name, prog=name) - else: - conf(args=my.args, default_config_files=[config_file]) - def from_class(cls): grant_access_to_class(conf, cls) - cls.set_cli = set_cli - cls.load = load return cls return from_class(opaque_type_of(ConfigProxy, name))() - return Obj(from_options=from_options) + def set_cli(args): + """ + Save the CLI arguments. + + :param args: a list of CLI arguments in strings + """ + + my.args = [] + my.args.extend(args) + + def load(config_file=None): + """Load the configurations from a config file. + + If the file name is not supplied, look for + + /etc/%project/%project.conf + + and + + ~/.%project/%project.conf + + :param config_file: the name of an alternative config file + """ + + if config_file is None: + conf(args=my.args, project=name, prog=name) + else: + conf(args=my.args, default_config_files=[config_file]) + + return Obj(from_options=from_options, set_cli=set_cli, load=load) def opaque_type_of(base, postfix): return type('%s of %s' % (base.__name__, postfix), (base,), {}) diff --git a/marconi/kernel.py b/marconi/kernel.py index cdfaf2d64..b9d1ced3e 100644 --- a/marconi/kernel.py +++ b/marconi/kernel.py @@ -18,7 +18,7 @@ from marconi.storage import reference as storage from marconi.transport.wsgi import driver as wsgi -cfg = config.project('marconi').from_options() +cfg_handle = config.project('marconi') class Kernel(object): @@ -31,7 +31,7 @@ class Kernel(object): def __init__(self, config_file=None): #TODO(kgriffs): Error handling - cfg.load(config_file) + cfg_handle.load(config_file) #TODO(kgriffs): Determine driver types from cfg self.storage = storage.Driver() diff --git a/marconi/tests/test_config.py b/marconi/tests/test_config.py index 2b70e6540..5fc4e797a 100644 --- a/marconi/tests/test_config.py +++ b/marconi/tests/test_config.py @@ -19,7 +19,8 @@ from marconi.common import config from marconi.tests.util import suite -cfg = config.project().from_options( +cfg_handle = config.project() +cfg = cfg_handle.from_options( without_help=3, with_help=(None, "nonsense")) @@ -28,11 +29,11 @@ class TestConfig(suite.TestSuite): def test_cli(self): args = ['--with_help', 'sense'] - cfg.set_cli(args) - cfg.load(self.conf_path('wsgi_reference.conf')) + cfg_handle.set_cli(args) + cfg_handle.load(self.conf_path('wsgi_reference.conf')) self.assertEquals(cfg.with_help, 'sense') - cfg.set_cli([]) - cfg.load() + cfg_handle.set_cli([]) + cfg_handle.load() self.assertEquals(cfg.with_help, None) def test_wrong_type(self):