| 1 | #!/usr/bin/env python
|
| 2 | """
|
| 3 | make_zip.py
|
| 4 |
|
| 5 | Takes a list of manifests and merges them into a zip file.
|
| 6 | """
|
| 7 |
|
| 8 | import sys
|
| 9 | import zipfile
|
| 10 |
|
| 11 |
|
| 12 | def 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 | try:
|
| 28 | full_path, rel_path = line.split(None, 1)
|
| 29 | except ValueError:
|
| 30 | raise RuntimeError('Invalid line %r' % line)
|
| 31 |
|
| 32 | if rel_path in seen:
|
| 33 | expected = seen[rel_path]
|
| 34 | if expected != full_path:
|
| 35 | print >>sys.stderr, 'WARNING: expected %r, got %r' % (expected,
|
| 36 | full_path)
|
| 37 | continue
|
| 38 |
|
| 39 | #print >>sys.stderr, '%s -> %s' % (full_path, rel_path)
|
| 40 | z.write(full_path, rel_path)
|
| 41 | seen[rel_path] = full_path
|
| 42 |
|
| 43 | # TODO: Make summary
|
| 44 |
|
| 45 |
|
| 46 | if __name__ == '__main__':
|
| 47 | try:
|
| 48 | main(sys.argv)
|
| 49 | except RuntimeError as e:
|
| 50 | print >>sys.stderr, 'make_zip:', e.args[0]
|
| 51 | sys.exit(1)
|