From 37c6db12a3e5216b067cdef7929d44fa7818c3cb Mon Sep 17 00:00:00 2001 From: ItsDrike Date: Thu, 22 Oct 2020 19:02:23 +0200 Subject: [PATCH] Run install packages when the file started directly --- src/packages.py | 12 ++++++++---- src/util/log.py | 37 ------------------------------------- src/util/user.py | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 41 deletions(-) delete mode 100644 src/util/log.py create mode 100644 src/util/user.py diff --git a/src/packages.py b/src/packages.py index fe0dd15..1d462d5 100644 --- a/src/packages.py +++ b/src/packages.py @@ -3,7 +3,7 @@ import yaml from src.util.package import Package, PackageAlreadyInstalled, InvalidPackage from src.util.install import Install -from src.util import log +from src.util.user import Print def obtain_packages() -> t.List[Package]: @@ -30,9 +30,13 @@ def install_packages() -> None: Install.upgrade_pacman() for package in packages: try: - log.action(f"Installing {package}") + Print.action(f"Installing {package}") package.install() except PackageAlreadyInstalled: - log.cancel(f"Package {package} is already installed.") + Print.cancel(f"Package {package} is already installed.") except InvalidPackage as e: - log.warning(e) + Print.warning(e) + + +if __name__ == "__main__": + install_packages() diff --git a/src/util/log.py b/src/util/log.py deleted file mode 100644 index b563a13..0000000 --- a/src/util/log.py +++ /dev/null @@ -1,37 +0,0 @@ -import typing as t - -from src.util.color import Color - - -def question(question: str, options: t.Optional[list] = None) -> None: - """Print syntax for question with optional `options` to it""" - text = [f"{Color.GREEN} // {question}{Color.RESET}"] - if options: - for option in options: - text.append(f"{Color.GREEN} # {options}{Color.RESET}") - print("\n".join(text)) - - -def action(action: str) -> None: - """Print syntax for action""" - print(f"{Color.GOLD} >> {action}{Color.RESET}") - - -def err(text: str) -> None: - """Print syntax for error""" - print(f"{Color.RED} !! {text}{Color.RESET}") - - -def cancel(text: str) -> None: - """Print syntax for cancellation""" - print(f"{Color.GREY} >> {text}{Color.RESET}") - - -def comment(text: str) -> None: - """Print syntax for comments""" - print(f"{Color.GREY} // {text}{Color.RESET}") - - -def warning(text: str) -> None: - """Print syntax for warnings""" - print(f"{Color.YELLOW} ** {text}{Color.RESET}") diff --git a/src/util/user.py b/src/util/user.py new file mode 100644 index 0000000..5782b56 --- /dev/null +++ b/src/util/user.py @@ -0,0 +1,33 @@ +import typing as t + +from src.util.color import Color + + +class Print: + def question(question: str, options: t.Optional[list] = None) -> None: + """Print syntax for question with optional `options` to it""" + text = [f"{Color.GREEN} // {question}{Color.RESET}"] + if options: + for option in options: + text.append(f"{Color.GREEN} # {options}{Color.RESET}") + print("\n".join(text)) + + def action(action: str) -> None: + """Print syntax for action""" + print(f"{Color.GOLD} >> {action}{Color.RESET}") + + def err(text: str) -> None: + """Print syntax for error""" + print(f"{Color.RED} !! {text}{Color.RESET}") + + def cancel(text: str) -> None: + """Print syntax for cancellation""" + print(f"{Color.GREY} >> {text}{Color.RESET}") + + def comment(text: str) -> None: + """Print syntax for comments""" + print(f"{Color.GREY} // {text}{Color.RESET}") + + def warning(text: str) -> None: + """Print syntax for warnings""" + print(f"{Color.YELLOW} ** {text}{Color.RESET}")