OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 # | |
3 # Copyright 2013 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 import optparse | |
8 import os | |
9 import sys | |
10 | |
11 from util import build_utils | |
12 | |
13 | |
14 def copy_resources_in_dir(input_dir, output_dir): | |
cjhopman
2013/04/26 20:57:31
Chrome uses MixedCase for function names (except f
Kibeom Kim (inactive)
2013/04/27 00:05:07
Done.
| |
15 """Copy resources in the directory recursively. | |
16 """ | |
17 | |
18 for root, dirs, files in os.walk(input_dir, followlinks=True): | |
19 relative_dir = os.path.relpath(root, input_dir) | |
20 for file_name in files: | |
21 if not file_name.lower().endswith('.xml'): | |
22 continue | |
cjhopman
2013/04/26 20:57:31
You could use build_utils.FindInDirectory() here.
Kibeom Kim (inactive)
2013/04/27 00:05:07
Done. Much shorter thanks!
| |
23 input_filename = os.path.join(input_dir, relative_dir, file_name) | |
24 output_filename = os.path.join(output_dir, relative_dir, file_name) | |
25 | |
26 build_utils.MakeDirectory(os.path.dirname(input_filename)) | |
cjhopman
2013/04/26 20:57:31
I don't think you need to make the input directory
Kibeom Kim (inactive)
2013/04/27 00:05:07
Done.
| |
27 build_utils.MakeDirectory(os.path.dirname(output_filename)) | |
28 build_utils.CopyFile(input_filename, output_filename) | |
29 | |
30 | |
31 def ParseArgs(): | |
32 """Parses command line options. | |
33 | |
34 Returns: | |
35 An options object as from optparse.OptionsParser.parse_args() | |
36 """ | |
37 parser = optparse.OptionParser() | |
38 parser.add_option('--res-dir', | |
39 help='directory containing resources to be copied') | |
40 parser.add_option('--res-v17-dir', | |
41 help='dest directory to be copied.') | |
42 | |
43 (options, args) = parser.parse_args() | |
cjhopman
2013/04/26 20:57:31
don't need parentheses, just "options, args"
Kibeom Kim (inactive)
2013/04/27 00:05:07
Done.
| |
44 | |
45 if args: | |
46 parser.error('No positional arguments should be given.') | |
47 | |
48 # Check that required options have been provided. | |
49 required_options = ('res_dir', 'res_v17_dir') | |
50 build_utils.CheckOptions(options, parser, required=required_options) | |
51 return options | |
52 | |
53 | |
54 def main(argv): | |
55 """Copy resource files and add -v17 to the sub directory names. | |
cjhopman
2013/04/26 20:57:31
I'd prefer a file-level docstring (or have both).
Kibeom Kim (inactive)
2013/04/27 00:05:07
Done.
| |
56 """ | |
57 options = ParseArgs() | |
58 | |
59 res_sub_dir_names = os.walk(options.res_dir).next()[1] | |
60 build_utils.MakeDirectory(options.res_v17_dir) | |
61 | |
62 for res_sub_dir_name in res_sub_dir_names: | |
63 dir_pieces = res_sub_dir_name.split('-') | |
64 resource_type = dir_pieces[0] | |
65 qualifiers = dir_pieces[1:] | |
66 | |
67 # We only copy resources under layout*/ and xml*/. | |
68 if resource_type not in ('layout', 'xml'): | |
69 continue | |
70 | |
71 # Skip RTL resources because they are not supported by API 14. | |
72 if 'ldrtl' in qualifiers: | |
73 continue | |
74 | |
75 # Copy all the resource files recursively. | |
76 copy_resources_in_dir(os.path.join(options.res_dir, | |
77 res_sub_dir_name), | |
78 os.path.join(options.res_v17_dir, | |
79 res_sub_dir_name + '-v17')) | |
80 | |
81 | |
82 if __name__ == '__main__': | |
83 sys.exit(main(sys.argv)) | |
84 | |
OLD | NEW |