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

Side by Side Diff: mojo/services/html_viewer/generate_blink_resource_map.py

Issue 1033733004: Part 3 of 4: Modify blink users so they use the image resources in blink. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix 100/200 percent packs. Created 5 years, 9 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 | « mojo/services/html_viewer/blink_resource_constants.h ('k') | tools/gritsettings/resource_ids » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2015 The Chromium Authors. All rights reserved. 1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 from string import Template 5 from string import Template
6 6
7 import optparse 7 import optparse
8 import os 8 import os
9 import sys 9 import sys
10 10
11 try: 11 try:
12 grit_module_path = os.path.join( 12 grit_module_path = os.path.join(
13 os.path.dirname(__file__), '..', '..', '..', 'tools', 'grit') 13 os.path.dirname(__file__), '..', '..', '..', 'tools', 'grit')
14 sys.path.insert(0, grit_module_path) 14 sys.path.insert(0, grit_module_path)
15 from grit.format import data_pack as DataPack 15 from grit.format import data_pack as DataPack
16 except ImportError, e: 16 except ImportError, e:
17 print 'ImportError: ', e 17 print 'ImportError: ', e
18 sys.exit(-1) 18 sys.exit(-1)
19 19
20 def is_ascii(s):
21 return all(ord(c) < 128 for c in s)
22
23 header_template = \ 20 header_template = \
24 """// Copyright 2015 The Chromium Authors. All rights reserved. 21 """// Copyright 2015 The Chromium Authors. All rights reserved.
25 // Use of this source code is governed by a BSD-style license that can be 22 // Use of this source code is governed by a BSD-style license that can be
26 // found in the LICENSE file. 23 // found in the LICENSE file.
27 24
28 #ifndef MOJO_SERVICES_HTML_VIEWER_BLINK_RESOURCE_MAP_H_ 25 #ifndef MOJO_SERVICES_HTML_VIEWER_BLINK_RESOURCE_MAP_H_
29 #define MOJO_SERVICES_HTML_VIEWER_BLINK_RESOURCE_MAP_H_ 26 #define MOJO_SERVICES_HTML_VIEWER_BLINK_RESOURCE_MAP_H_
30 27
31 #include <map> 28 #include <map>
32 29
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 107
111 pak_contents = DataPack.ReadDataPack(options.pak_file) 108 pak_contents = DataPack.ReadDataPack(options.pak_file)
112 resourceIds = [] 109 resourceIds = []
113 110
114 header_contents = dict() 111 header_contents = dict()
115 cpp_contents = dict() 112 cpp_contents = dict()
116 113
117 definitions = [] 114 definitions = []
118 115
119 for (resId, data) in pak_contents.resources.iteritems(): 116 for (resId, data) in pak_contents.resources.iteritems():
120 if not is_ascii(data):
121 continue
122 resourceIds.append(resId) 117 resourceIds.append(resId)
123 hex_values = ['0x{0:02x}'.format(ord(char)) for char in data] 118 hex_values = ['0x{0:02x}'.format(ord(char)) for char in data]
124 f = lambda A, n=12: [A[i:i+n] for i in range(0, len(A), n)] 119 f = lambda A, n=12: [A[i:i+n] for i in range(0, len(A), n)]
125 hex_values_string = ',\n '.join(', '.join(x) for x in f(hex_values)) 120 hex_values_string = ',\n '.join(', '.join(x) for x in f(hex_values))
126 cpp_definition = \ 121 cpp_definition = \
127 'const char kResource%s[%d] = {\n %s \n};' % \ 122 'const char kResource%s[%d] = {\n %s \n};' % \
128 (str(resId), len(hex_values), hex_values_string) 123 (str(resId), len(hex_values), hex_values_string)
129 definitions.append(cpp_definition) 124 definitions.append(cpp_definition)
130 125
131 header_file_contents = Template(header_template).substitute(header_contents) 126 header_file_contents = Template(header_template).substitute(header_contents)
(...skipping 10 matching lines...) Expand all
142 137
143 cpp_contents['definitions']= '\n'.join(definitions) 138 cpp_contents['definitions']= '\n'.join(definitions)
144 cpp_contents['header_file_name'] = os.path.basename(options.header_file) 139 cpp_contents['header_file_name'] = os.path.basename(options.header_file)
145 cpp_contents['map_initializer'] = '\n '.join(map_initializer) 140 cpp_contents['map_initializer'] = '\n '.join(map_initializer)
146 cpp_file_contents = Template(cpp_template).substitute(cpp_contents) 141 cpp_file_contents = Template(cpp_template).substitute(cpp_contents)
147 cpp_file.write(cpp_file_contents) 142 cpp_file.write(cpp_file_contents)
148 cpp_file.close() 143 cpp_file.close()
149 144
150 if __name__ == '__main__': 145 if __name__ == '__main__':
151 main() 146 main()
OLDNEW
« no previous file with comments | « mojo/services/html_viewer/blink_resource_constants.h ('k') | tools/gritsettings/resource_ids » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698