Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 2 # | |
| 3 # Copyright 2016 The Chromium Authors. All rights reserved. | |
| 4 # Use of this source code is governed by a BSD-style license that can be | |
| 5 # found in the LICENSE file. | |
| 6 | |
| 7 """Processes an Android AAR file.""" | |
| 8 | |
| 9 import argparse | |
| 10 import os | |
| 11 import shutil | |
| 12 import sys | |
| 13 import zipfile | |
| 14 | |
| 15 from util import build_utils | |
| 16 | |
|
agrieve
2016/07/15 14:34:40
nit: 2 blank lines between top-level things
Ian Wen
2016/07/17 02:08:09
Done.
| |
| 17 def main(): | |
| 18 parser = argparse.ArgumentParser(description=__doc__) | |
| 19 parser.add_argument('--extract', | |
| 20 help=('Extract the files to output directory.'), | |
|
agrieve
2016/07/15 14:34:41
these braces are not required.
Ian Wen
2016/07/17 02:08:08
Done.
| |
| 21 action='store_true') | |
| 22 parser.add_argument('--list_res', | |
|
agrieve
2016/07/15 14:34:41
use - rather than _ in flags. --list-resources
Ian Wen
2016/07/17 02:08:09
Done.
| |
| 23 help=('List all files in res folder.'), | |
| 24 action='store_true') | |
| 25 parser.add_argument('--input_file', | |
| 26 help=('Name and path of the AAR file.'), | |
|
agrieve
2016/07/15 14:34:41
nit: path implies name. Just say "Path to the .aar
Ian Wen
2016/07/17 02:08:09
Done.
| |
| 27 required=True, | |
| 28 metavar='FILE') | |
| 29 parser.add_argument('--output_dir', | |
| 30 help=('Output dir for the extracted files.'), | |
|
agrieve
2016/07/15 14:34:41
nit: don't use abbreviations in help when possible
Ian Wen
2016/07/17 02:08:09
Done.
| |
| 31 required=True, | |
|
agrieve
2016/07/15 14:34:40
This shouldn't be required for --list
Ian Wen
2016/07/17 02:08:08
Done.
| |
| 32 metavar='PATH') | |
|
agrieve
2016/07/15 14:34:41
It would make more sense to say 'DIR' since your o
Ian Wen
2016/07/17 02:08:09
Done.
| |
| 33 | |
| 34 args = parser.parse_args() | |
| 35 | |
| 36 aar_file = args.input_file # e.g. library.aar | |
| 37 output_dir = args.output_dir # e.g. path/to/output | |
| 38 | |
| 39 if (args.extract): | |
|
agrieve
2016/07/15 14:34:41
nit: drop parentheses.
Ian Wen
2016/07/17 02:08:08
Done.
| |
| 40 # Clear previously extracted versions of the AAR | |
|
agrieve
2016/07/15 14:34:41
nit: missing . at end of sentence.
Ian Wen
2016/07/17 02:08:09
Done.
| |
| 41 shutil.rmtree(output_dir, True) | |
| 42 build_utils.ExtractAll(aar_file, path=output_dir) | |
| 43 | |
| 44 if (args.list_res): | |
| 45 with zipfile.ZipFile(aar_file) as z: | |
| 46 for name in z.namelist(): | |
| 47 if name.startswith('res/') and not name.endswith('/'): | |
| 48 print os.path.join(output_dir, name) | |
|
agrieve
2016/07/15 14:34:41
I think it would make more sense to just output na
Ian Wen
2016/07/17 02:08:09
Done.
| |
| 49 | |
| 50 if __name__ == '__main__': | |
| 51 sys.exit(main()) | |
| OLD | NEW |