dotfiles/src/packages.py

41 lines
1.1 KiB
Python
Raw Normal View History

import typing as t
2020-10-22 16:31:20 +00:00
import yaml
from src.util.package import Package, PackageAlreadyInstalled, InvalidPackage
2021-01-14 13:55:21 +00:00
from src.util import install
2020-10-22 18:06:48 +00:00
from src.util.user import Print, Input
2020-10-22 16:31:20 +00:00
def obtain_packages() -> t.List[Package]:
with open("packages.yaml") as f:
yaml_file = yaml.safe_load(f)
pacman_packages = yaml_file["pacman"]
aur_packages = yaml_file["aur"]
git_packages = yaml_file["git"]
packages = []
packages += Package.safe_load(pacman_packages)
packages += Package.safe_load(aur_packages, aur=True)
packages += Package.safe_load(git_packages, git=True)
return packages
def install_packages() -> None:
packages = obtain_packages()
2020-10-22 18:06:48 +00:00
if Input.yes_no("Do you wish to perform system upgrade first? (Recommended)"):
2021-01-14 13:55:21 +00:00
install.upgrade_pacman()
for package in packages:
try:
Print.action(f"Installing {package}")
package.install()
except PackageAlreadyInstalled:
Print.cancel(f"Package {package} is already installed.")
except InvalidPackage as e:
Print.warning(e)
if __name__ == "__main__":
install_packages()