R1000 commited on
Commit
41bed09
·
verified ·
1 Parent(s): 48cb257

Update sync.py

Browse files
Files changed (1) hide show
  1. sync.py +0 -129
sync.py CHANGED
@@ -24,9 +24,6 @@ PATHS_TO_BACKUP = [
24
  BASE_DIR / "workspace",
25
  ]
26
 
27
- # # Path สำหรับ backup UI assets (ภายใน workspace)
28
- # UI_BACKUP_DIR = BASE_DIR / "workspace" / ".openclaw_ui_backup"
29
-
30
 
31
  def log(msg: str) -> None:
32
  print(msg, flush=True)
@@ -55,122 +52,6 @@ def safe_extract(tar: tarfile.TarFile, target_dir: Path) -> None:
55
  tar.extractall(path=target_dir)
56
 
57
 
58
- # def get_openclaw_ui_path() -> Path | None:
59
- # """หา path ของ openclaw UI assets"""
60
- # try:
61
- # result = subprocess.run(
62
- # ["npm", "root", "-g"],
63
- # capture_output=True,
64
- # text=True,
65
- # check=True
66
- # )
67
- # npm_global = Path(result.stdout.strip())
68
- # ui_path = npm_global / "openclaw" / "dist" / "control-ui"
69
-
70
- # if ui_path.exists() and ui_path.is_dir():
71
- # log(f"[UI] Found UI assets at npm global: {ui_path}")
72
- # return ui_path
73
- # except Exception as e:
74
- # log(f"[UI] Could not find npm global path: {e}")
75
-
76
- # possible_paths = [
77
- # Path("/usr/local/lib/node_modules/openclaw/dist/control-ui"),
78
- # Path("/usr/lib/node_modules/openclaw/dist/control-ui"),
79
- # Path("/opt/openclaw/dist/control-ui"),
80
- # ]
81
-
82
- # for path in possible_paths:
83
- # if path.exists() and path.is_dir():
84
- # log(f"[UI] Found UI assets at: {path}")
85
- # return path
86
-
87
- # log("[UI] Warning: OpenClaw UI assets not found")
88
- # return None
89
-
90
-
91
- # def backup_ui_assets() -> bool:
92
- # """คัดลอก UI assets ไปไว้ใน workspace เพื่อ backup"""
93
- # ui_path = get_openclaw_ui_path()
94
- # if not ui_path:
95
- # log("[BACKUP] No UI assets found to backup")
96
- # return False
97
-
98
- # try:
99
- # if UI_BACKUP_DIR.exists():
100
- # shutil.rmtree(UI_BACKUP_DIR)
101
-
102
- # UI_BACKUP_DIR.mkdir(parents=True, exist_ok=True)
103
-
104
- # copied_count = 0
105
- # for item in ui_path.iterdir():
106
- # dest = UI_BACKUP_DIR / item.name
107
- # if item.is_dir():
108
- # shutil.copytree(item, dest, dirs_exist_ok=True)
109
- # log(f"[BACKUP] Copied UI directory: {item.name}")
110
- # else:
111
- # shutil.copy2(item, dest)
112
- # log(f"[BACKUP] Copied UI file: {item.name}")
113
- # copied_count += 1
114
-
115
- # log(f"[BACKUP] Successfully backed up {copied_count} UI assets to {UI_BACKUP_DIR}")
116
- # return True
117
-
118
- # except Exception as e:
119
- # log_err(f"[BACKUP] Failed to backup UI assets: {e}")
120
- # return False
121
-
122
-
123
- # def restore_ui_assets() -> bool:
124
- # """กู้คืน UI assets จาก backup กลับไปที่ npm path"""
125
- # if not UI_BACKUP_DIR.exists():
126
- # log("[RESTORE] No UI backup found to restore")
127
- # return False
128
-
129
- # target_ui_path = get_openclaw_ui_path()
130
-
131
- # if not target_ui_path:
132
- # try:
133
- # result = subprocess.run(
134
- # ["npm", "root", "-g"],
135
- # capture_output=True,
136
- # text=True,
137
- # check=True
138
- # )
139
- # npm_global = Path(result.stdout.strip())
140
- # target_ui_path = npm_global / "openclaw" / "dist" / "control-ui"
141
- # target_ui_path.parent.mkdir(parents=True, exist_ok=True)
142
- # log(f"[RESTORE] Using default UI path: {target_ui_path}")
143
- # except Exception as e:
144
- # log_err(f"[RESTORE] Cannot determine target UI path: {e}")
145
- # return False
146
-
147
- # try:
148
- # if target_ui_path.exists():
149
- # backup_old = target_ui_path.parent / f"control-ui.backup.{os.getpid()}"
150
- # shutil.move(target_ui_path, backup_old)
151
- # log(f"[RESTORE] Backed up existing UI to: {backup_old}")
152
-
153
- # target_ui_path.mkdir(parents=True, exist_ok=True)
154
-
155
- # restored_count = 0
156
- # for item in UI_BACKUP_DIR.iterdir():
157
- # dest = target_ui_path / item.name
158
- # if item.is_dir():
159
- # shutil.copytree(item, dest, dirs_exist_ok=True)
160
- # log(f"[RESTORE] Restored UI directory: {item.name}")
161
- # else:
162
- # shutil.copy2(item, dest)
163
- # log(f"[RESTORE] Restored UI file: {item.name}")
164
- # restored_count += 1
165
-
166
- # log(f"[RESTORE] Successfully restored {restored_count} UI assets to {target_ui_path}")
167
- # return True
168
-
169
- # except Exception as e:
170
- # log_err(f"[RESTORE] Failed to restore UI assets: {e}")
171
- # return False
172
-
173
-
174
  def restore() -> bool:
