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.
This commit is contained in:
Georges Racinet 2014-12-15 19:52:24 +01:00 committed by Antony Lesuisse
parent a9b4c56343
commit 9dad29caaf
1 changed files with 9 additions and 2 deletions

View File

@ -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