diff options
| author | LMBishop <13875753+LMBishop@users.noreply.github.com> | 2022-11-20 22:59:20 +0000 |
|---|---|---|
| committer | LMBishop <13875753+LMBishop@users.noreply.github.com> | 2022-11-20 22:59:20 +0000 |
| commit | f80bd6727a727414d6736157bbac63705b92674c (patch) | |
| tree | 25a1d2e5c3ba9053535d311d07d4edece8d5f596 /util | |
| parent | e4367180c67085611b995e1539f0995be05d0308 (diff) | |
Add overwrite files mode
Diffstat (limited to 'util')
| -rw-r--r-- | util/runners.py | 14 |
1 files changed, 10 insertions, 4 deletions
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 |
