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