Add hide command option

This commit is contained in:
flyingscorpio@arch-desktop 2020-07-23 11:17:13 +02:00
parent 2d43389f9f
commit 201b9944a2

View file

@ -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()