cfg: Allow loading multiple configuration files

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2020-06-23 19:51:23 -07:00 committed by James Valleroy
parent 9def9750c0
commit 2a38e60d1c
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
3 changed files with 8 additions and 7 deletions

View File

@ -136,7 +136,8 @@ def main():
web_framework.init()
logger.info('FreedomBox Service (Plinth) version - %s', __version__)
logger.info('Configuration loaded from file - %s', cfg.config_file)
for config_file in cfg.config_files:
logger.info('Configuration loaded from file - %s', config_file)
logger.info('Script prefix - %s', cfg.server_dir)
module_loader.include_urls()

View File

@ -47,7 +47,7 @@ box_name = 'FreedomBox'
# Other globals
develop = False
config_file = None
config_files = []
def get_fallback_config_paths():
@ -78,13 +78,13 @@ def read(config_path=None, root_directory=None):
# Ignore missing configuration files
return
global config_file # pylint: disable-msg=invalid-name,global-statement
config_file = config_path
# Keep a note of configuration files read.
config_files.append(config_path)
parser = configparser.ConfigParser(defaults={
'root': os.path.realpath(root_directory),
})
parser.read(config_file)
parser.read(config_path)
config_items = (
('Path', 'root', 'string'),

View File

@ -49,7 +49,7 @@ def test_read_primary_config_file(get_config_paths):
cfg.read()
assert cfg.config_file == expected_config_path
assert cfg.config_files[-1] == expected_config_path
assert cfg.root == expected_root_directory
@ -60,7 +60,7 @@ def test_read_fallback_config_file():
fallback_config_file = os.path.join(fallback_root, 'plinth.config')
config_path, root_directory = cfg.get_fallback_config_paths()
cfg.read(config_path, root_directory)
assert cfg.config_file == fallback_config_file
assert cfg.config_files[-1] == fallback_config_file
assert cfg.root == fallback_root