Fixed some stuff with conditions in run
This commit is contained in:
parent
423cb4c1d8
commit
05e952eedb
1 changed files with 19 additions and 22 deletions
41
install.py
41
install.py
|
@ -27,6 +27,23 @@ class Installer:
|
||||||
self.force = force
|
self.force = force
|
||||||
self.update = update
|
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:
|
def pretty_path(self, path: Path) -> str:
|
||||||
"""Put the ~/ back in the path."""
|
"""Put the ~/ back in the path."""
|
||||||
|
|
||||||
|
@ -92,7 +109,8 @@ class Installer:
|
||||||
def do_run(self, command: str, condition: str = 'true') -> None:
|
def do_run(self, command: str, condition: str = 'true') -> None:
|
||||||
"""Run a command."""
|
"""Run a command."""
|
||||||
|
|
||||||
if not evaluate_condition(condition):
|
if not self.evaluate_condition(condition):
|
||||||
|
ui.info_2("Skipping", "`{}`".format(command))
|
||||||
return
|
return
|
||||||
|
|
||||||
ui.info_2("Running", "`{}`".format(command))
|
ui.info_2("Running", "`{}`".format(command))
|
||||||
|
@ -136,22 +154,6 @@ class Installer:
|
||||||
|
|
||||||
src_full.symlink(p_dest)
|
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:
|
def do_append(self, dest: str, content: str) -> None:
|
||||||
"""Append to a file."""
|
"""Append to a file."""
|
||||||
|
|
||||||
|
@ -210,11 +212,6 @@ class Installer:
|
||||||
ui.info()
|
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:
|
def main() -> None:
|
||||||
"""Parse args and instantiate the Installer."""
|
"""Parse args and instantiate the Installer."""
|
||||||
|
|
Loading…
Add table
Reference in a new issue