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 """Copy resource files and add -v17 to the sub directory names. | |
newt (away)
2013/05/03 20:16:16
empty line before docstring
Kibeom Kim (inactive)
2013/05/03 20:34:57
Done.
| |
7 | |
8 This is coupled with generate_v14_resources.py. Please refer to | |
9 generate_v14_resources.py's comment for why we are doing this. | |
10 Or crbug.com/235118 . | |
11 """ | |
12 | |
13 import optparse | |
14 import os | |
15 import shutil | |
16 import sys | |
17 | |
18 from util import build_utils | |
19 | |
20 | |
21 def CopyResourcesInDir(input_dir, output_dir): | |
22 """Copy all XML resources from input_dir to output_dir | |
newt (away)
2013/05/03 20:16:16
period and closing quotes at the end of the line
Kibeom Kim (inactive)
2013/05/03 20:34:57
Done.
| |
23 """ | |
24 | |
newt (away)
2013/05/03 20:16:16
don't need an empty line after docstring
Kibeom Kim (inactive)
2013/05/03 20:34:57
Done.
| |
25 for input_file in build_utils.FindInDirectory(input_dir, '*.xml'): | |
26 output_path = os.path.join(output_dir, | |
27 os.path.relpath(input_file, input_dir)) | |
28 build_utils.MakeDirectory(os.path.dirname(output_path)) | |
29 shutil.copy2(input_file, output_path) | |
30 | |
31 | |
32 def ParseArgs(): | |
33 """Parses command line options. | |
34 | |
35 Returns: | |
36 An options object as from optparse.OptionsParser.parse_args() | |
37 """ | |
38 | |
newt (away)
2013/05/03 20:16:16
don't need an empty line after docstring
Kibeom Kim (inactive)
2013/05/03 20:34:57
Done.
| |
39 parser = optparse.OptionParser() | |
40 parser.add_option('--res-dir', | |
41 help='directory containing resources to be copied') | |
42 parser.add_option('--res-v17-dir', | |
43 help='output directory to which resources will be copied.') | |
44 parser.add_option('--stamp', help='File to touch on success') | |
45 | |
46 options, args = parser.parse_args() | |
47 | |
48 if args: | |
49 parser.error('No positional arguments should be given.') | |
50 | |
51 # Check that required options have been provided. | |
52 required_options = ('res_dir', 'res_v17_dir') | |
53 build_utils.CheckOptions(options, parser, required=required_options) | |
54 return options | |
55 | |
56 | |
57 def main(argv): | |
58 options = ParseArgs() | |
59 | |
60 build_utils.DeleteDirectory(options.res_v17_dir) | |
61 build_utils.MakeDirectory(options.res_v17_dir) | |
62 | |
63 for name in os.listdir(options.res_dir): | |
64 if not os.path.isdir(os.path.join(options.res_dir, name)): | |
65 continue | |
66 | |
67 dir_pieces = name.split('-') | |
68 resource_type = dir_pieces[0] | |
69 qualifiers = dir_pieces[1:] | |
70 | |
71 # We only copy resources under layout*/ and xml*/. | |
72 if resource_type not in ('layout', 'xml'): | |
73 continue | |
74 | |
75 # Skip RTL resources because they are not supported by API 14. | |
76 if 'ldrtl' in qualifiers: | |
77 continue | |
78 | |
79 # Copy all the resource files. | |
80 input_path = os.path.join(options.res_dir, name) | |
81 output_path = os.path.join(options.res_v17_dir, name + '-v17') | |
82 CopyResourcesInDir(input_path, output_path) | |
83 | |
84 if options.stamp: | |
85 build_utils.Touch(options.stamp) | |
86 | |
87 if __name__ == '__main__': | |
88 sys.exit(main(sys.argv)) | |
89 | |
OLD | NEW |