Don't use irrelevant class for install

This commit is contained in:
ItsDrike 2021-01-14 14:55:21 +01:00
parent 28f9eb1545
commit edd79c3a49
No known key found for this signature in database
GPG key ID: 252D306F545351FC
3 changed files with 47 additions and 44 deletions

View file

@ -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}")

View file

@ -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}`")

View file

@ -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: