1
0
Fork 0
mirror of https://github.com/Kozea/Radicale.git synced 2025-08-01 18:18:31 +00:00

Remove global state about configuration and logs

Many things have been changed to make this possible, probably leading to
many hidden bugs waiting to be found.

Related to #122.
This commit is contained in:
Guillaume Ayoub 2016-04-22 11:37:02 +09:00
parent 8ac19ae0fc
commit 2f97d7d1e1
15 changed files with 576 additions and 488 deletions

View file

@ -24,7 +24,6 @@ Give a configparser-like interface to read and write configuration.
"""
import os
import sys
from configparser import RawConfigParser as ConfigParser
@ -66,18 +65,14 @@ INITIAL_CONFIG = {
"debug": "False",
"full_environment": "False"}}
# Create a ConfigParser and configure it
_CONFIG_PARSER = ConfigParser()
for section, values in INITIAL_CONFIG.items():
_CONFIG_PARSER.add_section(section)
for key, value in values.items():
_CONFIG_PARSER.set(section, key, value)
_CONFIG_PARSER.read("/etc/radicale/config")
_CONFIG_PARSER.read(os.path.expanduser("~/.config/radicale/config"))
if "RADICALE_CONFIG" in os.environ:
_CONFIG_PARSER.read(os.environ["RADICALE_CONFIG"])
# Wrap config module into ConfigParser instance
sys.modules[__name__] = _CONFIG_PARSER
def load(paths=()):
config = ConfigParser()
for section, values in INITIAL_CONFIG.items():
config.add_section(section)
for key, value in values.items():
config.set(section, key, value)
for path in paths:
if path:
config.read(path)
return config