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.
7 """Copy xml resource files and add -v17 to the sub directory names.
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 http://crbug.com/235118 .
18 import xml
.dom
.minidom
as minidom
20 from util
import build_utils
23 def CopyXmlResourcesInDir(input_dir
, output_dir
, only_styles
=False):
24 """Copy all XML resources from input_dir to output_dir."""
25 for input_file
in build_utils
.FindInDirectory(input_dir
, '*.xml'):
27 # If the xml file does not have a style element,
28 # it's not style resource, so skip.
29 dom
= minidom
.parse(input_file
)
30 if not dom
.getElementsByTagName('style'):
33 output_path
= os
.path
.join(output_dir
,
34 os
.path
.relpath(input_file
, input_dir
))
35 build_utils
.MakeDirectory(os
.path
.dirname(output_path
))
36 shutil
.copy2(input_file
, output_path
)
40 """Parses command line options.
43 An options object as from optparse.OptionsParser.parse_args()
45 parser
= optparse
.OptionParser()
46 parser
.add_option('--res-dir',
47 help='directory containing resources to be copied')
48 parser
.add_option('--res-v17-dir',
49 help='output directory to which resources will be copied.')
50 parser
.add_option('--stamp', help='File to touch on success')
52 options
, args
= parser
.parse_args()
55 parser
.error('No positional arguments should be given.')
57 # Check that required options have been provided.
58 required_options
= ('res_dir', 'res_v17_dir')
59 build_utils
.CheckOptions(options
, parser
, required
=required_options
)
66 build_utils
.DeleteDirectory(options
.res_v17_dir
)
67 build_utils
.MakeDirectory(options
.res_v17_dir
)
69 for name
in os
.listdir(options
.res_dir
):
70 if not os
.path
.isdir(os
.path
.join(options
.res_dir
, name
)):
73 dir_pieces
= name
.split('-')
74 resource_type
= dir_pieces
[0]
75 qualifiers
= dir_pieces
[1:]
77 # Skip RTL resources because they are not supported by API 14.
78 if 'ldrtl' in qualifiers
:
81 input_dir
= os
.path
.join(options
.res_dir
, name
)
82 output_dir
= os
.path
.join(options
.res_v17_dir
, name
+ '-v17')
84 # We only copy resources under layout*/, xml*/,
85 # and style resources under values*/.
86 # TODO(kkimlabs): don't process xml directly once all layouts have
87 # been moved out of XML directory. see http://crbug.com/238458
88 if resource_type
in ('layout', 'xml'):
89 CopyXmlResourcesInDir(input_dir
, output_dir
)
90 elif resource_type
in ('values'):
91 CopyXmlResourcesInDir(input_dir
, output_dir
, only_styles
=True)
94 build_utils
.Touch(options
.stamp
)
96 if __name__
== '__main__':
97 sys
.exit(main(sys
.argv
))