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

Side by Side Diff: tools/grit/grit/grd_reader.py

Issue 6760030: Print a grit debugging hint to stdout when a parse exception occurs (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Updated copyright year. Created 9 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | 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/python2.4 1 #!/usr/bin/python2.4
2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2011 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 '''Class for reading GRD files into memory, without processing them. 6 '''Class for reading GRD files into memory, without processing them.
7 ''' 7 '''
8 8
9 import os.path 9 import os.path
10 import types 10 import types
11 import xml.sax 11 import xml.sax
12 import xml.sax.handler 12 import xml.sax.handler
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 grit.exception.Parsing 127 grit.exception.Parsing
128 ''' 128 '''
129 handler = GrdContentHandler(stop_after=stop_after, debug=debug, 129 handler = GrdContentHandler(stop_after=stop_after, debug=debug,
130 defines=defines) 130 defines=defines)
131 try: 131 try:
132 xml.sax.parse(filename_or_stream, handler) 132 xml.sax.parse(filename_or_stream, handler)
133 except StopParsingException: 133 except StopParsingException:
134 assert stop_after 134 assert stop_after
135 pass 135 pass
136 except: 136 except:
137 if not debug:
138 print "parse exception: run GRIT with the -x flag to debug .grd problems"
137 raise 139 raise
138 140
139 if not flexible_root or hasattr(handler.root, 'SetOwnDir'): 141 if not flexible_root or hasattr(handler.root, 'SetOwnDir'):
140 assert isinstance(filename_or_stream, types.StringType) or dir != None 142 assert isinstance(filename_or_stream, types.StringType) or dir != None
141 if not dir: 143 if not dir:
142 dir = util.dirname(filename_or_stream) 144 dir = util.dirname(filename_or_stream)
143 if len(dir) == 0: 145 if len(dir) == 0:
144 dir = '.' 146 dir = '.'
145 # Fix up the base_dir so it is relative to the input file. 147 # Fix up the base_dir so it is relative to the input file.
146 handler.root.SetOwnDir(dir) 148 handler.root.SetOwnDir(dir)
147 149
148 # Assign first ids to the nodes that don't have them. 150 # Assign first ids to the nodes that don't have them.
149 if isinstance(handler.root, misc.GritNode) and first_id_filename != '': 151 if isinstance(handler.root, misc.GritNode) and first_id_filename != '':
150 handler.root.AssignFirstIds(filename_or_stream, first_id_filename, defines) 152 handler.root.AssignFirstIds(filename_or_stream, first_id_filename, defines)
151 153
152 return handler.root 154 return handler.root
153 155
154 156
155 if __name__ == '__main__': 157 if __name__ == '__main__':
156 util.ChangeStdoutEncoding() 158 util.ChangeStdoutEncoding()
157 print unicode(Parse(sys.argv[1])) 159 print unicode(Parse(sys.argv[1]))
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698