Run black

This commit is contained in:
flyingscorpio@arch-desktop 2020-05-30 11:51:58 +02:00
parent b670f2bdd6
commit 81fbb879ce

View file

@ -19,7 +19,7 @@ class Installer:
"""Regroups all the installation methods listed in the yaml conf file.""" """Regroups all the installation methods listed in the yaml conf file."""
def __init__(self, force: bool = False, update: bool = False): def __init__(self, force: bool = False, update: bool = False):
yaml = YAML(typ='safe') yaml = YAML(typ="safe")
self.conf = yaml.load(Path("configs.yml").text()) self.conf = yaml.load(Path("configs.yml").text())
self.base_dir = Path.getcwd() self.base_dir = Path.getcwd()
self.home = Path("~").expanduser() self.home = Path("~").expanduser()
@ -125,14 +125,10 @@ class Installer:
try: try:
# dict only contains os-specific packages # dict only contains os-specific packages
if "both" not in os_specific_packages.keys(): if "both" not in os_specific_packages.keys():
packages = tuple( packages = tuple(os_specific_packages[self.operating_system])
os_specific_packages[self.operating_system]
)
# some packages for other operating systems are in the dict # some packages for other operating systems are in the dict
elif self.operating_system not in os_specific_packages.keys(): elif self.operating_system not in os_specific_packages.keys():
packages = tuple( packages = tuple(os_specific_packages["both"])
os_specific_packages["both"]
)
# dict contains specific and non-specific packages # dict contains specific and non-specific packages
else: else:
packages = tuple( packages = tuple(
@ -148,15 +144,18 @@ class Installer:
ui.info_2("Installing packages...") ui.info_2("Installing packages...")
for i, package in enumerate(packages): for i, package in enumerate(packages):
if self.operating_system == "arch based": if self.operating_system == "arch based":
command = "sudo pacman -S --needed --noconfirm {}"\ command = "sudo pacman -S --needed --noconfirm {}".format(package)
.format(package)
elif self.operating_system == "debian based": elif self.operating_system == "debian based":
command = "sudo apt install -y {}".format(package) command = "sudo apt install -y {}".format(package)
ui.info_count(i, len(packages), package, end="... ") ui.info_count(i, len(packages), package, end="... ")
install = subprocess.run(command, check=False, shell=True, install = subprocess.run(
stdout=subprocess.DEVNULL, command,
stderr=subprocess.DEVNULL) check=False,
shell=True,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
if install.returncode != 0: if install.returncode != 0:
ui.info(ui.cross) ui.info(ui.cross)
@ -170,8 +169,12 @@ class Installer:
for failed in failed_installs: for failed in failed_installs:
ui.info(" ", failed) ui.info(" ", failed)
ui.info(ui.yellow, "Are the packages really meant for {} systems?" ui.info(
.format(self.operating_system)) ui.yellow,
"Are the packages really meant for {} systems?".format(
self.operating_system
),
)
def do_run(self, command: str, condition: str = "true") -> None: def do_run(self, command: str, condition: str = "true") -> None:
"""Run a command.""" """Run a command."""
@ -264,8 +267,9 @@ class Installer:
""" """
if not programs: if not programs:
ui.info("No programs were specified.", ui.info(
"Fetching from the configuration file.") "No programs were specified.", "Fetching from the configuration file."
)
programs = list(self.conf.keys()) programs = list(self.conf.keys())
for program in programs: for program in programs:
if ui.ask_yes_no("Do you wish to install {}?".format(program)): if ui.ask_yes_no("Do you wish to install {}?".format(program)):
@ -342,8 +346,7 @@ def read_programs_from_process_list() -> List[str]:
content = process_file.readlines() content = process_file.readlines()
programs = [ programs = [
line.strip() for line in content line.strip() for line in content if not line.startswith("#") and len(line) > 0
if not line.startswith("#") and len(line) > 0
] ]
for program in programs: for program in programs:
@ -357,34 +360,31 @@ def main() -> None:
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument( parser.add_argument(
"programs", "programs", nargs="*", help="Programs to process, can be none",
nargs="*",
help="Programs to process, can be none",
) )
parser.add_argument( parser.add_argument(
"-f", "--from_file", "-f",
"--from_file",
action="store_true", action="store_true",
help="Use 'process_list.txt' as programs to process", help="Use 'process_list.txt' as programs to process",
) )
parser.add_argument( parser.add_argument(
"-F", "--force", "-F", "--force", action="store_true", help="Overwrite existing files",
action="store_true",
help="Overwrite existing files",
) )
parser.add_argument( parser.add_argument(
"-g", "--generate", "-g",
"--generate",
action="store_true", action="store_true",
help="Generate a file containing all the programs from the config file" help="Generate a file containing all the programs from the config file",
) )
parser.add_argument( parser.add_argument(
"-l", "--list_programs", "-l",
"--list_programs",
action="store_true", action="store_true",
help="List all programs from the configuration file", help="List all programs from the configuration file",
) )
parser.add_argument( parser.add_argument(
"-u", "--update", "-u", "--update", action="store_true", help="Update git repos",
action="store_true",
help="Update git repos",
) )
args = parser.parse_args() args = parser.parse_args()
@ -409,8 +409,9 @@ def main() -> None:
return return
if from_file: if from_file:
assert not programs, \ assert (
"Can't use 'process_list.txt' if you also specify programs!" not programs
), "Can't use 'process_list.txt' if you also specify programs!"
programs = read_programs_from_process_list() programs = read_programs_from_process_list()