mirror of
https://github.com/isjerryxiao/pacroller.git
synced 2024-11-23 00:00:44 +08:00
change config and add update-merge-config.py
This commit is contained in:
parent
5579bd4231
commit
7035f0a719
3 changed files with 58 additions and 2 deletions
|
@ -17,7 +17,14 @@
|
||||||
"/etc/pacman.d/mirrorlist"
|
"/etc/pacman.d/mirrorlist"
|
||||||
],
|
],
|
||||||
"need_restart": false,
|
"need_restart": false,
|
||||||
"need_restart_cmd": ["needrestart", "-r", "a", "-m", "a", "-l"],
|
"need_restart_cmd": [
|
||||||
|
"needrestart",
|
||||||
|
"-r",
|
||||||
|
"a",
|
||||||
|
"-m",
|
||||||
|
"a",
|
||||||
|
"-l"
|
||||||
|
],
|
||||||
"systemd-check": true,
|
"systemd-check": true,
|
||||||
"clear_pkg_cache": false
|
"clear_pkg_cache": false
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ for i in IGNORED_PACNEW:
|
||||||
assert isinstance(i, str)
|
assert isinstance(i, str)
|
||||||
|
|
||||||
NEEDRESTART = bool(_config.get('need_restart', False))
|
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:
|
for i in NEEDRESTART_CMD:
|
||||||
assert isinstance(i, str)
|
assert isinstance(i, str)
|
||||||
|
|
||||||
|
|
49
src/pacroller/update-merge-config.py
Normal file
49
src/pacroller/update-merge-config.py
Normal file
|
@ -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()
|
Loading…
Reference in a new issue