From 90bd33a6808fa7d12a8aec3e39ec7d07837f787c Mon Sep 17 00:00:00 2001 From: Dominik Demuth Date: Sun, 4 Jun 2023 19:39:12 +0200 Subject: [PATCH] check also for individual files in config directory; closes #76 --- src/nmreval/configs.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/nmreval/configs.py b/src/nmreval/configs.py index abdf2a3..3527139 100644 --- a/src/nmreval/configs.py +++ b/src/nmreval/configs.py @@ -10,23 +10,25 @@ __all__ = ['config_paths', 'check_for_config', 'read_configuration', 'write_conf def check_for_config(make=True): try: - config_paths() + conf_path = config_paths() except FileNotFoundError as e: if make: conf_path = pathlib.Path('~/.auswerten').expanduser() conf_path.mkdir(parents=True) - cwd = pathlib.Path(__file__).parent - copyfile(cwd / 'models' / 'usermodels.py', conf_path / 'usermodels.py') - - with resource_path('resources', 'Default.agr') as fp: - copyfile(fp, conf_path / 'Default.agr') - - with resource_path('resources', 'logo.png') as fp: - copyfile(fp, conf_path / 'logo.png') else: raise e + for filename in ('Default.agr', 'logo.png'): + _file = conf_path / filename + if not _file.exists(): + with resource_path('resources', filename) as fp: + copyfile(fp, _file) + + if not (conf_path / 'usermodels.py').exists(): + cwd = pathlib.Path(__file__).parent + copyfile(cwd / 'models' / 'usermodels.py', conf_path / 'usermodels.py') + def config_paths() -> pathlib.Path: searchpaths = ['~/.config/nmreval', '~/.auswerten', '/usr/share/nmreval']