| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 """Copy xml resource files and add -v17 to the sub directory names. | 7 """Copy xml resource files and add -v17 to the sub directory names. |
| 8 | 8 |
| 9 This is coupled with generate_v14_resources.py. Please refer to | 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. | 10 generate_v14_resources.py's comment for why we are doing this. |
| 11 Or http://crbug.com/235118 . | 11 Or http://crbug.com/235118 . |
| 12 """ | 12 """ |
| 13 | 13 |
| 14 import optparse | 14 import optparse |
| 15 import os | 15 import os |
| 16 import shutil | 16 import shutil |
| 17 import sys | 17 import sys |
| 18 import xml.dom.minidom as minidom |
| 18 | 19 |
| 19 from util import build_utils | 20 from util import build_utils |
| 20 | 21 |
| 21 | 22 |
| 22 def CopyXmlResourcesInDir(input_dir, output_dir): | 23 def CopyXmlResourcesInDir(input_dir, output_dir, only_styles=False): |
| 23 """Copy all XML resources from input_dir to output_dir.""" | 24 """Copy all XML resources from input_dir to output_dir.""" |
| 24 for input_file in build_utils.FindInDirectory(input_dir, '*.xml'): | 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 |
| 25 output_path = os.path.join(output_dir, | 33 output_path = os.path.join(output_dir, |
| 26 os.path.relpath(input_file, input_dir)) | 34 os.path.relpath(input_file, input_dir)) |
| 27 build_utils.MakeDirectory(os.path.dirname(output_path)) | 35 build_utils.MakeDirectory(os.path.dirname(output_path)) |
| 28 shutil.copy2(input_file, output_path) | 36 shutil.copy2(input_file, output_path) |
| 29 | 37 |
| 30 | 38 |
| 31 def ParseArgs(): | 39 def ParseArgs(): |
| 32 """Parses command line options. | 40 """Parses command line options. |
| 33 | 41 |
| 34 Returns: | 42 Returns: |
| (...skipping 24 matching lines...) Expand all Loading... |
| 59 build_utils.MakeDirectory(options.res_v17_dir) | 67 build_utils.MakeDirectory(options.res_v17_dir) |
| 60 | 68 |
| 61 for name in os.listdir(options.res_dir): | 69 for name in os.listdir(options.res_dir): |
| 62 if not os.path.isdir(os.path.join(options.res_dir, name)): | 70 if not os.path.isdir(os.path.join(options.res_dir, name)): |
| 63 continue | 71 continue |
| 64 | 72 |
| 65 dir_pieces = name.split('-') | 73 dir_pieces = name.split('-') |
| 66 resource_type = dir_pieces[0] | 74 resource_type = dir_pieces[0] |
| 67 qualifiers = dir_pieces[1:] | 75 qualifiers = dir_pieces[1:] |
| 68 | 76 |
| 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. | 77 # Skip RTL resources because they are not supported by API 14. |
| 74 if 'ldrtl' in qualifiers: | 78 if 'ldrtl' in qualifiers: |
| 75 continue | 79 continue |
| 76 | 80 |
| 77 # Copy all the resource files. | 81 input_dir = os.path.join(options.res_dir, name) |
| 78 input_path = os.path.join(options.res_dir, name) | 82 output_dir = os.path.join(options.res_v17_dir, name + '-v17') |
| 79 output_path = os.path.join(options.res_v17_dir, name + '-v17') | 83 |
| 80 CopyXmlResourcesInDir(input_path, output_path) | 84 # We only copy resources under layout*/, xml*/, |
| 85 # and style resources under values*/. |
| 86 if resource_type in ('layout', 'xml'): |
| 87 CopyXmlResourcesInDir(input_dir, output_dir) |
| 88 elif resource_type in ('values'): |
| 89 CopyXmlResourcesInDir(input_dir, output_dir, True) |
| 81 | 90 |
| 82 if options.stamp: | 91 if options.stamp: |
| 83 build_utils.Touch(options.stamp) | 92 build_utils.Touch(options.stamp) |
| 84 | 93 |
| 85 if __name__ == '__main__': | 94 if __name__ == '__main__': |
| 86 sys.exit(main(sys.argv)) | 95 sys.exit(main(sys.argv)) |
| 87 | 96 |
| OLD | NEW |