Browse Source

[PATCH] Make server_environment_files optional

Backport of d9ad47f40d
pull/1425/head
Guewen Baconnier 6 years ago
committed by Laurent Mignon (ACSONE)
parent
commit
ff3d867972
  1. 44
      server_environment/serv_config.py

44
server_environment/serv_config.py

@ -19,6 +19,7 @@
# #
############################################################################## ##############################################################################
import logging
import os import os
import ConfigParser import ConfigParser
from lxml import etree from lxml import etree
@ -29,8 +30,15 @@ from odoo.tools.config import config as system_base_config
from .system_info import get_server_environment from .system_info import get_server_environment
from odoo.addons import server_environment_files
_dir = os.path.dirname(server_environment_files.__file__)
_logger = logging.getLogger(__name__)
try:
from odoo.addons import server_environment_files
_dir = os.path.dirname(server_environment_files.__file__)
except ImportError:
_logger.info('not using server_environment_files for configuration,'
' no directory found')
_dir = None
# Same dict as RawConfigParser._boolean_states # Same dict as RawConfigParser._boolean_states
_boolean_states = {'1': True, 'yes': True, 'true': True, 'on': True, _boolean_states = {'1': True, 'yes': True, 'true': True, 'on': True,
@ -45,13 +53,15 @@ if not system_base_config.get('running_env', False):
"[options]\nrunning_env = dev" "[options]\nrunning_env = dev"
) )
ck_path = os.path.join(_dir, system_base_config['running_env'])
ck_path = None
if _dir:
ck_path = os.path.join(_dir, system_base_config['running_env'])
if not os.path.exists(ck_path):
raise Exception(
"Provided server environment does not exist, "
"please add a folder %s" % ck_path
)
if not os.path.exists(ck_path):
raise Exception(
"Provided server environment does not exist, "
"please add a folder %s" % ck_path
)
def setboolean(obj, attr, _bool=None): def setboolean(obj, attr, _bool=None):
@ -81,8 +91,7 @@ def _listconf(env_path):
return files return files
def _load_config():
"""Load the configuration and return a ConfigParser instance."""
def _load_config_from_server_env_files(config_p):
default = os.path.join(_dir, 'default') default = os.path.join(_dir, 'default')
running_env = os.path.join(_dir, running_env = os.path.join(_dir,
system_base_config['running_env']) system_base_config['running_env'])
@ -91,16 +100,25 @@ def _load_config():
else: else:
conf_files = _listconf(running_env) conf_files = _listconf(running_env)
config_p = ConfigParser.SafeConfigParser()
# options are case-sensitive
config_p.optionxform = str
try: try:
config_p.read(conf_files) config_p.read(conf_files)
except Exception as e: except Exception as e:
raise Exception('Cannot read config files "%s": %s' % (conf_files, e)) raise Exception('Cannot read config files "%s": %s' % (conf_files, e))
def _load_config_from_rcfile(config_p):
config_p.read(system_base_config.rcfile) config_p.read(system_base_config.rcfile)
config_p.remove_section('options') config_p.remove_section('options')
def _load_config():
"""Load the configuration and return a ConfigParser instance."""
config_p = ConfigParser.SafeConfigParser()
# options are case-sensitive
config_p.optionxform = str
if _dir:
_load_config_from_server_env_files(config_p)
_load_config_from_rcfile(config_p)
return config_p return config_p

Loading…
Cancel
Save