From a36677eb70b92cf64fccb16075b7fec55660157f Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Wed, 17 Aug 2022 21:33:05 +0200 Subject: bring Hydrilla server part back to a usable state --- src/hydrilla/server/config.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'src/hydrilla/server/config.py') 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,20 +28,20 @@ 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 = { '$schema': 'http://json-schema.org/draft-07/schema#', 'type': 'object', 'properties': { - 'malcontent_dir': { - 'type': 'string' - }, 'malcontent_dir': { '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) -- cgit v1.2.3