]> glassweightruler.freedombox.rocks Git - waydroid.git/blob - tools/config/load.py
tools: Add restart container
[waydroid.git] / tools / config / load.py
1 # Copyright 2021 Oliver Smith
2 # SPDX-License-Identifier: GPL-3.0-or-later
3 import logging
4 import configparser
5 import os
6 import tools.config
7
8
9 def load(args):
10 cfg = configparser.ConfigParser()
11 if os.path.isfile(args.config):
12 cfg.read(args.config)
13
14 if "waydroid" not in cfg:
15 cfg["waydroid"] = {}
16
17 for key in tools.config.defaults:
18 if key in tools.config.config_keys and key not in cfg["waydroid"]:
19 cfg["waydroid"][key] = str(tools.config.defaults[key])
20
21 # We used to save default values in the config, which can *not* be
22 # configured in "waydroid init". That doesn't make sense, we always
23 # want to use the defaults from tools/config/__init__.py in that case,
24 if key not in tools.config.config_keys and key in cfg["waydroid"]:
25 logging.debug("Ignored unconfigurable and possibly outdated"
26 " default value from config: {}".format(cfg['waydroid'][key]))
27 del cfg["waydroid"][key]
28
29 return cfg
30
31 def load_session():
32 config_path = tools.config.session_defaults["config_path"]
33 cfg = configparser.ConfigParser()
34 if os.path.isfile(config_path):
35 cfg.read(config_path)
36
37 if "session" not in cfg:
38 cfg["session"] = {}
39
40 for key in tools.config.session_defaults:
41 if key in tools.config.session_config_keys and key not in cfg["session"]:
42 cfg["session"][key] = str(tools.config.session_defaults[key])
43
44 if key not in tools.config.session_config_keys and key in cfg["session"]:
45 logging.debug("Ignored unconfigurable and possibly outdated"
46 " default value from config: {}".format(cfg['session'][key]))
47 del cfg["session"][key]
48
49 return cfg
50
51 def load_channels():
52 config_path = tools.config.channels_defaults["config_path"]
53 cfg = configparser.ConfigParser()
54 if os.path.isfile(config_path):
55 cfg.read(config_path)
56
57 if "channels" not in cfg:
58 cfg["channels"] = {}
59
60 for key in tools.config.channels_defaults:
61 if key in tools.config.channels_config_keys and key not in cfg["channels"]:
62 cfg["channels"][key] = str(tools.config.channels_defaults[key])
63
64 if key not in tools.config.channels_config_keys and key in cfg["channels"]:
65 logging.debug("Ignored unconfigurable and possibly outdated"
66 " default value from config: {}".format(cfg['channels'][key]))
67 del cfg["channels"][key]
68
69 return cfg