1
Fork 0

Added winget install

This commit is contained in:
Edgar P. Burkhart 2022-10-31 18:42:41 +01:00
parent 22c05c3eba
commit 1f862145ea
Signed by: edpibu
GPG Key ID: 9833D3C5A25BD227
2 changed files with 46 additions and 26 deletions

View File

@ -1,3 +1,9 @@
[Winget]
packages = [
"Git.Git",
"Neovim.Neovim",
]
[PowerShell]
in="src/PowerShell/profile.ps1"
out="~/Documents/WindowsPowerShell/profile.ps1"

View File

@ -3,6 +3,7 @@ import logging
import logging.config
import pathlib
import shutil
import subprocess
import sys
import tomllib
@ -32,32 +33,45 @@ except FileNotFoundError:
sys.exit(1)
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)
match _name.lower():
case "winget":
log.info("Installing packages using winget.")
for _package in _conf.get("packages"):
_test = subprocess.run(("winget", "list", "--id", _package))
if _test.returncode == 0:
_yn = input(f"<{_package}> is already installed; reinstall [Yn] ? ").strip().lower()
if _yn != "y" and _yn != "":
log.info(f"> Skipping <{_package}> install.")
continue
log.info(f"> Installing {_package} using winget.")
subprocess.run(("winget", "install", _package))
case _:
_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)
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 _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)
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 OSError:
log.error(f"{_name} could not be configured: destination <{_out}> is not writable.")
sys.exit(1)
try:
shutil.copyfile(_in, _out)
except OSError:
log.error(f"> {_name} could not be configured: destination <{_out}> is not writable.")
sys.exit(1)