OLD | NEW |
---|---|
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 | 2 |
3 # Copyright 2016 The WebRTC project authors. All Rights Reserved. | 3 # Copyright 2016 The WebRTC project authors. All Rights Reserved. |
4 # | 4 # |
5 # Use of this source code is governed by a BSD-style license | 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 | 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 | 7 # tree. An additional intellectual property rights grant can be found |
8 # in the file PATENTS. All contributing project authors may | 8 # in the file PATENTS. All contributing project authors may |
9 # be found in the AUTHORS file in the root of the source tree. | 9 # be found in the AUTHORS file in the root of the source tree. |
10 | 10 |
11 """Script for flattening iOS header structure.""" | 11 """Script for flattening iOS header structure.""" |
12 | 12 |
13 import optparse | 13 import optparse |
14 import os | 14 import os |
15 import shutil | 15 import shutil |
16 import sys | 16 import sys |
17 | 17 |
18 def FlattenHeaders(lib_base_dir, framework_base_dir): | 18 def FlattenHeaders(input_dir, output_dir): |
kjellander_webrtc
2016/04/15 04:59:41
nit: +1 blank line before top-level definition
htt
tkchin_webrtc
2016/04/16 00:34:19
Done.
| |
19 """Flattens iOS header file directory structure.""" | 19 """Flattens iOS header file directory structure.""" |
20 include_dir = 'include' | 20 # Create output directories. |
21 unflattened_include_dir_path = os.path.join(lib_base_dir, include_dir) | 21 if not os.path.exists(output_dir): |
22 flattened_include_dir_path = os.path.join(framework_base_dir, include_dir) | 22 os.mkdir(output_dir) |
23 | 23 |
24 # Create output directories. | 24 for dirpath, _, filenames in os.walk(input_dir): |
25 if not os.path.exists(framework_base_dir): | |
26 os.mkdir(framework_base_dir) | |
27 if not os.path.exists(flattened_include_dir_path): | |
28 os.mkdir(flattened_include_dir_path) | |
29 | |
30 for dirpath, _, filenames in os.walk(unflattened_include_dir_path): | |
31 for filename in filenames: | 25 for filename in filenames: |
32 current_path = os.path.join(dirpath, filename) | 26 current_path = os.path.join(dirpath, filename) |
33 new_path = os.path.join(flattened_include_dir_path, filename) | 27 new_path = os.path.join(output_dir, filename) |
34 shutil.copy(current_path, new_path) | 28 shutil.copy(current_path, new_path) |
35 | 29 |
36 def Main(): | 30 def Main(): |
37 parser = optparse.OptionParser() | 31 parser = optparse.OptionParser() |
kjellander_webrtc
2016/04/15 04:59:41
If you're only using positional arguments you migh
tkchin_webrtc
2016/04/16 00:34:19
Done.
| |
38 _, args = parser.parse_args() | 32 _, args = parser.parse_args() |
39 if len(args) != 2: | 33 if len(args) != 2: |
40 parser.error('Error: Exactly 2 arguments required.') | 34 parser.error('Error: Exactly 2 arguments required.') |
kjellander_webrtc
2016/04/15 04:59:41
Output a usage line as well?
tkchin_webrtc
2016/04/16 00:34:19
Used argparse everywhere to get free usage and che
| |
41 lib_base_dir = args[0] | 35 input_dir = args[0] |
42 framework_base_dir = args[1] | 36 output_dir = args[1] |
43 FlattenHeaders(lib_base_dir, framework_base_dir) | 37 FlattenHeaders(input_dir, output_dir) |
44 | 38 |
45 if __name__ == '__main__': | 39 if __name__ == '__main__': |
46 sys.exit(Main()) | 40 sys.exit(Main()) |
OLD | NEW |