|
1 | | -#!/usr/bin/env python |
| 1 | +#!/usr/bin/python |
2 | 2 |
|
3 | 3 | # Uses the Python zip implementation to create deterministic XPI's |
4 | 4 | # Author: Yan Zhu, yan@mit.edu |
|
7 | 7 | Usage: python create_xpi.py -x <exclusions> -n <name of zipped file> <directory> |
8 | 8 | """ |
9 | 9 |
|
| 10 | +import argparse |
10 | 11 | import zipfile_deterministic as zipfile |
11 | 12 | import sys |
12 | 13 | import glob |
13 | | -import getopt |
14 | 14 |
|
15 | | -opts, args = getopt.getopt(sys.argv[1:], 'x:n:') |
| 15 | +parser = argparse.ArgumentParser( |
| 16 | + description="Deterministic XPI file creator.") |
| 17 | +parser.add_argument("-x", type=str, nargs="?", |
| 18 | + dest="exclusions", metavar="File with file pattern exclusions", |
| 19 | + default=".build_exclusions", help="Excluded file patterns.") |
| 20 | +parser.add_argument("-n", type=str, |
| 21 | + dest="name", help="Name of Zip file.") |
| 22 | +parser.add_argument("directory", type=str, |
| 23 | + help="Directory to compress.") |
| 24 | + |
| 25 | +args = parser.parse_args() |
| 26 | + |
| 27 | +xpiName = args.name |
| 28 | +exclusionsFile = args.exclusions |
| 29 | +directory = args.directory |
16 | 30 |
|
17 | 31 | exclusions = [] |
18 | | -for o, v in opts: |
19 | | - if o == "-x": |
20 | | - exclusionsFile = v |
21 | | - with open(exclusionsFile) as f: |
22 | | - for line in f: |
23 | | - exclusions.extend(glob.glob(line.strip())) |
24 | | - exclusions = map(lambda x: './'+x, exclusions) |
25 | | - elif o == "-n": |
26 | | - xpiName = v |
| 32 | +with open(exclusionsFile) as f: |
| 33 | + for line in f: |
| 34 | + exclusions.extend(glob.glob(line.strip())) |
| 35 | +exclusions = map(lambda x: './'+x, exclusions) |
27 | 36 |
|
28 | 37 | compress = zipfile.ZIP_DEFLATED |
29 | 38 |
|
30 | 39 | xpiFile = zipfile.ZipFile(xpiName, mode='w', compression=compress) |
31 | 40 |
|
32 | | -directory = args[0] |
33 | | - |
34 | 41 | xpiFile.write_from_directory(directory, exclusions, compress_type=compress) |
35 | 42 | xpiFile.close() |
0 commit comments