|
|
@@ -0,0 +1,64 @@
|
|
|
+#!/usr/bin/env python3
|
|
|
+import hashlib
|
|
|
+import os
|
|
|
+import sys
|
|
|
+from pathlib import Path
|
|
|
+
|
|
|
+INTERNAL_ROOT = Path(os.environ.get("ZQ_INTERNAL_WEBAPP", "/home/hxxy/zq/apps/internal/webapp"))
|
|
|
+ROOTS = ("web/upload", "web/subassembly/website")
|
|
|
+EXCLUDED_NAMES = {".DS_Store", ".AppleDouble", "Thumbs.db"}
|
|
|
+EXCLUDED_PREFIXES = ("._", ".zq-stage-")
|
|
|
+EXCLUDED_DIRS = {".zq-quarantine"}
|
|
|
+
|
|
|
+
|
|
|
+def excluded_file(name: str) -> bool:
|
|
|
+ return name in EXCLUDED_NAMES or name.startswith(EXCLUDED_PREFIXES) or name.endswith(".tmp")
|
|
|
+
|
|
|
+
|
|
|
+def sha256_file(path: Path) -> str:
|
|
|
+ digest = hashlib.sha256()
|
|
|
+ with path.open("rb") as handle:
|
|
|
+ while True:
|
|
|
+ chunk = handle.read(1024 * 1024)
|
|
|
+ if not chunk:
|
|
|
+ break
|
|
|
+ digest.update(chunk)
|
|
|
+ return digest.hexdigest()
|
|
|
+
|
|
|
+
|
|
|
+def main() -> int:
|
|
|
+ output = Path(sys.argv[1]) if len(sys.argv) > 1 else None
|
|
|
+ if output is None:
|
|
|
+ print("usage: zq-artifact-manifest.py <output>", file=sys.stderr)
|
|
|
+ return 2
|
|
|
+
|
|
|
+ sys.stdout.reconfigure(errors="surrogateescape")
|
|
|
+ count = 0
|
|
|
+ total_bytes = 0
|
|
|
+ with output.open("w", encoding="utf-8", errors="surrogateescape", newline="\n") as manifest:
|
|
|
+ for root_rel in ROOTS:
|
|
|
+ base = INTERNAL_ROOT / root_rel
|
|
|
+ if not base.is_dir():
|
|
|
+ continue
|
|
|
+ for current, dirs, files in os.walk(base, topdown=True, followlinks=False):
|
|
|
+ dirs[:] = sorted(
|
|
|
+ name for name in dirs
|
|
|
+ if name not in EXCLUDED_DIRS and not name.startswith(EXCLUDED_PREFIXES)
|
|
|
+ )
|
|
|
+ for name in sorted(files):
|
|
|
+ if excluded_file(name):
|
|
|
+ continue
|
|
|
+ full = Path(current) / name
|
|
|
+ if full.is_symlink() or not full.is_file():
|
|
|
+ continue
|
|
|
+ rel = full.relative_to(INTERNAL_ROOT).as_posix()
|
|
|
+ digest = sha256_file(full)
|
|
|
+ manifest.write(f"{digest} {rel}\n")
|
|
|
+ count += 1
|
|
|
+ total_bytes += full.stat().st_size
|
|
|
+ print(f"files={count} bytes={total_bytes}", file=sys.stderr)
|
|
|
+ return 0
|
|
|
+
|
|
|
+
|
|
|
+if __name__ == "__main__":
|
|
|
+ raise SystemExit(main())
|