1
Fork 0

Updated with any configuration

This commit is contained in:
Edgar P. Burkhart 2022-10-27 11:03:04 +02:00
parent 17492dfac9
commit 811943868c
Signed by: edpibu
GPG Key ID: 9833D3C5A25BD227
2 changed files with 17 additions and 12 deletions

View File

@ -1,5 +1,6 @@
import pathlib
def get_io(conf):
_in = pathlib.Path(conf.get("in")).expanduser()
_out = pathlib.Path(conf.get("out")).expanduser()

View File

@ -6,11 +6,10 @@ import shutil
import sys
import tomllib
from . import get_io
logging.config.fileConfig(pathlib.Path(__file__).parent.joinpath("log.conf"))
logging.config.fileConfig(pathlib.Path(__file__).with_name("log.conf"))
log = logging.getLogger("config")
_argp = argparse.ArgumentParser(
@ -24,7 +23,7 @@ args = _argp.parse_args()
log.info("Config installation starting")
log.info(f"Loading configuration file <{args.config}>")
log.info(f"Loading configuration file <{args.config}>.")
try:
with open(args.config, "rb") as _config_file:
config = tomllib.load(_config_file)
@ -32,12 +31,17 @@ except FileNotFoundError:
log.error(f"Configuration file <{args.config}> does not exist.")
sys.exit(1)
if (_ps := config.get("PowerShell", None)):
_in, _out = get_io(_ps)
log.info(f"Copying PowerShell configuration from <{_in}> to <{_out}>")
shutil.copyfile(_in, _out)
if (_git := config.get("Git", None)):
_in, _out = get_io(_git)
log.info(f"Copying Git configuration from <{_in}> to <{_out}>")
shutil.copyfile(_in, _out)
for _name, _conf in config.items():
_in, _out = get_io(_conf)
log.info(f"Installing {_name} configuration from <{_in}> to <{_out}>.")
if not _in.is_file():
log.error(f"{_name} configuration <{_in}> could not be found.")
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)