]> glassweightruler.freedombox.rocks Git - waydroid.git/blob - tools/config/load.py
user_manager: Fix app removal
[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 if "properties" not in cfg:
30 cfg["properties"] = {}
31 # no default values for property override
32
33 return cfg
34
35 def load_channels():
36 config_path = tools.config.channels_defaults["config_path"]
37 cfg = configparser.ConfigParser()
38 if os.path.isfile(config_path):
39 cfg.read(config_path)
40
41 if "channels" not in cfg:
42 cfg["channels"] = {}
43
44 for key in tools.config.channels_defaults:
45 if key in tools.config.channels_config_keys and key not in cfg["channels"]:
46 cfg["channels"][key] = str(tools.config.channels_defaults[key])
47
48 if key not in tools.config.channels_config_keys and key in cfg["channels"]:
49 logging.debug("Ignored unconfigurable and possibly outdated"
50 " default value from config: {}".format(cfg['channels'][key]))
51 del cfg["channels"][key]
52
53 return cfg