From a7549bc652e6524891af46a883fb9a7c88622e2c Mon Sep 17 00:00:00 2001 From: Florian Mounier Date: Tue, 5 Jul 2016 17:50:40 +0200 Subject: [PATCH] Split the main run function to allow the use of radicale serving programatically. Add an extra_config parameter to the config load to override config. --- radicale/__main__.py | 5 +++++ radicale/config.py | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/radicale/__main__.py b/radicale/__main__.py index 8b5d5ae..a91c6c8 100644 --- a/radicale/__main__.py +++ b/radicale/__main__.py @@ -107,6 +107,11 @@ def run(): if not configuration_found: logger.warning("Configuration file '%s' not found" % options.config) + serve(configuration, logger) + + +def serve(configuration, logger): + """Serve radicale from configuration""" # Fork if Radicale is launched as daemon if configuration.getboolean("server", "daemon"): # Check and create PID file in a race-free manner diff --git a/radicale/config.py b/radicale/config.py index 83c00e4..5d5e69d 100644 --- a/radicale/config.py +++ b/radicale/config.py @@ -65,12 +65,16 @@ INITIAL_CONFIG = { "mask_passwords": "True"}} -def load(paths=()): +def load(paths=(), extra_config=None): config = ConfigParser() for section, values in INITIAL_CONFIG.items(): config.add_section(section) for key, value in values.items(): config.set(section, key, value) + if extra_config: + for section, values in extra_config.items(): + for key, value in values.items(): + config.set(section, key, value) for path in paths: if path: config.read(path)