From 9dad29caaf5fb37a07617a9e1462ac2b7b342419 Mon Sep 17 00:00:00 2001 From: Georges Racinet Date: Mon, 15 Dec 2014 19:52:24 +0100 Subject: [PATCH] Reintroduce fname kwarg in configmanager In [f04f409], the configmanager's __init__ lost its fname kwarg, which allows to pass the name of the config file to read (or write). Without it the only way to programmatically specify this file name is to use the OPENERP_SERVER environment variable, which may be unpractical and/or subject to renaming. External tools (such as the buildout recipe) may need to pass this file in a clean way. --- openerp/tools/config.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/openerp/tools/config.py b/openerp/tools/config.py index d5ab9be1b81..72663b31f1c 100644 --- a/openerp/tools/config.py +++ b/openerp/tools/config.py @@ -73,7 +73,13 @@ def _get_default_datadir(): return func(appname=release.product_name, appauthor=release.author) class configmanager(object): - def __init__(self): + def __init__(self, fname=None): + """Constructor. + + :param fname: a shortcut allowing to instantiate :class:`configmanager` + from Python code without resorting to environment + variable + """ # Options not exposed on the command line. Command line options will be added # from optparse's parser. self.options = { @@ -94,6 +100,7 @@ class configmanager(object): self.casts = {} self.misc = {} + self.config_file = fname self.has_ssl = check_ssl() self._LOGLEVELS = dict([ @@ -377,7 +384,7 @@ class configmanager(object): rcfilepath = os.path.expanduser('~/.openerp_serverrc') self.rcfile = os.path.abspath( - opt.config or os.environ.get('OPENERP_SERVER') or rcfilepath) + self.config_file or opt.config or os.environ.get('OPENERP_SERVER') or rcfilepath) self.load() # Verify that we want to log or not, if not the output will go to stdout