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] [PowerShell]
in="src/PowerShell/profile.ps1" in="src/PowerShell/profile.ps1"
out="~/Documents/WindowsPowerShell/profile.ps1" out="~/Documents/WindowsPowerShell/profile.ps1"

View file

@ -3,6 +3,7 @@ import logging
import logging.config import logging.config
import pathlib import pathlib
import shutil import shutil
import subprocess
import sys import sys
import tomllib import tomllib
@ -32,32 +33,45 @@ except FileNotFoundError:
sys.exit(1) sys.exit(1)
for _name, _conf in config.items(): for _name, _conf in config.items():
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) _in, _out = get_io(_conf)
log.info(f"Installing {_name} configuration from <{_in}> to <{_out}>.") log.info(f"Installing {_name} configuration from <{_in}> to <{_out}>.")
if not _in.is_file(): if not _in.is_file():
log.error(f"{_name} configuration <{_in}> could not be found.") log.error(f"> {_name} configuration <{_in}> could not be found.")
sys.exit(1) sys.exit(1)
if _out.exists(): if _out.exists():
if _out.is_file(): if _out.is_file():
_yn = input(f"<{_out}> already exists; replace [Yn] ? ").strip().lower() _yn = input(f"<{_out}> already exists; replace [Yn] ? ").strip().lower()
if _yn != "y" and _yn != "": if _yn != "y" and _yn != "":
log.info(f"Skipping {_name} configuration.") log.info(f"> Skipping {_name} configuration.")
continue continue
else: else:
log.info(f"Installing {_name} configuration.") log.info(f"> Installing {_name} configuration.")
else: else:
log.error(f"<{_out}> already exists and is not a file.") log.error(f"> <{_out}> already exists and is not a file.")
sys.exit(1) sys.exit(1)
if not _out.parent.exists(): if not _out.parent.exists():
_out.parent.mkdir(parents=True) _out.parent.mkdir(parents=True)
elif not _out.parent.is_dir(): elif not _out.parent.is_dir():
log.error(f"{_name} configuration could not be installed as <{_out.parent}> is not a directory.") log.error(f"> {_name} configuration could not be installed as <{_out.parent}> is not a directory.")
sys.exit(1) sys.exit(1)
try: try:
shutil.copyfile(_in, _out) shutil.copyfile(_in, _out)
except OSError: except OSError:
log.error(f"{_name} could not be configured: destination <{_out}> is not writable.") log.error(f"> {_name} could not be configured: destination <{_out}> is not writable.")
sys.exit(1) sys.exit(1)