# Conflicts:
#	.idea/workspace.xml
This commit is contained in:
2025-08-29 20:48:47 +08:00
52 changed files with 116 additions and 145 deletions

View File

@@ -14,38 +14,34 @@ def _find_support_root(hint: Optional[Path]) -> Optional[Path]:
2) 其次:环境变量 SUPPORT_DDI_DIR
3) 再次:从 __file__ 所在目录向上搜索 3 层,找名为 'SupportFiles' 的目录
"""
# 1) 显式参数
if hint and hint.exists():
return hint.resolve()
# 2) 环境变量
env = os.environ.get("SUPPORT_DDI_DIR")
if env:
p = Path(env).expanduser()
if p.exists():
return p.resolve()
# 3) 向上搜索
here = Path(__file__).resolve().parent
for i in range(4): # 当前目录 + 向上 3 层
for _ in range(4): # 当前目录 + 向上 3 层
cand = here / "SupportFiles"
if cand.exists():
return cand.resolve()
here = here.parent
return None
@dataclass
class DevDiskImageDeployer:
"""
同步 SupportFiles/<version>/... 到 ~/.tidevice/device-support/<version>/...
- 自动定位 SupportFiles显式参数/环境变量/向上搜索)
- 已存在则跳过,不存在才复制
- 详细日志
同步 SupportFiles/<version>/ 或 SupportFiles/<version>.zip 到 ~/.tidevice/device-support
- 目录:复制为 ~/.tidevice/device-support/<version>/
- zip原样复制为 ~/.tidevice/device-support/<version>.zip (不解压)
- 已存在则跳过;如设置 overwrite=True 则覆盖
"""
project_support_root: Optional[Path] = None # 可不传,自动发现
cache_root: Optional[Path] = None # 默认 ~/.tidevice/device-support
project_support_root: Optional[Path] = None
cache_root: Optional[Path] = None
verbose: bool = True
dry_run: bool = False
overwrite: bool = False
@@ -73,7 +69,6 @@ class DevDiskImageDeployer:
print(f"[INFO] resolved SupportFiles = {self._src_dir}")
print(f"[INFO] cache_dir = {self._cache_dir}")
# 打印一眼能看见的兄弟目录,防路径误判
parent = self._src_dir.parent
try:
siblings = ", ".join(sorted(p.name for p in parent.iterdir() if p.is_dir()))
@@ -83,41 +78,58 @@ class DevDiskImageDeployer:
pass
def deploy_all(self):
candidates = list(self._iter_version_dirs(self._src_dir))
if self.verbose:
if not candidates:
print("[WARN] 未发现任何版本目录(仅匹配 15 / 15.6 / 16.7 / 16.7.1 这种名字)")
else:
print("[INFO] 发现版本目录:")
for c in candidates:
print(f" - {c.name}")
entries = list(self._iter_version_entries(self._src_dir))
copied = skipped = 0
for ver_dir in candidates:
dst = self._cache_dir / ver_dir.name
if dst.exists() and not self.overwrite:
if self.verbose:
print(f"[SKIP] 已存在:{dst}")
skipped += 1
continue
if dst.exists() and self.overwrite:
if self.verbose:
print(f"[INFO] 覆盖模式,删除:{dst}")
if not self.dry_run:
for p, kind, version in entries:
# kind: "dir" 或 "zip"
if kind == "dir":
dst = self._cache_dir / version
exists = dst.exists()
if exists and not self.overwrite:
skipped += 1
if self.verbose:
print(f"[SKIP] {dst} 已存在(目录)")
continue
if exists and self.overwrite and not self.dry_run:
shutil.rmtree(dst)
if self.verbose:
print(f"[COPY] {ver_dir} -> {dst}")
if not self.dry_run:
shutil.copytree(ver_dir, dst)
copied += 1
if self.verbose:
print(f"[COPY] DIR {p} -> {dst}")
if not self.dry_run:
shutil.copytree(p, dst)
copied += 1
elif kind == "zip":
dst = self._cache_dir / f"{version}.zip"
exists = dst.exists()
if exists and not self.overwrite:
skipped += 1
if self.verbose:
print(f"[SKIP] {dst} 已存在zip")
continue
if exists and self.overwrite and not self.dry_run:
dst.unlink()
if self.verbose:
print(f"[COPY] ZIP {p} -> {dst}")
if not self.dry_run:
# 用 copy2 保留 mtime 等元数据
shutil.copy2(p, dst)
copied += 1
if self.verbose:
print(f"[SUMMARY] copied={copied}, skipped={skipped}, total={copied+skipped}")
# -------- helpers --------
def _iter_version_dirs(self, root: Path) -> Iterable[Path]:
def _iter_version_entries(self, root: Path) -> Iterable[tuple[Path, str, str]]:
"""
迭代返回 (路径, 类型, 版本号)
- 目录:名称需匹配版本号
- zipstem去除后缀的名称需匹配版本号
"""
for p in sorted(root.iterdir()):
if p.is_dir() and VERSION_RE.match(p.name):
yield p
yield (p, "dir", p.name)
elif p.is_file() and p.suffix.lower() == ".zip" and VERSION_RE.match(p.stem):
yield (p, "zip", p.stem)