diff options
author | Wojtek Kosior <koszko@koszko.org> | 2022-08-17 21:33:05 +0200 |
---|---|---|
committer | Wojtek Kosior <koszko@koszko.org> | 2022-09-28 12:54:22 +0200 |
commit | a36677eb70b92cf64fccb16075b7fec55660157f (patch) | |
tree | a57b60853b0ad66ff3c233142c0431a5b1f5e05a /src/hydrilla/server/config.py | |
parent | d54a95e0f9c689f2bbaaea90a3a16a855a408823 (diff) | |
download | haketilo-hydrilla-a36677eb70b92cf64fccb16075b7fec55660157f.tar.gz haketilo-hydrilla-a36677eb70b92cf64fccb16075b7fec55660157f.zip |
bring Hydrilla server part back to a usable state
Diffstat (limited to 'src/hydrilla/server/config.py')
-rw-r--r-- | src/hydrilla/server/config.py | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/src/hydrilla/server/config.py b/src/hydrilla/server/config.py index c7c5657..7109eb1 100644 --- a/src/hydrilla/server/config.py +++ b/src/hydrilla/server/config.py @@ -28,11 +28,14 @@ from __future__ import annotations import json +import typing as t from pathlib import Path import jsonschema # type: ignore +from ..translations import smart_gettext as _ +from ..exceptions import HaketiloException from .. import json_instances config_schema = { @@ -42,9 +45,6 @@ config_schema = { 'malcontent_dir': { 'type': 'string' }, - 'malcontent_dir': { - 'type': 'string' - }, 'hydrilla_project_url': { 'type': 'string' }, @@ -67,6 +67,9 @@ config_schema = { }, 'werror': { 'type': 'boolean' + }, + 'verify_files': { + 'type': 'boolean' } } } @@ -75,7 +78,7 @@ here = Path(__file__).resolve().parent def load(config_paths: list[Path]=[here / 'config.json'], can_fail: list[bool]=[]) -> dict: - config = {} + config: dict[str, t.Any] = {} bools_missing = max(0, len(config_paths) - len(can_fail)) config_paths = [*config_paths] @@ -92,17 +95,13 @@ def load(config_paths: list[Path]=[here / 'config.json'], continue raise e from None - new_config = json_instances.strip_json_comments(json_text) + new_config = json.loads(json_instances.strip_json_comments(json_text)) jsonschema.validate(new_config, config_schema) config.update(new_config) - if 'malcontent_dir' in config: - malcontent_dir = Path(config['malcontent_dir']) - if not malcontent_dir.is_absolute(): - malcontent_dir = path.parent / malcontent_dir - - config['malcontent_dir'] = str(malcontent_dir.resolve()) + if 'malcontent_dir' in new_config: + malcontent_path_relative_to = path.parent for key, failure_ok in [('try_configs', True), ('use_configs', False)]: paths = new_config.get(key, []) @@ -110,6 +109,12 @@ def load(config_paths: list[Path]=[here / 'config.json'], config_paths.extend(paths) can_fail.extend([failure_ok] * len(paths)) + + if 'malcontent_dir' in config: + malcontent_dir_str = config['malcontent_dir'] + malcontent_dir_path = malcontent_path_relative_to / malcontent_dir_str + config['malcontent_dir'] = str(malcontent_dir_path) + for key in ('try_configs', 'use_configs'): if key in config: config.pop(key) |