auto-sync: 2026-03-26 10:53:44

This commit is contained in:
cfdaily
2026-03-26 10:53:44 +08:00
parent 9e3883677a
commit 546ec4cdc9
7 changed files with 46 additions and 18 deletions
@@ -16,12 +16,12 @@ from pathlib import Path
# 配置
PROJECT_DIR = "/Users/chufeng/.openclaw/sanguo_projects/sanguo_quant_live"
SELF_DIR = os.path.dirname(os.path.abspath(__file__))
LOG_FILE = os.path.join(SELF_DIR, "file-watcher.log")
SYNC_SCRIPT = os.path.join(PROJECT_DIR, "auto-sync.sh")
LOG_FILE = os.path.join(PROJECT_DIR, "simple-watcher.log")
SYNC_SCRIPT = os.path.join(PROJECT_DIR, "management/sanguo_auto_sync/auto-sync.sh")
LOCK_FILE = "/tmp/sanguo_sync.lock"
CHECK_INTERVAL = 60 # 检查间隔(秒)= 1 分钟
IGNORE_EXTENSIONS = ['.log', '.tmp', '~']
IGNORE_DIRS = ['.git']
IGNORE_EXTENSIONS = ['.log', '.tmp', '~', '.pyc']
IGNORE_DIRS = ['.git', '__pycache__', 'venv', '.venv', 'node_modules']
# 设置日志
logging.basicConfig(
@@ -79,6 +79,7 @@ class FileWatcher:
"""检查文件变化"""
changes_detected = False
# 第一步:遍历当前目录,检测新增和修改
for root, dirs, files in os.walk(self.directory):
# 跳过忽略的目录
dirs[:] = [d for d in dirs if d not in IGNORE_DIRS]
@@ -113,6 +114,23 @@ class FileWatcher:
changes_detected = True
logger.info(f"File deleted: {filepath.relative_to(self.directory)}")
# 第二步:反向检查 - 已记录的文件是否还存在
# 找出已不存在的文件(删除检测)
existing_files = list(self.last_modified.keys())
for filepath_str in existing_files:
filepath = Path(filepath_str)
if self._should_ignore(filepath):
continue
if not filepath.exists():
# 文件已被删除
del self.last_modified[filepath_str]
changes_detected = True
try:
rel_path = filepath.relative_to(self.directory)
logger.info(f"File deleted: {rel_path}")
except:
logger.info(f"File deleted: {filepath_str}")
return changes_detected
def run_sync(self):