| 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 xml resource files and add -v17 to the sub directory names. | |
| 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 http://crbug.com/235118 . | |
| 12 """ | |
| 13 | |
| 14 import optparse | |
| 15 import os | |
| 16 import shutil | |
| 17 import sys | |
| 18 import xml.dom.minidom as minidom | |
| 19 | |
| 20 from util import build_utils | |
| 21 | |
| 22 | |
| 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'): | |
| 26 if only_styles: | |
| 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'): | |
| 31 continue | |
| 32 | |
| 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) | |
| 37 | |
| 38 | |
| 39 def ParseArgs(): | |
| 40 """Parses command line options. | |
| 41 | |
| 42 Returns: | |
| 43 An options object as from optparse.OptionsParser.parse_args() | |
| 44 """ | |
| 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') | |
| 51 | |
| 52 options, args = parser.parse_args() | |
| 53 | |
| 54 if args: | |
| 55 parser.error('No positional arguments should be given.') | |
| 56 | |
| 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) | |
| 60 return options | |
| 61 | |
| 62 | |
| 63 def main(argv): | |
| 64 options = ParseArgs() | |
| 65 | |
| 66 build_utils.DeleteDirectory(options.res_v17_dir) | |
| 67 build_utils.MakeDirectory(options.res_v17_dir) | |
| 68 | |
| 69 for name in os.listdir(options.res_dir): | |
| 70 if not os.path.isdir(os.path.join(options.res_dir, name)): | |
| 71 continue | |
| 72 | |
| 73 dir_pieces = name.split('-') | |
| 74 resource_type = dir_pieces[0] | |
| 75 qualifiers = dir_pieces[1:] | |
| 76 | |
| 77 # Skip RTL resources because they are not supported by API 14. | |
| 78 if 'ldrtl' in qualifiers: | |
| 79 continue | |
| 80 | |
| 81 input_dir = os.path.join(options.res_dir, name) | |
| 82 output_dir = os.path.join(options.res_v17_dir, name + '-v17') | |
| 83 | |
| 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) | |
| 92 | |
| 93 if options.stamp: | |
| 94 build_utils.Touch(options.stamp) | |
| 95 | |
| 96 if __name__ == '__main__': | |
| 97 sys.exit(main(sys.argv)) | |
| 98 | |
| OLD | NEW |