Updated with any configuration
This commit is contained in:
parent
17492dfac9
commit
811943868c
2 changed files with 17 additions and 12 deletions
|
@ -1,5 +1,6 @@
|
||||||
import pathlib
|
import pathlib
|
||||||
|
|
||||||
|
|
||||||
def get_io(conf):
|
def get_io(conf):
|
||||||
_in = pathlib.Path(conf.get("in")).expanduser()
|
_in = pathlib.Path(conf.get("in")).expanduser()
|
||||||
_out = pathlib.Path(conf.get("out")).expanduser()
|
_out = pathlib.Path(conf.get("out")).expanduser()
|
||||||
|
|
|
@ -6,11 +6,10 @@ import shutil
|
||||||
import sys
|
import sys
|
||||||
import tomllib
|
import tomllib
|
||||||
|
|
||||||
|
|
||||||
from . import get_io
|
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")
|
log = logging.getLogger("config")
|
||||||
|
|
||||||
_argp = argparse.ArgumentParser(
|
_argp = argparse.ArgumentParser(
|
||||||
|
@ -24,7 +23,7 @@ args = _argp.parse_args()
|
||||||
|
|
||||||
log.info("Config installation starting")
|
log.info("Config installation starting")
|
||||||
|
|
||||||
log.info(f"Loading configuration file <{args.config}>")
|
log.info(f"Loading configuration file <{args.config}>.")
|
||||||
try:
|
try:
|
||||||
with open(args.config, "rb") as _config_file:
|
with open(args.config, "rb") as _config_file:
|
||||||
config = tomllib.load(_config_file)
|
config = tomllib.load(_config_file)
|
||||||
|
@ -32,12 +31,17 @@ except FileNotFoundError:
|
||||||
log.error(f"Configuration file <{args.config}> does not exist.")
|
log.error(f"Configuration file <{args.config}> does not exist.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if (_ps := config.get("PowerShell", None)):
|
for _name, _conf in config.items():
|
||||||
_in, _out = get_io(_ps)
|
_in, _out = get_io(_conf)
|
||||||
log.info(f"Copying PowerShell configuration from <{_in}> to <{_out}>")
|
log.info(f"Installing {_name} configuration from <{_in}> to <{_out}>.")
|
||||||
shutil.copyfile(_in, _out)
|
if not _in.is_file():
|
||||||
|
log.error(f"{_name} configuration <{_in}> could not be found.")
|
||||||
if (_git := config.get("Git", None)):
|
sys.exit(1)
|
||||||
_in, _out = get_io(_git)
|
try:
|
||||||
log.info(f"Copying Git configuration from <{_in}> to <{_out}>")
|
shutil.copyfile(_in, _out)
|
||||||
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)
|
||||||
|
|
Loading…
Reference in a new issue