diff --git a/src/pacroller/config.py b/src/pacroller/config.py index 21ae778..04aa05a 100644 --- a/src/pacroller/config.py +++ b/src/pacroller/config.py @@ -1,8 +1,12 @@ import json from pathlib import Path +import sys +import importlib.util +from typing import Any CONFIG_DIR = Path('/etc/pacroller') CONFIG_FILE = 'config.json' +F_KNOWN_OUTPUT_OVERRIDE = 'known_output_override.py' LIB_DIR = Path('/var/lib/pacroller') DB_FILE = 'db' PACMAN_CONFIG = '/etc/pacman.conf' @@ -16,6 +20,17 @@ if (cfg := (CONFIG_DIR / CONFIG_FILE)).exists(): else: _config = dict() +def _import_module(fpath: str) -> Any: + spec = importlib.util.spec_from_file_location(fpath.removesuffix('.py').replace('/', '.'), fpath) + mod = importlib.util.module_from_spec(spec) + spec.loader.exec_module(mod) + return mod +if (_komf := (CONFIG_DIR / F_KNOWN_OUTPUT_OVERRIDE)).exists(): + _kom = _import_module(str(_komf.resolve())) + KNOWN_OUTPUT_OVERRIDE = (_kom.KNOWN_HOOK_OUTPUT, _kom.KNOWN_PACKAGE_OUTPUT) +else: + KNOWN_OUTPUT_OVERRIDE = (dict(), dict()) + TIMEOUT = int(_config.get('timeout', 300)) UPGRADE_TIMEOUT = int(_config.get('upgrade_timeout', 3600)) NETWORK_RETRY = int(_config.get('network_retry', 5)) diff --git a/src/pacroller/known_output.py b/src/pacroller/known_output.py index 3377e9c..65fac4e 100644 --- a/src/pacroller/known_output.py +++ b/src/pacroller/known_output.py @@ -1,3 +1,6 @@ +from pacroller.config import KNOWN_OUTPUT_OVERRIDE +KNOWN_HOOK_OUTPUT_OVERRIDE, KNOWN_PACKAGE_OUTPUT_OVERRIDE = KNOWN_OUTPUT_OVERRIDE + KNOWN_HOOK_OUTPUT = { '': [], '20-systemd-sysusers.hook': [ @@ -15,7 +18,8 @@ KNOWN_HOOK_OUTPUT = { r'==> Creating (?:.+)-compressed initcpio image: .+', r'==> Image generation successful.*', r'[ ]+-> .+', - ] + ], + **KNOWN_HOOK_OUTPUT_OVERRIDE } _keyring_output = [ @@ -46,4 +50,5 @@ KNOWN_PACKAGE_OUTPUT = { r'Generation complete\.', r' .*_.*\.\.\. done', ], + **KNOWN_PACKAGE_OUTPUT_OVERRIDE } diff --git a/src/pacroller/known_output_override.py b/src/pacroller/known_output_override.py new file mode 100644 index 0000000..f5802f8 --- /dev/null +++ b/src/pacroller/known_output_override.py @@ -0,0 +1,7 @@ +KNOWN_HOOK_OUTPUT = { + 'example.hook': [], +} + +KNOWN_PACKAGE_OUTPUT = { + 'example-package': [], +}