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 """Convert Android xml resources to API 14 compatible. | 7 """Convert Android xml resources to API 14 compatible. |
8 | 8 |
9 There are two reasons that we cannot just use API 17 attributes, | 9 There are two reasons that we cannot just use API 17 attributes, |
10 so we are generating another set of resources by this script. | 10 so we are generating another set of resources by this script. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 'paddingEnd' : 'paddingRight', | 44 'paddingEnd' : 'paddingRight', |
45 'drawableEnd' : 'drawableRight', | 45 'drawableEnd' : 'drawableRight', |
46 'layout_alignEnd' : 'layout_alignRight', | 46 'layout_alignEnd' : 'layout_alignRight', |
47 'layout_marginEnd' : 'layout_marginRight', | 47 'layout_marginEnd' : 'layout_marginRight', |
48 'layout_alignParentEnd' : 'layout_alignParentRight', | 48 'layout_alignParentEnd' : 'layout_alignParentRight', |
49 'layout_toEndOf' : 'layout_toRightOf'} | 49 'layout_toEndOf' : 'layout_toRightOf'} |
50 | 50 |
51 ATTRIBUTES_TO_MAP = dict(['android:' + k, 'android:' + v] for k, v | 51 ATTRIBUTES_TO_MAP = dict(['android:' + k, 'android:' + v] for k, v |
52 in ATTRIBUTES_TO_MAP.iteritems()) | 52 in ATTRIBUTES_TO_MAP.iteritems()) |
53 | 53 |
54 ATTRIBUTES_TO_MAP_REVERSED = dict([v,k] for k, v | 54 ATTRIBUTES_TO_MAP_REVERSED = dict([v, k] for k, v |
55 in ATTRIBUTES_TO_MAP.iteritems()) | 55 in ATTRIBUTES_TO_MAP.iteritems()) |
56 | 56 |
57 | 57 |
58 def IterateXmlElements(node): | 58 def IterateXmlElements(node): |
59 """minidom helper function that iterates all the element nodes. | 59 """minidom helper function that iterates all the element nodes. |
60 Iteration order is pre-order depth-first.""" | 60 Iteration order is pre-order depth-first.""" |
61 if node.nodeType == node.ELEMENT_NODE: | 61 if node.nodeType == node.ELEMENT_NODE: |
62 yield node | 62 yield node |
63 for child_node in node.childNodes: | 63 for child_node in node.childNodes: |
64 for child_node_element in IterateXmlElements(child_node): | 64 for child_node_element in IterateXmlElements(child_node): |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 | 274 |
275 if args: | 275 if args: |
276 parser.error('No positional arguments should be given.') | 276 parser.error('No positional arguments should be given.') |
277 | 277 |
278 # Check that required options have been provided. | 278 # Check that required options have been provided. |
279 required_options = ('res_dir', 'res_v14_compatibility_dir') | 279 required_options = ('res_dir', 'res_v14_compatibility_dir') |
280 build_utils.CheckOptions(options, parser, required=required_options) | 280 build_utils.CheckOptions(options, parser, required=required_options) |
281 return options | 281 return options |
282 | 282 |
283 | 283 |
284 def main(argv): | 284 def main(): |
285 options = ParseArgs() | 285 options = ParseArgs() |
286 | 286 |
287 build_utils.DeleteDirectory(options.res_v14_compatibility_dir) | 287 build_utils.DeleteDirectory(options.res_v14_compatibility_dir) |
288 build_utils.MakeDirectory(options.res_v14_compatibility_dir) | 288 build_utils.MakeDirectory(options.res_v14_compatibility_dir) |
289 | 289 |
290 for name in os.listdir(options.res_dir): | 290 for name in os.listdir(options.res_dir): |
291 if not os.path.isdir(os.path.join(options.res_dir, name)): | 291 if not os.path.isdir(os.path.join(options.res_dir, name)): |
292 continue | 292 continue |
293 | 293 |
294 dir_pieces = name.split('-') | 294 dir_pieces = name.split('-') |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 '-'.join([resource_type] + | 335 '-'.join([resource_type] + |
336 output_qualifiers)) | 336 output_qualifiers)) |
337 GenerateV14StyleResourcesInDir(input_dir, output_v14_dir) | 337 GenerateV14StyleResourcesInDir(input_dir, output_v14_dir) |
338 elif not api_level_qualifier: | 338 elif not api_level_qualifier: |
339 ErrorIfStyleResourceExistsInDir(input_dir) | 339 ErrorIfStyleResourceExistsInDir(input_dir) |
340 | 340 |
341 if options.stamp: | 341 if options.stamp: |
342 build_utils.Touch(options.stamp) | 342 build_utils.Touch(options.stamp) |
343 | 343 |
344 if __name__ == '__main__': | 344 if __name__ == '__main__': |
345 sys.exit(main(sys.argv)) | 345 sys.exit(main()) |
346 | 346 |
OLD | NEW |