| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2015 The Chromium Authors. All rights reserved. | 2 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 from __future__ import with_statement | 6 from __future__ import with_statement |
| 7 import string | 7 import string |
| 8 import sys | 8 import sys |
| 9 | 9 |
| 10 | 10 |
| 11 FILE_TEMPLATE = \ | 11 FILE_TEMPLATE = \ |
| 12 """<?xml version="1.0" encoding="utf-8"?> | 12 """<?xml version="1.0" encoding="utf-8"?> |
| 13 <!-- | 13 <!-- |
| 14 This file is generated. | 14 This file is generated. |
| 15 Please use 'src/tools/polymer/polymer_grdp_to_txt.py' and | 15 Please use 'src/tools/polymer/polymer_grdp_to_txt.py' and |
| 16 'src/tools/polymer/txt_to_polymer_grdp.py' to modify it, if possible. | 16 'src/tools/polymer/txt_to_polymer_grdp.py' to modify it, if possible. |
| 17 | 17 |
| 18 'polymer_grdp_to_txt.py' converts 'polymer_resources.grdp' to a plane list of | 18 'polymer_grdp_to_txt.py' converts 'polymer_resources.grdp' to a plane list of |
| 19 used Polymer components. v1.0 elements are marked with 'v1.0 ' prefix: | 19 used Polymer components: |
| 20 ... | 20 ... |
| 21 core-animation/core-animation.html | 21 iron-iron-iconset/iron-iconset-extracted.js |
| 22 core-animation/web-animations.html | 22 iron-iron-iconset/iron-iconset.html |
| 23 core-collapse/core-collapse-extracted.js | |
| 24 core-collapse/core-collapse.css | |
| 25 core-collapse/core-collapse.html | |
| 26 core-dropdown/core-dropdown-base-extracted.js | |
| 27 ... | |
| 28 v1.0 iron-iron-iconset/iron-iconset-extracted.js | |
| 29 v1.0 iron-iron-iconset/iron-iconset.html | |
| 30 ... | 23 ... |
| 31 | 24 |
| 32 'txt_to_polymer_grdp.py' converts list back to GRDP file. | 25 'txt_to_polymer_grdp.py' converts list back to GRDP file. |
| 33 | 26 |
| 34 Usage: | 27 Usage: |
| 35 $ polymer_grdp_to_txt.py polymer_resources.grdp > /tmp/list.txt | 28 $ polymer_grdp_to_txt.py polymer_resources.grdp > /tmp/list.txt |
| 36 $ vim /tmp/list.txt | 29 $ vim /tmp/list.txt |
| 37 $ txt_to_polymer_grdp.py /tmp/list.txt > polymer_resources.grdp | 30 $ txt_to_polymer_grdp.py /tmp/list.txt > polymer_resources.grdp |
| 38 --> | 31 --> |
| 39 <grit-part> | 32 <grit-part> |
| 40 <!-- Polymer 0.5 (TODO: Remove by M45 branch point) --> | |
| 41 %(v_0_5)s | |
| 42 | |
| 43 <!-- Polymer 1.0 --> | 33 <!-- Polymer 1.0 --> |
| 44 %(v_1_0)s | 34 %(v_1_0)s |
| 45 <structure name="IDR_POLYMER_1_0_WEB_ANIMATIONS_JS_WEB_ANIMATIONS_NEXT_LITE_MI
N_JS" | 35 <structure name="IDR_POLYMER_1_0_WEB_ANIMATIONS_JS_WEB_ANIMATIONS_NEXT_LITE_MI
N_JS" |
| 46 file="../../../third_party/web-animations-js/sources/web-animations
-next-lite.min.js" | 36 file="../../../third_party/web-animations-js/sources/web-animations
-next-lite.min.js" |
| 47 type="chrome_html" /> | 37 type="chrome_html" /> |
| 48 </grit-part> | 38 </grit-part> |
| 49 """ | 39 """ |
| 50 | 40 |
| 51 | 41 |
| 52 DEFINITION_TEMPLATE_0_5 = \ | |
| 53 """ <structure name="%s" | |
| 54 file="../../../third_party/polymer/components-chromium/%s" | |
| 55 type="chrome_html" />""" | |
| 56 | |
| 57 DEFINITION_TEMPLATE_1_0 = \ | 42 DEFINITION_TEMPLATE_1_0 = \ |
| 58 """ <structure name="%s" | 43 """ <structure name="%s" |
| 59 file="../../../third_party/polymer/v1_0/components-chromium/%s" | 44 file="../../../third_party/polymer/v1_0/components-chromium/%s" |
| 60 type="chrome_html" />""" | 45 type="chrome_html" />""" |
| 61 | 46 |
| 62 | 47 |
| 63 def PathToGritId(path, is_1_0): | 48 def PathToGritId(path): |
| 64 table = string.maketrans(string.lowercase + '/.-', string.uppercase + '___') | 49 table = string.maketrans(string.lowercase + '/.-', string.uppercase + '___') |
| 65 return 'IDR_POLYMER_' + ('1_0_' if is_1_0 else '') + path.translate(table) | 50 return 'IDR_POLYMER_1_0_' + path.translate(table) |
| 66 | 51 |
| 67 def SortKey(record): | 52 def SortKey(record): |
| 68 return (record[1], PathToGritId(record[0], record[1])) | 53 return (record, PathToGritId(record)) |
| 69 | 54 |
| 70 | 55 |
| 71 def ParseRecord(record): | 56 def ParseRecord(record): |
| 72 record = record.strip() | 57 return record.strip() |
| 73 v_1_0_prefix = 'v1.0 ' | |
| 74 if record.startswith(v_1_0_prefix): | |
| 75 return (record[len(v_1_0_prefix):], True) | |
| 76 else: | |
| 77 return (record, False) | |
| 78 | 58 |
| 79 def main(argv): | 59 def main(argv): |
| 80 with open(argv[1]) as f: | 60 with open(argv[1]) as f: |
| 81 records = [ParseRecord(r) for r in f if not r.isspace()] | 61 records = [ParseRecord(r) for r in f if not r.isspace()] |
| 82 lines = { 'v_0_5': [], 'v_1_0': [] } | 62 lines = { 'v_1_0': [] } |
| 83 for (path, is_1_0) in sorted(set(records), key=SortKey): | 63 for path in sorted(set(records), key=SortKey): |
| 84 template = DEFINITION_TEMPLATE_1_0 if is_1_0 else DEFINITION_TEMPLATE_0_5 | 64 template = DEFINITION_TEMPLATE_1_0 |
| 85 lines['v_1_0' if is_1_0 else 'v_0_5'].append( | 65 lines['v_1_0'].append( |
| 86 template % (PathToGritId(path, is_1_0), path)) | 66 template % (PathToGritId(path), path)) |
| 87 print FILE_TEMPLATE % { 'v_0_5': '\n'.join(lines['v_0_5']), | 67 print FILE_TEMPLATE % { 'v_1_0': '\n'.join(lines['v_1_0']) } |
| 88 'v_1_0': '\n'.join(lines['v_1_0']) } | |
| 89 | 68 |
| 90 if __name__ == '__main__': | 69 if __name__ == '__main__': |
| 91 sys.exit(main(sys.argv)) | 70 sys.exit(main(sys.argv)) |
| OLD | NEW |