Add first draft for config parsing
Signed-off-by: InsanePrawn <insane.prawny@gmail.com>
This commit is contained in:
parent
2de5d33f19
commit
07c61f9a33
1 changed files with 44 additions and 0 deletions
44
config.py
Normal file
44
config.py
Normal file
|
@ -0,0 +1,44 @@
|
|||
import appdirs
|
||||
import os
|
||||
import toml
|
||||
|
||||
CONFIG_DEFAULT_PATH = os.path.join(appdirs.user_config_dir('kupfer'), 'kupferbootstrap.toml')
|
||||
|
||||
PROFILE_DEFAULTS = {
|
||||
'device': '',
|
||||
'flavour': '',
|
||||
'pkgs_include': [],
|
||||
'pkgs_exclude': [],
|
||||
'hostname': 'kupfer',
|
||||
'username': 'kupfer'
|
||||
}
|
||||
|
||||
CONFIG_DEFAULTS = {
|
||||
'build': {
|
||||
'crosscompile': True,
|
||||
'threads': 0,
|
||||
},
|
||||
'paths': {
|
||||
'chroots': os.path.join(appdirs.user_cache_dir('kupfer'), 'chroots'),
|
||||
'pacman_cache': os.path.join(appdirs.user_cache_dir('kupfer'), 'pacman'),
|
||||
'jumpdrive_cache': os.path.join(appdirs.user_cache_dir('kupfer'), 'jumpdrive')
|
||||
},
|
||||
'profiles': {
|
||||
'default': PROFILE_DEFAULTS.copy()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def load_config(config_file=None):
|
||||
_conf_file = config_file if config_file != None else DEFAULT_CONFIG_PATH
|
||||
loaded_conf = toml.load(_conf_file)
|
||||
# TODO: validate keys in loaded_conf, selectively merge known ones with CONFIG_DEFAULTS.
|
||||
# Recurse into dict vales for one level except for profiles.* (do check for profiles.default tho!)
|
||||
pass
|
||||
|
||||
|
||||
# temporary demo
|
||||
if __name__ == '__main__':
|
||||
conf = CONFIG_DEFAULTS.copy()
|
||||
conf['profiles']['pinephone'] = {'hostname': 'slowphone', 'pkgs_include': ['zsh','tmux','mpv','firefox']}
|
||||
print(toml.dumps(conf))
|
Loading…
Add table
Add a link
Reference in a new issue