diff --git a/install.py b/install.py index 1cac315..d1256a5 100755 --- a/install.py +++ b/install.py @@ -27,6 +27,23 @@ class Installer: self.force = force self.update = update + def evaluate_condition(self, condition: str) -> bool: + """Run a bash command. On success return True, else return False.""" + + conditions = { + "force": self.force, + "no force": not self.force, + "update": self.update, + "no update": not self.update, + } + + if condition in conditions.keys(): + return conditions[condition] + + command = subprocess.run(condition, check=False, shell=True) + + return command.returncode == 0 + def pretty_path(self, path: Path) -> str: """Put the ~/ back in the path.""" @@ -92,7 +109,8 @@ class Installer: def do_run(self, command: str, condition: str = 'true') -> None: """Run a command.""" - if not evaluate_condition(condition): + if not self.evaluate_condition(condition): + ui.info_2("Skipping", "`{}`".format(command)) return ui.info_2("Running", "`{}`".format(command)) @@ -136,22 +154,6 @@ class Installer: src_full.symlink(p_dest) - def do_run_update(self, command: str) -> None: - """Run a command only if self.update is True.""" - - if self.update: - self.do_run(command) - else: - ui.info_2("Skipping", "`{}`".format(command)) - - def do_run_no_update(self, command: str) -> None: - """Run a command only if self.update is False.""" - - if not self.update: - self.do_run(command) - else: - ui.info_2("Skipping", "`{}`".format(command)) - def do_append(self, dest: str, content: str) -> None: """Append to a file.""" @@ -210,11 +212,6 @@ class Installer: ui.info() -def evaluate_condition(command: str) -> bool: - """Run a bash command. On success return True, else return False.""" - - return subprocess.run(command, check=False, shell=True).returncode == 0 - def main() -> None: """Parse args and instantiate the Installer."""