| 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. |
| 11 | 11 |
| 12 1. paddingStart attribute can cause a crash on Galaxy Tab 2. | 12 1. paddingStart attribute can cause a crash on Galaxy Tab 2. |
| 13 2. There is a bug that paddingStart does not override paddingLeft on | 13 2. There is a bug that paddingStart does not override paddingLeft on |
| 14 JB-MR1. This is fixed on JB-MR2. b/8654490 | 14 JB-MR1. This is fixed on JB-MR2. b/8654490 |
| 15 | 15 |
| 16 Therefore, this resource generation script can be removed when | 16 Therefore, this resource generation script can be removed when |
| 17 we drop the support for JB-MR1. | 17 we drop the support for JB-MR1. |
| 18 | 18 |
| 19 Please refer to http://crbug.com/235118 for the details. | 19 Please refer to http://crbug.com/235118 for the details. |
| 20 """ | 20 """ |
| 21 | 21 |
| 22 import codecs |
| 22 import optparse | 23 import optparse |
| 23 import os | 24 import os |
| 24 import re | 25 import re |
| 25 import shutil | 26 import shutil |
| 26 import sys | 27 import sys |
| 27 import xml.dom.minidom as minidom | 28 import xml.dom.minidom as minidom |
| 28 | 29 |
| 29 from util import build_utils | 30 from util import build_utils |
| 30 | 31 |
| 31 # Note that we are assuming 'android:' is an alias of | 32 # Note that we are assuming 'android:' is an alias of |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 msg += ('\nFor background, see: http://android-developers.blogspot.com/' | 90 msg += ('\nFor background, see: http://android-developers.blogspot.com/' |
| 90 '2013/03/native-rtl-support-in-android-42.html\n' | 91 '2013/03/native-rtl-support-in-android-42.html\n' |
| 91 'If you have a legitimate need for this attribute, discuss with ' | 92 'If you have a legitimate need for this attribute, discuss with ' |
| 92 'kkimlabs@chromium.org or newt@chromium.org') | 93 'kkimlabs@chromium.org or newt@chromium.org') |
| 93 raise Exception(msg) | 94 raise Exception(msg) |
| 94 | 95 |
| 95 | 96 |
| 96 def WriteDomToFile(dom, filename): | 97 def WriteDomToFile(dom, filename): |
| 97 """Write the given dom to filename.""" | 98 """Write the given dom to filename.""" |
| 98 build_utils.MakeDirectory(os.path.dirname(filename)) | 99 build_utils.MakeDirectory(os.path.dirname(filename)) |
| 99 with open(filename, 'w') as f: | 100 with codecs.open(filename, 'w', 'utf-8') as f: |
| 100 dom.writexml(f, '', ' ', '\n', encoding='utf-8') | 101 dom.writexml(f, '', ' ', '\n', encoding='utf-8') |
| 101 | 102 |
| 102 | 103 |
| 103 def HasStyleResource(dom): | 104 def HasStyleResource(dom): |
| 104 """Return True if the dom is a style resource, False otherwise.""" | 105 """Return True if the dom is a style resource, False otherwise.""" |
| 105 root_node = IterateXmlElements(dom).next() | 106 root_node = IterateXmlElements(dom).next() |
| 106 return bool(root_node.nodeName == 'resources' and | 107 return bool(root_node.nodeName == 'resources' and |
| 107 list(root_node.getElementsByTagName('style'))) | 108 list(root_node.getElementsByTagName('style'))) |
| 108 | 109 |
| 109 | 110 |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 build_utils.MakeDirectory(res_v14_dir) | 311 build_utils.MakeDirectory(res_v14_dir) |
| 311 | 312 |
| 312 GenerateV14Resources(options.res_dir, res_v14_dir) | 313 GenerateV14Resources(options.res_dir, res_v14_dir) |
| 313 | 314 |
| 314 if options.stamp: | 315 if options.stamp: |
| 315 build_utils.Touch(options.stamp) | 316 build_utils.Touch(options.stamp) |
| 316 | 317 |
| 317 if __name__ == '__main__': | 318 if __name__ == '__main__': |
| 318 sys.exit(main()) | 319 sys.exit(main()) |
| 319 | 320 |
| OLD | NEW |