From edd79c3a493c3a6ff383c418dff3efc59fb32159 Mon Sep 17 00:00:00 2001 From: ItsDrike Date: Thu, 14 Jan 2021 14:55:21 +0100 Subject: [PATCH] Don't use irrelevant class for install --- src/packages.py | 4 +-- src/util/install.py | 75 +++++++++++++++++++++++---------------------- src/util/package.py | 12 ++++---- 3 files changed, 47 insertions(+), 44 deletions(-) diff --git a/src/packages.py b/src/packages.py index 8261663..6513d90 100644 --- a/src/packages.py +++ b/src/packages.py @@ -2,7 +2,7 @@ import typing as t import yaml from src.util.package import Package, PackageAlreadyInstalled, InvalidPackage -from src.util.install import Install +from src.util import install from src.util.user import Print, Input @@ -25,7 +25,7 @@ def obtain_packages() -> t.List[Package]: def install_packages() -> None: packages = obtain_packages() if Input.yes_no("Do you wish to perform system upgrade first? (Recommended)"): - Install.upgrade_pacman() + install.upgrade_pacman() for package in packages: try: Print.action(f"Installing {package}") diff --git a/src/util/install.py b/src/util/install.py index 5ef7c9d..1975010 100644 --- a/src/util/install.py +++ b/src/util/install.py @@ -5,46 +5,49 @@ from src.util import command from src.util.user import Print, Input -class Install: - def is_installed(package: str) -> bool: - """Check if the package is already installed in the system""" - return_code = command.get_return_code(f"pacman -Qi {package}") - return return_code != 1 +def is_installed(package: str) -> bool: + """Check if the package is already installed in the system""" + return_code = command.get_return_code(f"pacman -Qi {package}") + return return_code != 1 - def upgrade_pacman() -> None: - """Run full sync, refresh the package database and upgrade.""" - command.execute("sudo pacman -Syu") - def pacman_install(package: str) -> None: - """Install given `package`""" - command.execute(f"sudo pacman -S {package}") +def upgrade_pacman() -> None: + """Run full sync, refresh the package database and upgrade.""" + command.execute("sudo pacman -Syu") - def yay_install(package: str) -> None: - """Install give package via `yay` (from AUR)""" - command.execute(f"yay -S {package}") - def git_install(url: str) -> None: - """Clone a git repository with given `url`""" - dir_name = url.split("/")[-1].replace(".git", "") - if os.path.exists(dir_name): - Print.cancel(f"Git repository {dir_name} already exists") +def pacman_install(package: str) -> None: + """Install given `package`""" + command.execute(f"sudo pacman -S {package}") - ret_code = command.get_return_code(f"git clone {url}") - if ret_code == 128: - Print.warning(f"Unable to install git repository {url}") - return - if not os.path.exists(f"{dir_name}/PKGBUILD"): - Print.comment(f"Git repository {dir_name} doesn't contain PKGBUILD, only downloaded.") - return +def yay_install(package: str) -> None: + """Install give package via `yay` (from AUR)""" + command.execute(f"yay -S {package}") - if Input.yes_no("Do you wish to run makepkg on the downloaded git repository?"): - cwd = os.getcwd() - os.chdir(dir_name) - command.execute("makepkg -si") - os.chdir(cwd) - shutil.rmtree(dir_name) - else: - os.makedirs("download") - command.execute(f"mv {dir_name} download/") - Print.action(f"Your git repository was cloned into `download/{dir_name}`") + +def git_install(url: str) -> None: + """Clone a git repository with given `url`""" + dir_name = url.split("/")[-1].replace(".git", "") + if os.path.exists(dir_name): + Print.cancel(f"Git repository {dir_name} already exists") + + ret_code = command.get_return_code(f"git clone {url}") + if ret_code == 128: + Print.warning(f"Unable to install git repository {url}") + return + + if not os.path.exists(f"{dir_name}/PKGBUILD"): + Print.comment(f"Git repository {dir_name} doesn't contain PKGBUILD, only downloaded.") + return + + if Input.yes_no("Do you wish to run makepkg on the downloaded git repository?"): + cwd = os.getcwd() + os.chdir(dir_name) + command.execute("makepkg -si") + os.chdir(cwd) + shutil.rmtree(dir_name) + else: + os.makedirs("download") + command.execute(f"mv {dir_name} download/") + Print.action(f"Your git repository was cloned into `download/{dir_name}`") diff --git a/src/util/package.py b/src/util/package.py index e4a3a6a..44db89f 100644 --- a/src/util/package.py +++ b/src/util/package.py @@ -1,6 +1,6 @@ import typing as t -from src.util.install import Install +from src.util import install from src.util.user import Print @@ -32,17 +32,17 @@ class Package: self.git_url = f"https://github.com/{self.name}" def install(self) -> None: - if not self.git and Install.is_installed(self.name): + if not self.git and install.is_installed(self.name): raise PackageAlreadyInstalled(f"Package {self} is already installed") if self.aur: - if not Install.is_installed("yay"): + if not install.is_installed("yay"): raise InvalidPackage(f"Package {self} can't be installed (missing `yay` - AUR installation software), alternatively, you can use git") - Install.yay_install(self.name) + install.yay_install(self.name) elif self.git: - Install.git_install(self.git_url) + install.git_install(self.git_url) else: - Install.pacman_install(self.name) + install.pacman_install(self.name) def __repr__(self) -> str: if self.git: