1# This Source Code Form is subject to the terms of the Mozilla Public
2# License, v. 2.0. If a copy of the MPL was not distributed with this
3# file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
5# This script creates a zip file, but will also strip any binaries
6# it finds before adding them to the zip.
7
8from __future__ import absolute_import
9
10from mozpack.files import FileFinder
11from mozpack.copier import Jarrer
12from mozpack.errors import errors
13
14import argparse
15import mozpack.path as mozpath
16import sys
17
18def main(args):
19    parser = argparse.ArgumentParser()
20    parser.add_argument("-C", metavar='DIR', default=".",
21                        help="Change to given directory before considering "
22                        "other paths")
23    parser.add_argument("zip", help="Path to zip file to write")
24    parser.add_argument("input", nargs="+",
25                        help="Path to files to add to zip")
26    args = parser.parse_args(args)
27
28    jarrer = Jarrer(optimize=False)
29
30    with errors.accumulate():
31        finder = FileFinder(args.C)
32        for path in args.input:
33            for p, f in finder.find(path):
34                jarrer.add(p, f)
35        jarrer.copy(mozpath.join(args.C, args.zip))
36
37
38if __name__ == '__main__':
39    main(sys.argv[1:])
40