forked from osbuild/osbuild
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorg.osbuild.dnf-automatic.config
executable file
·46 lines (33 loc) · 1.16 KB
/
org.osbuild.dnf-automatic.config
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/python3
import sys
import iniparse
import osbuild.api
def bool_to_yes_no(b):
if b:
return "yes"
return "no"
def main(tree, options):
config = options.get("config")
dnf_automatic_config_path = f"{tree}/etc/dnf/automatic.conf"
dnf_automatic_conf = iniparse.SafeConfigParser()
# do not touch the config file if not needed
if config is None:
return 0
try:
with open(dnf_automatic_config_path, "r", encoding="utf8") as f:
dnf_automatic_conf.readfp(f)
except FileNotFoundError:
print(f"Error: DNF automatic configuration file '{dnf_automatic_config_path}' does not exist.")
return 1
for config_section, config_options in config.items():
for option, value in config_options.items():
if isinstance(value, bool):
value = bool_to_yes_no(value)
dnf_automatic_conf.set(config_section, option, value)
with open(dnf_automatic_config_path, "w", encoding="utf8") as f:
dnf_automatic_conf.write(f)
return 0
if __name__ == '__main__':
args = osbuild.api.arguments()
r = main(args["tree"], args["options"])
sys.exit(r)