All scripts now use os.path.dirname(os.path.abspath(__file__)) to dynamically resolve paths relative to their location, consistent with backend/app.py. Also fixes healthcheck.sh to use --fail and --max-time for curl, and corrects port references to 19000. Affected files: - set_state.py - healthcheck.sh - office-agent-push.py - convert_to_webp.py - repack_star_working.py Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
61 lines
1.7 KiB
Python
61 lines
1.7 KiB
Python
#!/usr/bin/env python3
|
|
"""简单的状态更新工具,用于测试 Star Office UI"""
|
|
|
|
import json
|
|
import os
|
|
import sys
|
|
from datetime import datetime
|
|
|
|
ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
STATE_FILE = os.path.join(ROOT_DIR, "state.json")
|
|
|
|
VALID_STATES = [
|
|
"idle",
|
|
"writing",
|
|
"researching",
|
|
"executing",
|
|
"syncing",
|
|
"error"
|
|
]
|
|
|
|
def load_state():
|
|
if os.path.exists(STATE_FILE):
|
|
with open(STATE_FILE, "r", encoding="utf-8") as f:
|
|
return json.load(f)
|
|
return {
|
|
"state": "idle",
|
|
"detail": "待命中...",
|
|
"progress": 0,
|
|
"updated_at": datetime.now().isoformat()
|
|
}
|
|
|
|
def save_state(state):
|
|
with open(STATE_FILE, "w", encoding="utf-8") as f:
|
|
json.dump(state, f, ensure_ascii=False, indent=2)
|
|
|
|
if __name__ == "__main__":
|
|
if len(sys.argv) < 2:
|
|
print("用法: python set_state.py <state> [detail]")
|
|
print(f"状态选项: {', '.join(VALID_STATES)}")
|
|
print("\n例子:")
|
|
print(" python set_state.py idle")
|
|
print(" python set_state.py researching \"在查 Godot MCP...\"")
|
|
print(" python set_state.py writing \"在写热点日报模板...\"")
|
|
sys.exit(1)
|
|
|
|
state_name = sys.argv[1]
|
|
detail = sys.argv[2] if len(sys.argv) > 2 else ""
|
|
|
|
if state_name not in VALID_STATES:
|
|
print(f"无效状态: {state_name}")
|
|
print(f"有效选项: {', '.join(VALID_STATES)}")
|
|
sys.exit(1)
|
|
|
|
state = load_state()
|
|
state["state"] = state_name
|
|
state["detail"] = detail
|
|
state["updated_at"] = datetime.now().isoformat()
|
|
|
|
save_state(state)
|
|
print(f"状态已更新: {state_name} - {detail}")
|