Skip to content

Commit 587ebf4

Browse files
committed
Merged branch 'create-xpi-argparse'.
2 parents 0a634e2 + 79d599c commit 587ebf4

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

utils/create_xpi.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/python
22

33
# Uses the Python zip implementation to create deterministic XPI's
44
# Author: Yan Zhu, yan@mit.edu
@@ -7,29 +7,36 @@
77
Usage: python create_xpi.py -x <exclusions> -n <name of zipped file> <directory>
88
"""
99

10+
import argparse
1011
import zipfile_deterministic as zipfile
1112
import sys
1213
import glob
13-
import getopt
1414

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
1630

1731
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)
2736

2837
compress = zipfile.ZIP_DEFLATED
2938

3039
xpiFile = zipfile.ZipFile(xpiName, mode='w', compression=compress)
3140

32-
directory = args[0]
33-
3441
xpiFile.write_from_directory(directory, exclusions, compress_type=compress)
3542
xpiFile.close()

0 commit comments

Comments
 (0)