1
0
forked from IPKM/nmreval

check also for individual files in config directory; closes #76

This commit is contained in:
Dominik Demuth 2023-06-04 19:39:12 +02:00
parent 26fea8f69f
commit 90bd33a680

View File

@ -10,23 +10,25 @@ __all__ = ['config_paths', 'check_for_config', 'read_configuration', 'write_conf
def check_for_config(make=True): def check_for_config(make=True):
try: try:
config_paths() conf_path = config_paths()
except FileNotFoundError as e: except FileNotFoundError as e:
if make: if make:
conf_path = pathlib.Path('~/.auswerten').expanduser() conf_path = pathlib.Path('~/.auswerten').expanduser()
conf_path.mkdir(parents=True) 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: else:
raise e 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: def config_paths() -> pathlib.Path:
searchpaths = ['~/.config/nmreval', '~/.auswerten', '/usr/share/nmreval'] searchpaths = ['~/.config/nmreval', '~/.auswerten', '/usr/share/nmreval']