OILS / build / make_zip.py View on Github | oilshell.org

53 lines, 29 significant
1#!/usr/bin/env python2
2"""
3make_zip.py
4
5Takes a list of manifests and merges them into a zip file.
6"""
7
8import sys
9import zipfile
10
11
12def main(argv):
13 # Write input files to a .zip
14 out_path = argv[1]
15
16 # NOTE: Startup is ~3 ms faster WITHOUT compression. 38 ms. vs 41. ms.
17 #mode = zipfile.ZIP_DEFLATED
18
19 # Increase size of bytecode, slightly faster compression, don't need zlib.
20 mode = zipfile.ZIP_STORED
21
22 z = zipfile.ZipFile(out_path, 'w', mode)
23
24 seen = {}
25 for line in sys.stdin:
26 line = line.strip()
27 if not line: # Some files are hand-edited. Allow empty lines.
28 continue
29 try:
30 full_path, rel_path = line.split(None, 1)
31 except ValueError:
32 raise RuntimeError('Invalid line %r' % line)
33
34 if rel_path in seen:
35 expected = seen[rel_path]
36 if expected != full_path:
37 print >>sys.stderr, 'WARNING: expected %r, got %r' % (expected,
38 full_path)
39 continue
40
41 #print >>sys.stderr, '%s -> %s' % (full_path, rel_path)
42 z.write(full_path, rel_path)
43 seen[rel_path] = full_path
44
45 # TODO: Make summary
46
47
48if __name__ == '__main__':
49 try:
50 main(sys.argv)
51 except RuntimeError as e:
52 print >>sys.stderr, 'make_zip:', e.args[0]
53 sys.exit(1)