44 lines
1.1 KiB
Python
44 lines
1.1 KiB
Python
#!/usr/bin/env python3
|
|
"""Stage the portable app bundle within the Web distribution's file limits."""
|
|
|
|
import argparse
|
|
import json
|
|
import shutil
|
|
from pathlib import Path
|
|
|
|
|
|
PART_BYTES = 24 * 1024 * 1024
|
|
|
|
|
|
def package_bundle(bundle: Path, output: Path) -> None:
|
|
if output.exists():
|
|
shutil.rmtree(output)
|
|
output.mkdir()
|
|
|
|
size = 0
|
|
parts = []
|
|
with bundle.open("rb") as source:
|
|
while block := source.read(PART_BYTES):
|
|
name = f"part-{len(parts):03d}.bin"
|
|
(output / name).write_bytes(block)
|
|
parts.append(name)
|
|
size += len(block)
|
|
|
|
if not parts:
|
|
raise ValueError(f"Empty app bundle: {bundle}")
|
|
(output / "manifest.json").write_text(
|
|
json.dumps({"size": size, "parts": parts}) + "\n", encoding="utf-8"
|
|
)
|
|
|
|
|
|
def main() -> None:
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("bundle", type=Path)
|
|
parser.add_argument("output", type=Path)
|
|
args = parser.parse_args()
|
|
package_bundle(args.bundle, args.output)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|