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 | |
Dan Beam
2015/03/17 16:37:53
why is this necessary? just to use with?
dzhioev (left Google)
2015/03/17 18:26:46
Yep.
| |
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: | |
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 | |
29 'txt_to_polymer_grdp.py' converts list back to GRDP file. | |
30 | |
31 Usage: | |
32 $ polymer_grdp_to_txt.py polymer_resources.grdp > /tmp/list.txt | |
33 $ vim /tmp/list.txt | |
34 $ txt_to_polymer_grdp.py /tmp/list.txt > polymer_resources.grdp | |
35 --> | |
36 <grit-part> | |
37 %s | |
38 <structure name="IDR_POLYMER_WEB_ANIMATIONS_JS_WEB_ANIMATIONS_NEXT_LITE_MIN_JS " | |
39 file="../../../third_party/web-animations-js/sources/web-animations -next-lite.min.js" | |
40 type="chrome_html" /> | |
41 <structure name="IDR_POLYMER_WEB_ANIMATIONS_JS_WEB_ANIMATIONS_NEXT_LITE_MIN_JS _MAP" | |
42 file="../../../third_party/web-animations-js/sources/web-animations -next-lite.min.js.map" | |
43 type="chrome_html" /> | |
44 </grit-part> | |
45 """ | |
46 | |
47 | |
48 DEFINITION_TEMPLATE = \ | |
49 """ <structure name="%s" | |
50 file="../../../third_party/polymer/components-chromium/%s" | |
51 type="chrome_html" />""" | |
52 | |
53 | |
54 def PathToGritId(path): | |
55 table = string.maketrans(string.lowercase + '/.-', string.uppercase + '___') | |
56 return 'IDR_POLYMER_' + path.translate(table) | |
57 | |
58 | |
59 def main(argv): | |
60 with open(argv[1]) as f: | |
61 paths = [p.strip() for p in f if p.strip()] | |
Dan Beam
2015/03/17 16:37:53
what is this code doing? filtering out empty line
dzhioev (left Google)
2015/03/17 18:26:46
Not only empty, but also whitespace-only lines. In
| |
62 lines = [] | |
63 for path in sorted(paths, key=PathToGritId): | |
64 lines.append(DEFINITION_TEMPLATE % (PathToGritId(path), path)) | |
65 print FILE_TEMPLATE % '\n'.join(lines) | |
66 | |
67 | |
68 if __name__ == '__main__': | |
69 sys.exit(main(sys.argv)) | |
OLD | NEW |