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 """Copy resource files and add -v17 to the sub directory names. | |
cjhopman
2013/05/03 21:23:04
Nit: Copy xml resource files? See comment below.
Kibeom Kim (inactive)
2013/05/03 22:09:57
Done.
| |
8 | |
9 This is coupled with generate_v14_resources.py. Please refer to | |
10 generate_v14_resources.py's comment for why we are doing this. | |
11 Or crbug.com/235118 . | |
cjhopman
2013/05/03 21:23:04
Nit: add http:// (many linkifiers require it).
Kibeom Kim (inactive)
2013/05/03 22:09:57
Done.
| |
12 """ | |
13 | |
14 import optparse | |
15 import os | |
16 import shutil | |
17 import sys | |
18 | |
19 from util import build_utils | |
20 | |
21 | |
22 def CopyResourcesInDir(input_dir, output_dir): | |
cjhopman
2013/05/03 21:23:04
Nit: Maybe rename to CopyXmlResourcesInDir? Or is
Kibeom Kim (inactive)
2013/05/03 22:09:57
Done.
| |
23 """Copy all XML resources from input_dir to output_dir.""" | |
24 for input_file in build_utils.FindInDirectory(input_dir, '*.xml'): | |
25 output_path = os.path.join(output_dir, | |
26 os.path.relpath(input_file, input_dir)) | |
27 build_utils.MakeDirectory(os.path.dirname(output_path)) | |
28 shutil.copy2(input_file, output_path) | |
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='output directory to which resources will be copied.') | |
42 parser.add_option('--stamp', help='File to touch on success') | |
43 | |
44 options, args = parser.parse_args() | |
45 | |
46 if args: | |
47 parser.error('No positional arguments should be given.') | |
48 | |
49 # Check that required options have been provided. | |
50 required_options = ('res_dir', 'res_v17_dir') | |
51 build_utils.CheckOptions(options, parser, required=required_options) | |
52 return options | |
53 | |
54 | |
55 def main(argv): | |
56 options = ParseArgs() | |
57 | |
58 build_utils.DeleteDirectory(options.res_v17_dir) | |
59 build_utils.MakeDirectory(options.res_v17_dir) | |
60 | |
61 for name in os.listdir(options.res_dir): | |
62 if not os.path.isdir(os.path.join(options.res_dir, name)): | |
63 continue | |
64 | |
65 dir_pieces = name.split('-') | |
66 resource_type = dir_pieces[0] | |
67 qualifiers = dir_pieces[1:] | |
68 | |
69 # We only copy resources under layout*/ and xml*/. | |
70 if resource_type not in ('layout', 'xml'): | |
71 continue | |
72 | |
73 # Skip RTL resources because they are not supported by API 14. | |
74 if 'ldrtl' in qualifiers: | |
75 continue | |
76 | |
77 # Copy all the resource files. | |
78 input_path = os.path.join(options.res_dir, name) | |
79 output_path = os.path.join(options.res_v17_dir, name + '-v17') | |
80 CopyResourcesInDir(input_path, output_path) | |
81 | |
82 if options.stamp: | |
83 build_utils.Touch(options.stamp) | |
84 | |
85 if __name__ == '__main__': | |
86 sys.exit(main(sys.argv)) | |
87 | |
OLD | NEW |