Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 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 | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 from __future__ import with_statement | |
| 7 import string | |
| 8 import sys | |
| 9 | |
| 10 | |
| 11 FILE_TEMPLATE = \ | |
| 12 """<?xml version="1.0" encoding="utf-8"?> | |
| 13 <!-- | |
| 14 This file is generated. | |
| 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. | |
| 17 | |
| 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: | |
| 20 ... | |
| 21 core-animation/core-animation.html | |
| 22 core-animation/web-animations.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 ... | |
| 31 | |
| 32 'txt_to_polymer_grdp.py' converts list back to GRDP file. | |
| 33 | |
| 34 Usage: | |
| 35 $ polymer_grdp_to_txt.py polymer_resources.grdp > /tmp/list.txt | |
| 36 $ vim /tmp/list.txt | |
| 37 $ txt_to_polymer_grdp.py /tmp/list.txt > polymer_resources.grdp | |
| 38 --> | |
| 39 <grit-part> | |
| 40 <!-- Polymer 0.5 (TODO: Remove by M45 branch point) --> | |
| 41 %(v_0_5)s | |
| 42 <structure name="IDR_POLYMER_WEB_ANIMATIONS_JS_WEB_ANIMATIONS_NEXT_LITE_MIN_JS " | |
| 43 file="../../../third_party/web-animations-js/sources/web-animations -next-lite.min.js" | |
| 44 type="chrome_html" /> | |
| 45 <structure name="IDR_POLYMER_WEB_ANIMATIONS_JS_WEB_ANIMATIONS_NEXT_LITE_MIN_JS _MAP" | |
| 46 file="../../../third_party/web-animations-js/sources/web-animations -next-lite.min.js.map" | |
|
Dan Beam
2015/06/16 00:09:18
the presubmit is not fond of your examples... perh
dzhioev (left Google)
2015/06/16 00:18:16
Unfortunately this is not an example, but a part o
Dan Beam
2015/06/16 00:19:40
ah, either do some string splitting magic or NOPRE
| |
| 47 type="chrome_html" /> | |
| 48 | |
| 49 <!-- Polymer 1.0 --> | |
| 50 %(v_1_0)s | |
| 51 </grit-part> | |
| 52 """ | |
| 53 | |
| 54 | |
| 55 DEFINITION_TEMPLATE_0_5 = \ | |
| 56 """ <structure name="%s" | |
| 57 file="../../../third_party/polymer/components-chromium/%s" | |
| 58 type="chrome_html" />""" | |
| 59 | |
| 60 DEFINITION_TEMPLATE_1_0 = \ | |
| 61 """ <structure name="%s" | |
| 62 file="../../../third_party/polymer/v1_0/components-chromium/%s" | |
| 63 type="chrome_html" />""" | |
| 64 | |
| 65 | |
| 66 def PathToGritId(path, is_1_0): | |
| 67 table = string.maketrans(string.lowercase + '/.-', string.uppercase + '___') | |
| 68 return 'IDR_POLYMER_' + ('1_0_' if is_1_0 else '') + path.translate(table) | |
| 69 | |
| 70 def SortKey(record): | |
| 71 return (record[1], PathToGritId(record[0], record[1])) | |
| 72 | |
| 73 | |
| 74 def ParseRecord(record): | |
| 75 record = record.strip() | |
| 76 v_1_0_prefix = 'v1.0 ' | |
| 77 if record.startswith(v_1_0_prefix): | |
| 78 return (record[len(v_1_0_prefix):], True) | |
| 79 else: | |
| 80 return (record, False) | |
| 81 | |
| 82 def main(argv): | |
| 83 with open(argv[1]) as f: | |
| 84 records = [ParseRecord(r) for r in f if not r.isspace()] | |
| 85 lines = { 'v_0_5': [], 'v_1_0': [] } | |
| 86 for (path, is_1_0) in sorted(set(records), key=SortKey): | |
| 87 template = DEFINITION_TEMPLATE_1_0 if is_1_0 else DEFINITION_TEMPLATE_0_5 | |
| 88 lines['v_1_0' if is_1_0 else 'v_0_5'].append( | |
| 89 template % (PathToGritId(path, is_1_0), path)) | |
| 90 print FILE_TEMPLATE % { 'v_0_5': '\n'.join(lines['v_0_5']), | |
| 91 'v_1_0': '\n'.join(lines['v_1_0']) } | |
| 92 | |
| 93 if __name__ == '__main__': | |
| 94 sys.exit(main(sys.argv)) | |
| OLD | NEW |