Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(349)

Side by Side Diff: tools/polymer/txt_to_polymer_grdp.py

Issue 984553002: Added helper scripts for modifying polymer_resources.grdp. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased again. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/polymer/polymer_grdp_to_txt.py ('k') | ui/webui/resources/polymer_resources.grdp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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))
OLDNEW
« no previous file with comments | « tools/polymer/polymer_grdp_to_txt.py ('k') | ui/webui/resources/polymer_resources.grdp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698