175
  if not REPO_ID or not TOKEN:
176
  log("[RESTORE] Skip: HF_DATASET or HF_TOKEN not set")
@@ -191,10 +72,6 @@ def restore() -> bool:
191
  safe_extract(tar, BASE_DIR)
192
 
193
  log(f"[RESTORE] Success: restored from {FILENAME}")
194
-
195
- log("[RESTORE] Restoring UI assets...")
196
- restore_ui_assets()
197
-
198
  return True
199
 
200
  except EntryNotFoundError:
@@ -219,9 +96,6 @@ def backup() -> bool:
219
  log("[BACKUP] Skip: HF_DATASET or HF_TOKEN not set")
220
  return False
221
 
222
- log("[BACKUP] Step 1: Backing up UI assets to workspace...")
223
- backup_ui_assets()
224
-
225
  existing_paths = []
226
  for p in PATHS_TO_BACKUP:
227
  if p.exists():
@@ -230,9 +104,6 @@ def backup() -> bool:
230
  else:
231
  log(f"[BACKUP] Warning: {p} does not exist, skipping")
232
 
233
- if UI_BACKUP_DIR.exists():
234
- log(f"[BACKUP] UI backup included in workspace: {UI_BACKUP_DIR}")
235
-
236
  if not existing_paths:
237
  log("[BACKUP] Skip: no paths to backup")
238
  return False
 
24
  BASE_DIR / "workspace",
25
  ]
26
 
 
 
 
27
 
28
  def log(msg: str) -> None:
29
  print(msg, flush=True)
 
52
  tar.extractall(path=target_dir)
53
 
54
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  def restore() -> bool:
56
  if not REPO_ID or not TOKEN:
57
  log("[RESTORE] Skip: HF_DATASET or HF_TOKEN not set")
 
72
  safe_extract(tar, BASE_DIR)
73
 
74
  log(f"[RESTORE] Success: restored from {FILENAME}")
 
 
 
 
75
  return True
76
 
77
  except EntryNotFoundError:
 
96
  log("[BACKUP] Skip: HF_DATASET or HF_TOKEN not set")
97
  return False
98
 
 
 
 
99
  existing_paths = []
100
  for p in PATHS_TO_BACKUP:
101
  if p.exists():
 
104
  else:
105
  log(f"[BACKUP] Warning: {p} does not exist, skipping")
106
 
 
 
 
107
  if not existing_paths:
108
  log("[BACKUP] Skip: no paths to backup")
109
  return False