|
3 | 3 | import logging |
4 | 4 | import os |
5 | 5 | import shutil |
| 6 | +import sys |
6 | 7 | import time |
7 | 8 | from datetime import datetime |
8 | 9 | from pathlib import Path |
@@ -131,9 +132,12 @@ def _run( |
131 | 132 | return |
132 | 133 |
|
133 | 134 | # delete and create results directory |
134 | | - if os.path.exists(expedition_dir.joinpath(RESULTS)): |
135 | | - shutil.rmtree(expedition_dir.joinpath(RESULTS)) |
136 | | - os.makedirs(expedition_dir.joinpath(RESULTS)) |
| 135 | + results_dir = expedition_dir.joinpath(RESULTS) |
| 136 | + _warn_overwrite(results_dir) |
| 137 | + |
| 138 | + if os.path.exists(results_dir): |
| 139 | + shutil.rmtree(results_dir) |
| 140 | + os.makedirs(results_dir) |
137 | 141 |
|
138 | 142 | print("\n----- EXPEDITION SUMMARY ------") |
139 | 143 |
|
@@ -284,6 +288,21 @@ def _unique_id(expedition: Expedition, cache_dir: Path) -> str: |
284 | 288 | return new_id |
285 | 289 |
|
286 | 290 |
|
| 291 | +def _warn_overwrite(results_dir: Path) -> None: |
| 292 | + if os.path.exists(results_dir): |
| 293 | + print( |
| 294 | + f"\nWARNING: The '{results_dir}' directory already exists and will be overwritten. If you want to keep the previous results, please move or rename the '{results_dir}' directory before re-running the expedition.\n" |
| 295 | + ) |
| 296 | + decision = input( |
| 297 | + "Do you want to continue and overwrite the existing results? (y/n): " |
| 298 | + ) |
| 299 | + if decision.lower() != "y": |
| 300 | + print("Expedition run cancelled by user.") |
| 301 | + sys.exit(0) |
| 302 | + if decision.lower() == "y": |
| 303 | + print("Continuing with expedition run and overwriting existing results...") |
| 304 | + |
| 305 | + |
287 | 306 | def _load_checkpoint(expedition_dir: Path) -> Checkpoint | None: |
288 | 307 | file_path = expedition_dir.joinpath(CHECKPOINT) |
289 | 308 | try: |
|
0 commit comments