Make do_install possible from dict instead of just list
This commit is contained in:
parent
2a72401456
commit
426f602a99
1 changed files with 21 additions and 9 deletions
30
install.py
30
install.py
|
@ -105,30 +105,39 @@ class Installer:
|
||||||
if executable:
|
if executable:
|
||||||
p_dest.chmod(0o755)
|
p_dest.chmod(0o755)
|
||||||
|
|
||||||
def do_install(self, *packages) -> None:
|
def do_install(self, *packages, **os_specific_packages) -> None:
|
||||||
"""Install packages with OS-dependent package manager."""
|
"""Install packages with OS-specific package manager.
|
||||||
|
|
||||||
|
Packages can either be in a list for non OS-specific packages, or in a
|
||||||
|
dict for OS-specific packages.
|
||||||
|
"""
|
||||||
|
|
||||||
|
if not packages: # we got the dict, make a list out of it
|
||||||
|
try:
|
||||||
|
packages = os_specific_packages[self.operating_system].split()\
|
||||||
|
+ os_specific_packages["both"].split()
|
||||||
|
except KeyError:
|
||||||
|
ui.fatal("Operating System not understood.")
|
||||||
|
return
|
||||||
|
|
||||||
failed_installs = []
|
failed_installs = []
|
||||||
|
|
||||||
|
ui.info_2("Installing packages...")
|
||||||
for package in packages:
|
for package in packages:
|
||||||
ui.info_2("Installing", package, ui.ellipsis, end='')
|
|
||||||
if self.operating_system == "arch based":
|
if self.operating_system == "arch based":
|
||||||
command = "sudo pacman -S --needed {}".format(package)
|
command = "sudo pacman -S --needed {}".format(package)
|
||||||
elif self.operating_system == "debian based":
|
elif self.operating_system == "debian based":
|
||||||
command = "sudo apt install {}".format(package)
|
command = "sudo apt install {}".format(package)
|
||||||
else:
|
|
||||||
ui.fatal("Operating System not understood.")
|
|
||||||
return
|
|
||||||
|
|
||||||
install = subprocess.run(command, check=False, shell=True,
|
install = subprocess.run(command, check=False, shell=True,
|
||||||
stdout=subprocess.DEVNULL,
|
stdout=subprocess.DEVNULL,
|
||||||
stderr=subprocess.DEVNULL)
|
stderr=subprocess.DEVNULL)
|
||||||
|
|
||||||
if install.returncode != 0:
|
if install.returncode != 0:
|
||||||
ui.info(ui.cross)
|
ui.info(ui.cross, package)
|
||||||
failed_installs.append(package)
|
failed_installs.append(package)
|
||||||
else:
|
else:
|
||||||
ui.info(ui.check)
|
ui.info(ui.check, package)
|
||||||
|
|
||||||
if len(failed_installs) > 0:
|
if len(failed_installs) > 0:
|
||||||
ui.warning("These packages failed to install:")
|
ui.warning("These packages failed to install:")
|
||||||
|
@ -269,8 +278,11 @@ def define_os() -> str:
|
||||||
return "debian based"
|
return "debian based"
|
||||||
|
|
||||||
ui.warning("Operating system wasn't found")
|
ui.warning("Operating system wasn't found")
|
||||||
|
operating_system = input("What is it ? ")
|
||||||
|
if operating_system in ("arch", "debian"):
|
||||||
|
return operating_system + " based"
|
||||||
|
|
||||||
return input("What is it ? ")
|
return ui.fatal("I only support Arch and Debian based distros.")
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
|
|
Loading…
Add table
Reference in a new issue