OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 # | |
3 # Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | |
kjellander_webrtc
2017/01/04 14:25:21
New files should have the current year.
mbonadei
2017/01/04 15:19:06
Good catch, I am still writing 2016 everywhere. :-
| |
4 # | |
5 # Use of this source code is governed by a BSD-style license | |
6 # that can be found in the LICENSE file in the root of the source | |
7 # tree. An additional intellectual property rights grant can be found | |
8 # in the file PATENTS. All contributing project authors may | |
9 # be found in the AUTHORS file in the root of the source tree. | |
10 | |
11 #TODO(mbonadei): move this script into chromium (build/android/gyp) | |
kjellander_webrtc
2017/01/04 14:25:21
Comments usually don't start right after the #.
I
mbonadei
2017/01/04 15:19:06
Acknowledged.
| |
12 # when approved | |
13 | |
14 #TODO(mbonadei): write some documentation on how to use this script | |
15 | |
16 import re | |
17 import optparse | |
18 import os | |
19 import sys | |
20 import zipfile | |
21 import ntpath | |
kjellander_webrtc
2017/01/04 14:25:21
sort alphabetically
mbonadei
2017/01/04 15:19:06
Acknowledged.
| |
22 | |
23 #TODO(mbonadei): fix this import and meke it relative to the chromium | |
kjellander_webrtc
2017/01/04 14:25:21
meke -> make
mbonadei
2017/01/04 15:19:06
Acknowledged.
| |
24 # build/android/gyp folder. | |
25 sys.path.insert(0, os.path.abspath('../../build/android/gyp/util')) | |
kjellander_webrtc
2017/01/04 14:25:21
Please build the path using os.path.join and os.pa
mbonadei
2017/01/04 15:19:06
Acknowledged.
| |
26 import build_utils | |
27 | |
28 | |
29 def FindZipPathFromSource(src_file): | |
kjellander_webrtc
2017/01/04 14:25:21
Can you add a docstring what this method does?
I
mbonadei
2017/01/04 15:19:06
Acknowledged.
| |
30 with open(src_file, "r") as f: | |
kjellander_webrtc
2017/01/04 14:25:21
You can leave out 'r', as it's the default if mode
mbonadei
2017/01/04 15:19:06
Acknowledged.
| |
31 file_src = f.read() | |
32 package = re.search("package (.*);", file_src).group(1) | |
kjellander_webrtc
2017/01/04 14:25:21
Please use single-quotes for all strings. The styl
mbonadei
2017/01/04 15:19:06
Acknowledged.
| |
33 zip_folder = package.replace('.', os.path.sep) | |
34 file_name = ntpath.basename(src_file) | |
kjellander_webrtc
2017/01/04 14:25:21
I don't ntpath is useful here. Just regular os.pat
mbonadei
2017/01/04 15:19:06
Acknowledged.
| |
35 return os.path.join(zip_folder, file_name) | |
36 | |
37 | |
38 def DoMain(argv): | |
39 usage = 'usage: %prog [options] [output_dir] input_file(s)...' | |
40 parser = optparse.OptionParser(usage=usage) | |
41 parser.add_option('--srcjar', | |
kjellander_webrtc
2017/01/04 14:25:21
For our use case this is a required flag, right? T
mbonadei
2017/01/04 15:19:06
Acknowledged.
I am not throwing parser.error in t
| |
42 help='When specified, a .srcjar at the given path is ' | |
43 'created instead of individual .java files.') | |
44 | |
45 options, args = parser.parse_args(argv) | |
46 | |
47 if not args: | |
48 parser.error('Need to specify at least one input file') | |
49 input_paths = args | |
50 | |
51 with zipfile.ZipFile(options.srcjar, 'w', zipfile.ZIP_STORED) as srcjar: | |
52 for src_path in input_paths: | |
53 zip_path = FindZipPathFromSource(src_path) | |
kjellander_webrtc
2017/01/04 14:25:21
This manipulation just to figure out the path insi
mbonadei
2017/01/04 15:19:06
Yeah, I agree but I think that probably it is the
| |
54 build_utils.AddToZipHermetic(srcjar, zip_path, src_path) | |
55 | |
56 | |
57 if __name__ == '__main__': | |
58 DoMain(sys.argv[1:]) | |
OLD | NEW |