From e8c0830f7de26c814b78cc659ad111c055e526f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Sun, 1 May 2022 21:02:44 +0200 Subject: [PATCH] correct location for config file. create default config if not existent --- scripts/parse_config.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/scripts/parse_config.py b/scripts/parse_config.py index 4181451..9a6b9c1 100644 --- a/scripts/parse_config.py +++ b/scripts/parse_config.py @@ -12,8 +12,20 @@ def get_config_file(): if 'XDG_CONFIG_HOME' in os.environ.keys(): xdg_config_home = Path(os.environ['XDG_CONFIG_HOME']).resolve() else: - xdg_config_home = Path('~/.config').resolve() - return xdg_config_home / 'university-setup' / 'config.cfg' + xdg_config_home = Path('~/.config').expanduser().resolve() + config_file = xdg_config_home / 'university-setup' / 'config.cfg' + if not config_file.exists(): + config_file.parent.mkdir(exist_ok=True, parents=True) + config_file.write_text( + '# Automatically generated default config file for university-setup\n' + '# Edit this as you wish\n' + '\n' + '[Subprocess]\n' + 'terminal = i3-sensible-terminal' + ) + print(f'Initialized default config file at {str(config_file)}.') + print(config_file) + return config_file def get_config(section_name: str = 'Subprocess') -> Dict: