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

Side by Side Diff: components/variations/service/generate_ui_string_overrider.py

Issue 1411153006: Variations string overrides now handles more .grd files (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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 | « chrome/chrome_resources.gyp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright 2014 The Chromium Authors. All rights reserved. 2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import argparse 6 import argparse
7 import collections 7 import collections
8 import hashlib 8 import hashlib
9 import operator 9 import operator
10 import os 10 import os
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 Args: 64 Args:
65 resources_content: The input string to process, contains lines of the form 65 resources_content: The input string to process, contains lines of the form
66 "#define NAME INDEX". 66 "#define NAME INDEX".
67 67
68 Returns: 68 Returns:
69 A sorted list of |Resource| objects. 69 A sorted list of |Resource| objects.
70 """ 70 """
71 resources = [Resource(_HashName(name), name, index) for name, index in 71 resources = [Resource(_HashName(name), name, index) for name, index in
72 _GetNameIndexPairsIter(resources_content)] 72 _GetNameIndexPairsIter(resources_content)]
73 73
74 # Deduplicate resources
jwd 2015/10/22 19:00:34 nit: Add a bit more to the comment, like why you n
Moe 2015/10/26 15:09:26 Done.
75 resources = list(set(resources))
76
74 # The default |Resource| order makes |resources| sorted by the hash, then 77 # The default |Resource| order makes |resources| sorted by the hash, then
75 # name, then index. 78 # name, then index.
76 resources.sort() 79 resources.sort()
77 80
78 return resources 81 return resources
79 82
80 83
81 def _CheckForHashCollisions(sorted_resource_list): 84 def _CheckForHashCollisions(sorted_resource_list):
82 """Checks a sorted list of |Resource| objects for hash collisions. 85 """Checks a sorted list of |Resource| objects for hash collisions.
83 86
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 header_filename: Path to the corresponding .h. 156 header_filename: Path to the corresponding .h.
154 157
155 Returns: 158 Returns:
156 .cc file content implementing the CreateUIStringOverrider() factory. 159 .cc file content implementing the CreateUIStringOverrider() factory.
157 """ 160 """
158 hashed_tuples = _GetResourceListFromString(resources_content) 161 hashed_tuples = _GetResourceListFromString(resources_content)
159 162
160 collisions = _CheckForHashCollisions(hashed_tuples) 163 collisions = _CheckForHashCollisions(hashed_tuples)
161 if collisions: 164 if collisions:
162 error_message = "\n".join( 165 error_message = "\n".join(
163 ["hash: %i, name: %s" % (i[0], i[1]) for i in sorted(collisions)]) 166 ["hash: %i, name: %s" % (i.hash, i.name) for i in sorted(collisions)])
164 error_message = ("\nThe following names had hash collisions " 167 error_message = ("\nThe following names had hash collisions "
165 "(sorted by the hash value):\n%s\n" %(error_message)) 168 "(sorted by the hash value):\n%s\n" %(error_message))
166 raise HashCollisionError(error_message) 169 raise HashCollisionError(error_message)
167 170
168 hashes_array = _GenDataArray( 171 hashes_array = _GenDataArray(
169 hashed_tuples, " %iU, // %s", 'kResourceHashes', 'uint32_t', 172 hashed_tuples, " %iU, // %s", 'kResourceHashes', 'uint32_t',
170 operator.attrgetter('hash')) 173 operator.attrgetter('hash'))
171 indices_array = _GenDataArray( 174 indices_array = _GenDataArray(
172 hashed_tuples, " %s, // %s", 'kResourceIndices', 'int', 175 hashed_tuples, " %s, // %s", 'kResourceIndices', 'int',
173 operator.attrgetter('index')) 176 operator.attrgetter('index'))
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 with open(os.path.join( 286 with open(os.path.join(
284 arguments.output_dir, arguments.source_filename), "w") as generated_file: 287 arguments.output_dir, arguments.source_filename), "w") as generated_file:
285 generated_file.write(source_file_content) 288 generated_file.write(source_file_content)
286 with open(os.path.join( 289 with open(os.path.join(
287 arguments.output_dir, arguments.header_filename), "w") as generated_file: 290 arguments.output_dir, arguments.header_filename), "w") as generated_file:
288 generated_file.write(header_file_content) 291 generated_file.write(header_file_content)
289 292
290 293
291 if __name__ == '__main__': 294 if __name__ == '__main__':
292 sys.exit(main()) 295 sys.exit(main())
OLDNEW
« no previous file with comments | « chrome/chrome_resources.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698