mirror of
https://github.com/ItsDrike/dotfiles.git
synced 2024-12-26 13:14:35 +00:00
Don't use irrelevant class for install
This commit is contained in:
parent
28f9eb1545
commit
edd79c3a49
|
@ -2,7 +2,7 @@ import typing as t
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
from src.util.package import Package, PackageAlreadyInstalled, InvalidPackage
|
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
|
from src.util.user import Print, Input
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ def obtain_packages() -> t.List[Package]:
|
||||||
def install_packages() -> None:
|
def install_packages() -> None:
|
||||||
packages = obtain_packages()
|
packages = obtain_packages()
|
||||||
if Input.yes_no("Do you wish to perform system upgrade first? (Recommended)"):
|
if Input.yes_no("Do you wish to perform system upgrade first? (Recommended)"):
|
||||||
Install.upgrade_pacman()
|
install.upgrade_pacman()
|
||||||
for package in packages:
|
for package in packages:
|
||||||
try:
|
try:
|
||||||
Print.action(f"Installing {package}")
|
Print.action(f"Installing {package}")
|
||||||
|
|
|
@ -5,24 +5,27 @@ from src.util import command
|
||||||
from src.util.user import Print, Input
|
from src.util.user import Print, Input
|
||||||
|
|
||||||
|
|
||||||
class Install:
|
|
||||||
def is_installed(package: str) -> bool:
|
def is_installed(package: str) -> bool:
|
||||||
"""Check if the package is already installed in the system"""
|
"""Check if the package is already installed in the system"""
|
||||||
return_code = command.get_return_code(f"pacman -Qi {package}")
|
return_code = command.get_return_code(f"pacman -Qi {package}")
|
||||||
return return_code != 1
|
return return_code != 1
|
||||||
|
|
||||||
|
|
||||||
def upgrade_pacman() -> None:
|
def upgrade_pacman() -> None:
|
||||||
"""Run full sync, refresh the package database and upgrade."""
|
"""Run full sync, refresh the package database and upgrade."""
|
||||||
command.execute("sudo pacman -Syu")
|
command.execute("sudo pacman -Syu")
|
||||||
|
|
||||||
|
|
||||||
def pacman_install(package: str) -> None:
|
def pacman_install(package: str) -> None:
|
||||||
"""Install given `package`"""
|
"""Install given `package`"""
|
||||||
command.execute(f"sudo pacman -S {package}")
|
command.execute(f"sudo pacman -S {package}")
|
||||||
|
|
||||||
|
|
||||||
def yay_install(package: str) -> None:
|
def yay_install(package: str) -> None:
|
||||||
"""Install give package via `yay` (from AUR)"""
|
"""Install give package via `yay` (from AUR)"""
|
||||||
command.execute(f"yay -S {package}")
|
command.execute(f"yay -S {package}")
|
||||||
|
|
||||||
|
|
||||||
def git_install(url: str) -> None:
|
def git_install(url: str) -> None:
|
||||||
"""Clone a git repository with given `url`"""
|
"""Clone a git repository with given `url`"""
|
||||||
dir_name = url.split("/")[-1].replace(".git", "")
|
dir_name = url.split("/")[-1].replace(".git", "")
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import typing as t
|
import typing as t
|
||||||
|
|
||||||
from src.util.install import Install
|
from src.util import install
|
||||||
from src.util.user import Print
|
from src.util.user import Print
|
||||||
|
|
||||||
|
|
||||||
|
@ -32,17 +32,17 @@ class Package:
|
||||||
self.git_url = f"https://github.com/{self.name}"
|
self.git_url = f"https://github.com/{self.name}"
|
||||||
|
|
||||||
def install(self) -> None:
|
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")
|
raise PackageAlreadyInstalled(f"Package {self} is already installed")
|
||||||
|
|
||||||
if self.aur:
|
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")
|
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:
|
elif self.git:
|
||||||
Install.git_install(self.git_url)
|
install.git_install(self.git_url)
|
||||||
else:
|
else:
|
||||||
Install.pacman_install(self.name)
|
install.pacman_install(self.name)
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
if self.git:
|
if self.git:
|
||||||
|
|
Loading…
Reference in a new issue