31 lines
996 B
Python
31 lines
996 B
Python
#!/usr/bin/env python3
|
|
"""Normalize Windows-style ZIP entries in a Mini Program build directory."""
|
|
|
|
from pathlib import Path
|
|
import os
|
|
import sys
|
|
|
|
|
|
def normalize(root: Path) -> int:
|
|
moved = 0
|
|
entries = sorted(root.rglob("*"), key=lambda path: len(path.parts), reverse=True)
|
|
for entry in entries:
|
|
if "\\" not in entry.name:
|
|
continue
|
|
target = entry.parent.joinpath(*entry.name.split("\\"))
|
|
target.parent.mkdir(parents=True, exist_ok=True)
|
|
if target.exists():
|
|
raise FileExistsError(f"normalization target already exists: {target}")
|
|
os.replace(entry, target)
|
|
moved += 1
|
|
return moved
|
|
|
|
|
|
if __name__ == "__main__":
|
|
if len(sys.argv) != 2:
|
|
raise SystemExit(f"usage: {Path(sys.argv[0]).name} BUILD_DIR")
|
|
build_dir = Path(sys.argv[1])
|
|
if not build_dir.is_dir():
|
|
raise SystemExit(f"build directory not found: {build_dir}")
|
|
print(f"normalized {normalize(build_dir)} Windows-style paths")
|