1
Fork 0

Updated install process with folder creation.

This commit is contained in:
Edgar P. Burkhart 2022-10-30 15:29:41 +01:00
parent 811943868c
commit feb12c4ebc
Signed by: edpibu
GPG Key ID: 9833D3C5A25BD227
2 changed files with 20 additions and 8 deletions

View File

@ -2,8 +2,4 @@ import pathlib
def get_io(conf):
_in = pathlib.Path(conf.get("in")).expanduser()
_out = pathlib.Path(conf.get("out")).expanduser()
if _out.is_dir():
_out = _out.joinpath(_in.name)
return _in, _out
return pathlib.Path(conf.get("in")).expanduser(), pathlib.Path(conf.get("out")).expanduser()

View File

@ -37,11 +37,27 @@ for _name, _conf in config.items():
if not _in.is_file():
log.error(f"{_name} configuration <{_in}> could not be found.")
sys.exit(1)
if _out.exists():
if _out.is_file():
_yn = input(f"<{_out}> already exists; replace [Yn] ?").strip().lower()
if _yn != "y" and _yn != "":
log.info(f"Skipping {_name} configuration.")
continue
else:
log.info(f"Installing {_name} configuration.")
else:
log.error(f"<{_out}> already exists and is not a file.")
sys.exit(1)
if not _out.parent.exists():
_out.parent.mkdir(parents=True)
elif not _out.parent.is_dir():
log.error(f"{_name} configuration could not be installed as <{_out.parent}> is not a directory.")
sys.exit(1)
try:
shutil.copyfile(_in, _out)
except FileNotFoundError:
log.error(f"{_name} could not be configured: destination <{_out}> could not be found.")
sys.exit(1)
except OSError:
log.error(f"{_name} could not be configured: destination <{_out}> is not writable.")
sys.exit(1)