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
13 """<?xml version="1.0" encoding="utf-8"?>
15 This file is generated.
16 Please use 'src/tools/polymer/polymer_grdp_to_txt.py' and
17 'src/tools/polymer/txt_to_polymer_grdp.py' to modify it, if possible.
19 'polymer_grdp_to_txt.py' converts 'polymer_resources.grdp' to a plane list of
20 used Polymer components:
22 iron-iron-iconset/iron-iconset-extracted.js
23 iron-iron-iconset/iron-iconset.html
26 'txt_to_polymer_grdp.py' converts list back to GRDP file.
29 $ polymer_grdp_to_txt.py polymer_resources.grdp > /tmp/list.txt
31 $ txt_to_polymer_grdp.py /tmp/list.txt > polymer_resources.grdp
36 <structure name="IDR_POLYMER_1_0_WEB_ANIMATIONS_JS_WEB_ANIMATIONS_NEXT_LITE_MIN_JS"
37 file="../../../third_party/web-animations-js/sources/web-animations-next-lite.min.js"
43 DEFINITION_TEMPLATE_1_0
= \
44 """ <structure name="%s"
45 file="../../../third_party/polymer/v1_0/components-chromium/%s"
46 type="chrome_html" />"""
49 def PathToGritId(path
):
50 table
= string
.maketrans(string
.lowercase
+ '/.-', string
.uppercase
+ '___')
51 return 'IDR_POLYMER_1_0_' + path
.translate(table
)
55 return (record
, PathToGritId(record
))
58 def ParseRecord(record
):
62 class FileNotFoundException(Exception):
66 _HERE
= os
.path
.dirname(os
.path
.realpath(__file__
))
67 _POLYMER_DIR
= os
.path
.join(_HERE
, os
.pardir
, os
.pardir
,
68 'third_party', 'polymer', 'v1_0', 'components-chromium')
72 with
open(argv
[1]) as f
:
73 records
= [ParseRecord(r
) for r
in f
if not r
.isspace()]
74 lines
= { 'v_1_0': [] }
75 for path
in sorted(set(records
), key
=SortKey
):
76 full_path
= os
.path
.normpath(os
.path
.join(_POLYMER_DIR
, path
))
77 if not os
.path
.exists(full_path
):
78 raise FileNotFoundException('%s not found' % full_path
)
80 template
= DEFINITION_TEMPLATE_1_0
81 lines
['v_1_0'].append(
82 template
% (PathToGritId(path
), path
))
83 print FILE_TEMPLATE
% { 'v_1_0': '\n'.join(lines
['v_1_0']) }
85 if __name__
== '__main__':
86 sys
.exit(main(sys
.argv
))