This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
#!/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")
|
||||
Reference in New Issue
Block a user