diff --git a/kallithea/bin/kallithea_cli_base.py b/kallithea/bin/kallithea_cli_base.py --- a/kallithea/bin/kallithea_cli_base.py +++ b/kallithea/bin/kallithea_cli_base.py @@ -13,8 +13,10 @@ # along with this program. If not, see . import click +import cStringIO import functools import os +import re import sys import kallithea @@ -31,6 +33,19 @@ import paste.deploy kallithea_cli_path = sys.argv[0] +def read_config(ini_file_name, strip_section_prefix): + """Read ini_file_name content, and for all sections like '[X:Y]' where X is + strip_section_prefix, replace the section name with '[Y]'.""" + + def repl(m): + if m.group(1) == strip_section_prefix: + return '[%s]' % m.group(2) + return m.group(0) + + with open(ini_file_name) as f: + return re.sub(r'^\[([^:]+):(.*)]', repl, f.read(), flags=re.MULTILINE) + + # This placeholder is the main entry point for the kallithea-cli command @click.group(context_settings=dict(help_option_names=['-h', '--help'])) def cli(): @@ -55,7 +70,8 @@ def register_command(config_file=False, def runtime_wrapper(config_file, *args, **kwargs): path_to_ini_file = os.path.realpath(config_file) kallithea.CONFIG = paste.deploy.appconfig('config:' + path_to_ini_file) - logging.config.fileConfig(path_to_ini_file) + config_bytes = read_config(path_to_ini_file, strip_section_prefix=annotated.__name__) + logging.config.fileConfig(cStringIO.StringIO(config_bytes)) if config_file_initialize_app: kallithea.config.middleware.make_app_without_logging(kallithea.CONFIG.global_conf, **kallithea.CONFIG.local_conf) kallithea.lib.utils.setup_cache_regions(kallithea.CONFIG)