Simplify do_install greatly

This commit is contained in:
flyingscorpio@pinebookpro 2021-07-07 10:53:13 +02:00
parent fb43a2cb56
commit 53c9b156be

View file

@ -63,11 +63,10 @@ class Installer:
this_stderr: Optional[int] = subprocess.DEVNULL if self.hide_commands else None this_stderr: Optional[int] = subprocess.DEVNULL if self.hide_commands else None
if operating_system in ("arch", "manjaro"): if operating_system in ("arch", "manjaro"):
operating_system = "arch"
# On Arch-based systems, will update while installing packages # On Arch-based systems, will update while installing packages
pass
elif operating_system in ("debian", "ubuntu"): elif operating_system in ("debian", "ubuntu"):
operating_system = "debian"
subprocess.run( subprocess.run(
"sudo apt update", "sudo apt update",
check=True, check=True,
@ -204,14 +203,13 @@ class Installer:
except KeyError: except KeyError:
ui.warning("No packages for {}".format(self.operating_system)) ui.warning("No packages for {}".format(self.operating_system))
failed_installs = []
# defaults for subprocess.run() # defaults for subprocess.run()
this_stdout: Optional[int] = subprocess.DEVNULL if self.hide_commands else None this_stdout: Optional[int] = subprocess.DEVNULL if self.hide_commands else None
this_stderr: Optional[int] = subprocess.DEVNULL if self.hide_commands else None this_stderr: Optional[int] = subprocess.DEVNULL if self.hide_commands else None
ui.info_2("Installing packages...") ui.info_2("Installing packages...")
# On Arch-based OS, update the system first
if self.operating_system == "arch": if self.operating_system == "arch":
subprocess.run( subprocess.run(
"sudo pacman -Syu", "sudo pacman -Syu",
@ -221,37 +219,21 @@ class Installer:
stderr=this_stderr, stderr=this_stderr,
) )
for i, package in enumerate(packages): if self.operating_system == "arch":
if self.operating_system == "arch": command = "sudo pacman -S --needed --noconfirm {}".format(
command = "sudo pacman -S --needed --noconfirm {}".format(package) " ".join(packages)
elif self.operating_system == "debian":
command = "sudo apt install -y {}".format(package)
ui.info_count(i, len(packages), package, end="... ")
install = subprocess.run(
command,
check=False,
shell=True,
stdout=this_stdout,
stderr=this_stderr,
) )
elif self.operating_system == "debian":
command = "sudo apt install -y {}".format(" ".join(packages))
if install.returncode != 0: assert command
ui.info(ui.cross) subprocess.run(
failed_installs.append(package) command,
else: check=False,
ui.info(ui.check) shell=True,
stdout=this_stdout,
if len(failed_installs) > 0: stderr=this_stderr,
ui.warning("These packages failed to install:") )
for failed in failed_installs:
ui.info(" ", failed)
ui.warning(
f"Are the packages really meant for {self.operating_system} systems?"
)
def do_include(self, yml_file: str) -> None: def do_include(self, yml_file: str) -> None:
"""Include an additional config file.""" """Include an additional config file."""