Update restore_workspace.py
Browse files- restore_workspace.py +16 -19
restore_workspace.py
CHANGED
|
@@ -4,34 +4,31 @@ from huggingface_hub import snapshot_download
|
|
| 4 |
TOKEN = os.getenv("MY_HF_TOKEN")
|
| 5 |
DATASET = os.getenv("HF_DATASET_REPO")
|
| 6 |
CONFIG_DIR = "/workspace/config"
|
|
|
|
| 7 |
PROJECTS_DIR = "/workspace/projects"
|
| 8 |
|
| 9 |
-
|
| 10 |
-
os.makedirs(
|
| 11 |
|
| 12 |
if not TOKEN or not DATASET:
|
| 13 |
-
print("⏭️ Restore skipped
|
| 14 |
exit(0)
|
| 15 |
|
| 16 |
try:
|
| 17 |
-
print("⬇️ Restoring config
|
| 18 |
snapshot_download(
|
| 19 |
repo_id=DATASET, repo_type="dataset",
|
| 20 |
-
local_dir="/tmp/
|
| 21 |
)
|
| 22 |
-
#
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
shutil.copytree(src, dst)
|
| 31 |
-
else:
|
| 32 |
-
shutil.copy2(src, dst)
|
| 33 |
-
print("✅ Config restored.")
|
| 34 |
except Exception as e:
|
| 35 |
-
print(f"⏭️ Fresh
|
| 36 |
finally:
|
| 37 |
-
shutil.rmtree("/tmp/
|
|
|
|
| 4 |
TOKEN = os.getenv("MY_HF_TOKEN")
|
| 5 |
DATASET = os.getenv("HF_DATASET_REPO")
|
| 6 |
CONFIG_DIR = "/workspace/config"
|
| 7 |
+
DATA_DIR = "/workspace/data"
|
| 8 |
PROJECTS_DIR = "/workspace/projects"
|
| 9 |
|
| 10 |
+
for d in [CONFIG_DIR, DATA_DIR, PROJECTS_DIR]:
|
| 11 |
+
os.makedirs(d, exist_ok=True)
|
| 12 |
|
| 13 |
if not TOKEN or not DATASET:
|
| 14 |
+
print("⏭️ Restore skipped.")
|
| 15 |
exit(0)
|
| 16 |
|
| 17 |
try:
|
| 18 |
+
print("⬇️ Restoring config & sessions...")
|
| 19 |
snapshot_download(
|
| 20 |
repo_id=DATASET, repo_type="dataset",
|
| 21 |
+
local_dir="/tmp/ws_restore", token=TOKEN
|
| 22 |
)
|
| 23 |
+
# Restore config/ and sessions/ subdirs from dataset
|
| 24 |
+
for subdir, target in [("config", CONFIG_DIR), ("sessions", DATA_DIR)]:
|
| 25 |
+
src = os.path.join("/tmp/ws_restore", subdir)
|
| 26 |
+
if os.path.exists(src):
|
| 27 |
+
if os.path.exists(target):
|
| 28 |
+
shutil.rmtree(target)
|
| 29 |
+
shutil.copytree(src, target)
|
| 30 |
+
print(f"✅ {subdir} restored.")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
except Exception as e:
|
| 32 |
+
print(f"⏭️ Fresh start: {e}")
|
| 33 |
finally:
|
| 34 |
+
shutil.rmtree("/tmp/ws_restore", ignore_errors=True)
|