From 201b9944a2b2f74e1fd70f2fae3e64cb2209cf01 Mon Sep 17 00:00:00 2001 From: "flyingscorpio@arch-desktop" Date: Thu, 23 Jul 2020 11:17:13 +0200 Subject: [PATCH] Add hide command option --- install.py | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/install.py b/install.py index 2e9bd7b..398d330 100755 --- a/install.py +++ b/install.py @@ -19,7 +19,11 @@ class Installer: """Regroups all the installation methods listed in the yaml conf file.""" def __init__( - self, force: bool = False, first_install: bool = False, update: bool = False + self, + force: bool = False, + first_install: bool = False, + update: bool = False, + hide_commands: bool = False, ): yaml = YAML(typ="safe") self.conf = yaml.load(Path("configs.yml").text()) @@ -29,6 +33,7 @@ class Installer: self.force = force self.first_install = first_install self.update = update + self.hide_commands = hide_commands def evaluate_condition(self, condition: str) -> bool: """Run a bash command. On success return True, else return False.""" @@ -146,6 +151,12 @@ class Installer: failed_installs = [] + this_stdout: Optional[int] = None + this_stderr: Optional[int] = None + if self.hide_commands: + this_stdout = subprocess.DEVNULL + this_stderr = subprocess.DEVNULL + ui.info_2("Installing packages...") for i, package in enumerate(packages): if self.operating_system == "arch based": @@ -158,8 +169,8 @@ class Installer: command, check=False, shell=True, - stdout=subprocess.DEVNULL, - stderr=subprocess.DEVNULL, + stdout=this_stdout, + stderr=this_stderr, ) if install.returncode != 0: @@ -397,6 +408,9 @@ def main() -> None: parser.add_argument( "-u", "--update", action="store_true", help="Update git repos", ) + parser.add_argument( + "-H", "--hide_commands", action="store_true", help="Hide command outputs", + ) args = parser.parse_args() @@ -407,8 +421,14 @@ def main() -> None: generate = args.generate list_programs = args.list_programs update = args.update + hide_commands = args.hide_commands - installer = Installer(force=force, first_install=first_install, update=update) + installer = Installer( + force=force, + first_install=first_install, + update=update, + hide_commands=hide_commands, + ) if generate: installer.generate_process_list()