diff options
| -rwxr-xr-x | deploy.py | 5 | ||||
| -rw-r--r-- | util/runners.py | 14 |
2 files changed, 15 insertions, 4 deletions
@@ -10,6 +10,7 @@ import yaml from termcolor import colored CWD = os.getcwd() +OVERWRITE_FILES = os.getenv("OVERWRITE_FILES") def get_sections_meeting_preconditions(yaml): @@ -47,6 +48,10 @@ print("Sections to run: " + ", ".join( )) print() +if OVERWRITE_FILES == "1": + print(colored("Warning: ", "red") + "you have requested overwrite mode!") + print() + if not query_yes_no("Proceed with install?", False): exit(1) diff --git a/util/runners.py b/util/runners.py index dcce820..dbfcf1f 100644 --- a/util/runners.py +++ b/util/runners.py @@ -4,6 +4,7 @@ from util.exceptions import StepFailedError from termcolor import colored HOME = os.getenv("HOME") +OVERWRITE_FILES = os.getenv("OVERWRITE_FILES") def run_step(step): @@ -24,12 +25,17 @@ def do_run(command): def do_link(source, destination): destination = re.sub(r"^~/", HOME + "/", destination) print(f"Linking {source} -> {destination}") + if os.path.exists(destination): + if OVERWRITE_FILES == "1": + os.remove(destination) + print(colored(" (File overwritten)", "yellow")) + else: + print(colored(" (File already exists)", "yellow")) + return + try: os.link(source, destination) except OSError as e: - if e.errno == 17: - print(colored(" (File already exists)", "yellow")) - else: - raise StepFailedError("Link raised exeption: " + str(e)) from e + raise StepFailedError("Link raised exeption: " + str(e)) from e except Exception as e: raise StepFailedError("Link raised exeption: " + str(e)) from e |
