File size: 1,365 Bytes
f95cbd4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"""Build a deterministic source/research ZIP from the verified release manifest."""
import argparse
from pathlib import Path
import zipfile
from celestis_rl.release import verify_manifest,MANIFEST


def main():
    p=argparse.ArgumentParser(description=__doc__)
    p.add_argument("--root",default=str(Path(__file__).resolve().parents[1]))
    p.add_argument("--output",required=True)
    args=p.parse_args();root=Path(args.root).resolve();out=Path(args.output).resolve()
    if root==out or root in out.parents:
        raise ValueError("write archives outside the source tree to avoid including the archive in itself")
    m=verify_manifest(root);out.parent.mkdir(parents=True,exist_ok=True)
    with zipfile.ZipFile(out,'w',compression=zipfile.ZIP_DEFLATED,compresslevel=9) as z:
        for rel in sorted([*m['files'],MANIFEST]):
            info=zipfile.ZipInfo(f"{root.name}/{rel}",date_time=(2026,9,21,0,0,0))
            info.compress_type=zipfile.ZIP_DEFLATED
            info.external_attr=((0o755 if rel.endswith('.sh') else 0o644)&0xFFFF)<<16
            z.writestr(info,(root/rel).read_bytes(),compresslevel=9)
    with zipfile.ZipFile(out) as z:
        if z.testzip() is not None: raise ValueError('ZIP CRC verification failed')
    print(f"Created {out.name}: {len(m['files'])+1} files, {out.stat().st_size} bytes")


if __name__=='__main__':main()