[Android WebViewShell] Add inclusion test for webview exposed stable interfaces.
[chromium-blink-merge.git] / tools / polymer / txt_to_polymer_grdp.py
blobb775f4c000f0aca855582cd86329a3286b8a0e1a
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.
6 from __future__ import with_statement
7 import string
8 import sys
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.
18 'polymer_grdp_to_txt.py' converts 'polymer_resources.grdp' to a plane list of
19 used Polymer components:
20 ...
21 iron-iron-iconset/iron-iconset-extracted.js
22 iron-iron-iconset/iron-iconset.html
23 ...
25 'txt_to_polymer_grdp.py' converts list back to GRDP file.
27 Usage:
28 $ polymer_grdp_to_txt.py polymer_resources.grdp > /tmp/list.txt
29 $ vim /tmp/list.txt
30 $ txt_to_polymer_grdp.py /tmp/list.txt > polymer_resources.grdp
31 -->
32 <grit-part>
33 <!-- Polymer 1.0 -->
34 %(v_1_0)s
35 <structure name="IDR_POLYMER_1_0_WEB_ANIMATIONS_JS_WEB_ANIMATIONS_NEXT_LITE_MIN_JS"
36 file="../../../third_party/web-animations-js/sources/web-animations-next-lite.min.js"
37 type="chrome_html" />
38 </grit-part>
39 """
42 DEFINITION_TEMPLATE_1_0 = \
43 """ <structure name="%s"
44 file="../../../third_party/polymer/v1_0/components-chromium/%s"
45 type="chrome_html" />"""
48 def PathToGritId(path):
49 table = string.maketrans(string.lowercase + '/.-', string.uppercase + '___')
50 return 'IDR_POLYMER_1_0_' + path.translate(table)
52 def SortKey(record):
53 return (record, PathToGritId(record))
56 def ParseRecord(record):
57 return record.strip()
59 def main(argv):
60 with open(argv[1]) as f:
61 records = [ParseRecord(r) for r in f if not r.isspace()]
62 lines = { 'v_1_0': [] }
63 for path in sorted(set(records), key=SortKey):
64 template = DEFINITION_TEMPLATE_1_0
65 lines['v_1_0'].append(
66 template % (PathToGritId(path), path))
67 print FILE_TEMPLATE % { 'v_1_0': '\n'.join(lines['v_1_0']) }
69 if __name__ == '__main__':
70 sys.exit(main(sys.argv))