ummmar commited on
Commit
e3a9f69
·
verified ·
1 Parent(s): 2d12dd3

Update restore_workspace.py

Browse files
Files changed (1) hide show
  1. restore_workspace.py +20 -13
restore_workspace.py CHANGED
@@ -3,28 +3,35 @@ from huggingface_hub import snapshot_download
3
 
4
  TOKEN = os.getenv("MY_HF_TOKEN")
5
  DATASET = os.getenv("HF_DATASET_REPO")
6
- WORKSPACE = "/workspace/projects"
 
7
 
8
- os.makedirs(WORKSPACE, exist_ok=True)
 
9
 
10
  if not TOKEN or not DATASET:
11
  print("⏭️ Restore skipped: MY_HF_TOKEN or HF_DATASET_REPO not set.")
12
  exit(0)
13
 
14
  try:
15
- print("⬇️ Restoring workspace from HF Dataset...")
16
- # Pass token directly to snapshot_download
17
  snapshot_download(
18
  repo_id=DATASET, repo_type="dataset",
19
- local_dir="/tmp/ws_restore", token=TOKEN,
20
- ignore_patterns=[".git", "__pycache__"]
21
  )
22
- if os.path.exists(WORKSPACE):
23
- shutil.rmtree(WORKSPACE)
24
- shutil.copytree("/tmp/ws_restore", WORKSPACE)
25
- print("✅ Workspace restored.")
 
 
 
 
 
 
 
 
26
  except Exception as e:
27
- print(f"⏭️ Fresh start (Dataset empty or missing): {e}")
28
  finally:
29
- shutil.rmtree("/tmp/ws_restore", ignore_errors=True)
30
- os.makedirs(WORKSPACE, exist_ok=True)
 
3
 
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
+ os.makedirs(CONFIG_DIR, exist_ok=True)
10
+ os.makedirs(PROJECTS_DIR, exist_ok=True)
11
 
12
  if not TOKEN or not DATASET:
13
  print("⏭️ Restore skipped: MY_HF_TOKEN or HF_DATASET_REPO not set.")
14
  exit(0)
15
 
16
  try:
17
+ print("⬇️ Restoring config from HF Dataset...")
 
18
  snapshot_download(
19
  repo_id=DATASET, repo_type="dataset",
20
+ local_dir="/tmp/config_restore", token=TOKEN
 
21
  )
22
+ # Only restore config dir, NOT projects
23
+ if os.path.exists("/tmp/config_restore"):
24
+ for item in os.listdir("/tmp/config_restore"):
25
+ src = os.path.join("/tmp/config_restore", item)
26
+ dst = os.path.join(CONFIG_DIR, item)
27
+ if os.path.isdir(src):
28
+ if os.path.exists(dst):
29
+ shutil.rmtree(dst)
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 config start: {e}")
36
  finally:
37
+ shutil.rmtree("/tmp/config_restore", ignore_errors=True)