Added winget install
This commit is contained in:
parent
22c05c3eba
commit
1f862145ea
2 changed files with 46 additions and 26 deletions
|
@ -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"
|
||||||
|
|
|
@ -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():
|
||||||
_in, _out = get_io(_conf)
|
match _name.lower():
|
||||||
log.info(f"Installing {_name} configuration from <{_in}> to <{_out}>.")
|
case "winget":
|
||||||
if not _in.is_file():
|
log.info("Installing packages using winget.")
|
||||||
log.error(f"{_name} configuration <{_in}> could not be found.")
|
for _package in _conf.get("packages"):
|
||||||
sys.exit(1)
|
_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.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)
|
||||||
|
|
Loading…
Reference in a new issue