Bug 1348229 - Add an unzip py_action script based on the mozjar code. r?mshal
In the long term, this can be used to replace uses of the system unzip program.
new file mode 100644
--- /dev/null
+++ b/python/mozbuild/mozbuild/action/unzip.py
@@ -0,0 +1,44 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+# This script creates a zip file, but will also strip any binaries
+# it finds before adding them to the zip.
+
+from __future__ import absolute_import
+
+import argparse
+import mozpack.path as mozpath
+import sys
+from mozbuild.util import ensureParentDir
+from mozpack.mozjar import JarReader
+from mozpack.files import DeflatedFile
+
+
+def main(args):
+ parser = argparse.ArgumentParser()
+ parser.add_argument("-C", metavar='DIR', default=".",
+ help="Change to given directory before extracting")
+ parser.add_argument("-l", action='store_true',
+ help="List files")
+ parser.add_argument("zip", help="Path to zip file")
+ parser.add_argument("files", nargs="*",
+ help="Path to files to extract from zip")
+ args = parser.parse_args(args)
+
+ jar = JarReader(file=args.zip)
+
+ for entry in jar.entries:
+ if not args.files or any(mozpath.match(entry, f)
+ for f in args.files):
+ if args.l:
+ print entry
+ else:
+ print 'Extracting {}'.format(entry)
+ dest = mozpath.join(args.C, entry)
+ ensureParentDir(dest)
+ DeflatedFile(jar[entry]).copy(dest)
+
+
+if __name__ == '__main__':
+ main(sys.argv[1:])