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

Side by Side Diff: remoting/tools/verify_resources.py

Issue 684373002: [Chromoting] Remove warning for unused strings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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 | « remoting/remoting.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/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 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 """Verifies that GRD resource files define all the strings used by a given 6 """Verifies that GRD resource files define all the strings used by a given
7 set of source files. For file formats where it is not possible to infer which 7 set of source files. For file formats where it is not possible to infer which
8 strings represent message identifiers, localized strings should be explicitly 8 strings represent message identifiers, localized strings should be explicitly
9 annotated with the string "i18n-content", for example: 9 annotated with the string "i18n-content", for example:
10 10
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 # Jinja2 template file 86 # Jinja2 template file
87 m = re.search('\{\%\s+trans\s+\%\}([A-Z0-9_]+)\{\%\s+endtrans\s+\%\}', line) 87 m = re.search('\{\%\s+trans\s+\%\}([A-Z0-9_]+)\{\%\s+endtrans\s+\%\}', line)
88 if m: return m.group(1) 88 if m: return m.group(1)
89 return None 89 return None
90 90
91 91
92 def VerifyFile(filename, messages, used_tags): 92 def VerifyFile(filename, messages, used_tags):
93 """ 93 """
94 Parse |filename|, looking for tags and report any that are not included in 94 Parse |filename|, looking for tags and report any that are not included in
95 |messages|. Return True if all tags are present and correct, or False if 95 |messages|. Return True if all tags are present and correct, or False if
96 any are missing. If no tags are found, print a warning message and return 96 any are missing.
97 True.
98 """ 97 """
99 98
100 base_name, file_type = os.path.splitext(filename) 99 base_name, file_type = os.path.splitext(filename)
101 file_type = file_type[1:] 100 file_type = file_type[1:]
102 if file_type == 'jinja2' and base_name.endswith('.json'): 101 if file_type == 'jinja2' and base_name.endswith('.json'):
103 file_type = 'json.jinja2' 102 file_type = 'json.jinja2'
104 if file_type not in ['js', 'cc', 'html', 'json.jinja2', 'jinja2', 'mm']: 103 if file_type not in ['js', 'cc', 'html', 'json.jinja2', 'jinja2', 'mm']:
105 raise Exception("Unknown file type: %s" % file_type) 104 raise Exception("Unknown file type: %s" % file_type)
106 105
107 result = True 106 result = True
108 matches = False 107 matches = False
109 f = open(filename, 'r') 108 f = open(filename, 'r')
110 lines = f.readlines() 109 lines = f.readlines()
111 for i in xrange(0, len(lines)): 110 for i in xrange(0, len(lines)):
112 tag = ExtractTagFromLine(file_type, lines[i]) 111 tag = ExtractTagFromLine(file_type, lines[i])
113 if tag: 112 if tag:
114 tag = tag.upper() 113 tag = tag.upper()
115 used_tags.add(tag) 114 used_tags.add(tag)
116 matches = True 115 matches = True
117 if not tag in messages: 116 if not tag in messages:
118 result = False 117 result = False
119 print '%s/%s:%d: error: Undefined tag: %s' % \ 118 print '%s/%s:%d: error: Undefined tag: %s' % \
120 (os.getcwd(), filename, i + 1, tag) 119 (os.getcwd(), filename, i + 1, tag)
121 if not matches:
122 print '%s/%s:0: warning: No tags found' % (os.getcwd(), filename)
123 f.close() 120 f.close()
124 return result 121 return result
125 122
126 123
127 def main(): 124 def main():
128 parser = optparse.OptionParser( 125 parser = optparse.OptionParser(
129 usage='Usage: %prog [options...] [source_file...]') 126 usage='Usage: %prog [options...] [source_file...]')
130 parser.add_option('-t', '--touch', dest='touch', 127 parser.add_option('-t', '--touch', dest='touch',
131 help='File to touch when finished.') 128 help='File to touch when finished.')
132 parser.add_option('-r', '--grd', dest='grd', action='append', 129 parser.add_option('-r', '--grd', dest='grd', action='append',
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 if exit_code == 0: 165 if exit_code == 0:
169 f = open(options.touch, 'a') 166 f = open(options.touch, 'a')
170 f.close() 167 f.close()
171 os.utime(options.touch, None) 168 os.utime(options.touch, None)
172 169
173 return exit_code 170 return exit_code
174 171
175 172
176 if __name__ == '__main__': 173 if __name__ == '__main__':
177 sys.exit(main()) 174 sys.exit(main())
OLDNEW
« no previous file with comments | « remoting/remoting.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698