diff --git a/src/pacroller/config.json.example b/src/pacroller/config.json.example index 997e270..beb1db9 100644 --- a/src/pacroller/config.json.example +++ b/src/pacroller/config.json.example @@ -17,7 +17,14 @@ "/etc/pacman.d/mirrorlist" ], "need_restart": false, - "need_restart_cmd": ["needrestart", "-r", "a", "-m", "a", "-l"], + "need_restart_cmd": [ + "needrestart", + "-r", + "a", + "-m", + "a", + "-l" + ], "systemd-check": true, "clear_pkg_cache": false } diff --git a/src/pacroller/config.py b/src/pacroller/config.py index 91d7ded..13804c6 100644 --- a/src/pacroller/config.py +++ b/src/pacroller/config.py @@ -58,7 +58,7 @@ for i in IGNORED_PACNEW: assert isinstance(i, str) NEEDRESTART = bool(_config.get('need_restart', False)) -NEEDRESTART_CMD = _config.get('need_restart_cmd', False) +NEEDRESTART_CMD = _config.get('need_restart_cmd', ["needrestart", "-r", "a", "-m", "a", "-l"]) for i in NEEDRESTART_CMD: assert isinstance(i, str) diff --git a/src/pacroller/update-merge-config.py b/src/pacroller/update-merge-config.py new file mode 100644 index 0000000..2a36a2b --- /dev/null +++ b/src/pacroller/update-merge-config.py @@ -0,0 +1,49 @@ +#!/usr/bin/python + +from pacroller.config import CONFIG_DIR, CONFIG_FILE +import json + +def main() -> None: + oldcfg = CONFIG_DIR / CONFIG_FILE + newcfg = CONFIG_DIR / f"{CONFIG_FILE}.pacnew" + assert oldcfg.exists() + assert newcfg.exists() + old: dict = json.loads(oldcfg.read_text()) + new: dict = json.loads(newcfg.read_text()) + new_copy = new.copy() + for k, v in new.items(): + if isinstance(v, (int, str, bool)): + if old.get(k, None) is None: + print(f"use default value {k} = {v} for new option {k}") + else: + if old[k] != v: + print(f"use custom value {k} = {old[k]} while default value is {v}") + new_copy[k] = old[k] + elif isinstance(v, list): + if k == "need_restart_cmd": + if old[k] != v: + print(f"use custom value {k} = {old[k]} while default value is {v}") + new_copy[k] = old[k] + else: + _new = list() + for _item in [*old[k], *v]: + if _item not in _new: + _new.append(_item) + if _new != old[k]: + print(f"merged {old[k]} and {v} to {_new}") + new_copy[k] = _new + elif isinstance(v, dict): + for _o in old.get(k, {}): + if v.get(_o) != old[k][_o]: + print(f"use custom value {k}[{_o}] = {old[k][_o]} while default value is {v.get(_o)}") + new_copy[k][_o] = old[k][_o] + for _o in v: + if _o not in old.get(k, {}): + print(f"new value {k}[{_o}] = {v[_o]}") + + oldcfg.rename(CONFIG_DIR / f"{CONFIG_FILE}.pacsave") + oldcfg.write_text(json.dumps(new_copy, indent=4)) + print("wrote new config") + +if __name__ == '__main__': + main()