main.py (5824:b88edb9f3333) main.py (5873:67a6ea624776)
1# Copyright (c) 2005 The Regents of The University of Michigan
2# All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions are
6# met: redistributions of source code must retain the above copyright
7# notice, this list of conditions and the following disclaimer;
8# redistributions in binary form must reproduce the above copyright
9# notice, this list of conditions and the following disclaimer in the
10# documentation and/or other materials provided with the distribution;
11# neither the name of the copyright holders nor the names of its
12# contributors may be used to endorse or promote products derived from
13# this software without specific prior written permission.
14#
15# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26#
27# Authors: Nathan Binkert
28
29import code
30import datetime
31import os
32import socket
33import sys
34
35from util import attrdict
36import config
37from options import OptionParser
38
39__all__ = [ 'options', 'arguments', 'main' ]
40
1# Copyright (c) 2005 The Regents of The University of Michigan
2# All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions are
6# met: redistributions of source code must retain the above copyright
7# notice, this list of conditions and the following disclaimer;
8# redistributions in binary form must reproduce the above copyright
9# notice, this list of conditions and the following disclaimer in the
10# documentation and/or other materials provided with the distribution;
11# neither the name of the copyright holders nor the names of its
12# contributors may be used to endorse or promote products derived from
13# this software without specific prior written permission.
14#
15# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26#
27# Authors: Nathan Binkert
28
29import code
30import datetime
31import os
32import socket
33import sys
34
35from util import attrdict
36import config
37from options import OptionParser
38
39__all__ = [ 'options', 'arguments', 'main' ]
40
41def print_list(items, indent=4):
42 line = ' ' * indent
43 for i,item in enumerate(items):
44 if len(line) + len(item) > 76:
45 print line
46 line = ' ' * indent
47
48 if i < len(items) - 1:
49 line += '%s, ' % item
50 else:
51 line += item
52 print line
53
54usage="%prog [m5 options] script.py [script options]"
55version="%prog 2.0"
56brief_copyright='''
57Copyright (c) 2001-2008
58The Regents of The University of Michigan
59All Rights Reserved
60'''
61
62options = OptionParser(usage=usage, version=version,
63 description=brief_copyright)
64add_option = options.add_option
65set_group = options.set_group
66usage = options.usage
67
68# Help options
69add_option('-A', "--authors", action="store_true", default=False,
70 help="Show author information")
71add_option('-B', "--build-info", action="store_true", default=False,
72 help="Show build information")
73add_option('-C', "--copyright", action="store_true", default=False,
74 help="Show full copyright information")
75add_option('-R', "--readme", action="store_true", default=False,
76 help="Show the readme")
77add_option('-N', "--release-notes", action="store_true", default=False,
78 help="Show the release notes")
79
80# Options for configuring the base simulator
81add_option('-d', "--outdir", metavar="DIR", default="m5out",
82 help="Set the output directory to DIR [Default: %default]")
83add_option('-r', "--redirect-stdout", action="store_true", default=False,
84 help="Redirect stdout (& stderr, without -e) to file")
85add_option('-e', "--redirect-stderr", action="store_true", default=False,
86 help="Redirect stderr to file")
87add_option("--stdout-file", metavar="FILE", default="simout",
88 help="Filename for -r redirection [Default: %default]")
89add_option("--stderr-file", metavar="FILE", default="simerr",
90 help="Filename for -e redirection [Default: %default]")
91add_option('-i', "--interactive", action="store_true", default=False,
92 help="Invoke the interactive interpreter after running the script")
93add_option("--pdb", action="store_true", default=False,
94 help="Invoke the python debugger before running the script")
95add_option('-p', "--path", metavar="PATH[:PATH]", action='append', split=':',
96 help="Prepend PATH to the system path when invoking the script")
97add_option('-q', "--quiet", action="count", default=0,
98 help="Reduce verbosity")
99add_option('-v', "--verbose", action="count", default=0,
100 help="Increase verbosity")
101
102# Statistics options
103set_group("Statistics Options")
104add_option("--stats-file", metavar="FILE", default="stats.txt",
105 help="Sets the output file for statistics [Default: %default]")
106
107# Configuration Options
108set_group("Configuration Options")
109add_option("--dump-config", metavar="FILE", default="config.ini",
110 help="Dump configuration output file [Default: %default]")
111
112# Debugging options
113set_group("Debugging Options")
114add_option("--debug-break", metavar="TIME[,TIME]", action='append', split=',',
115 help="Cycle to create a breakpoint")
116add_option("--remote-gdb-port", type='int', default=7000,
117 help="Remote gdb base port")
118
119# Tracing options
120set_group("Trace Options")
121add_option("--trace-help", action='store_true',
122 help="Print help on trace flags")
123add_option("--trace-flags", metavar="FLAG[,FLAG]", action='append', split=',',
124 help="Sets the flags for tracing (-FLAG disables a flag)")
125add_option("--trace-start", metavar="TIME", type='int',
126 help="Start tracing at TIME (must be in ticks)")
127add_option("--trace-file", metavar="FILE", default="cout",
128 help="Sets the output file for tracing [Default: %default]")
129add_option("--trace-ignore", metavar="EXPR", action='append', split=':',
130 help="Ignore EXPR sim objects")
131
132# Help options
133set_group("Help Options")
134add_option("--list-sim-objects", action='store_true', default=False,
135 help="List all built-in SimObjects, their parameters and default values")
136
137def main():
138 import core
139 import debug
140 import defines
141 import event
142 import info
143 import stats
144 import trace
145
146 def check_tracing():
147 if defines.TRACING_ON:
148 return
149
150 fatal("Tracing is not enabled. Compile with TRACING_ON")
151
152 # load the options.py config file to allow people to set their own
153 # default options
154 options_file = config.get('options.py')
155 if options_file:
156 scope = { 'options' : options }
157 execfile(options_file, scope)
158
159 arguments = options.parse_args()
160
161 if not os.path.isdir(options.outdir):
162 os.makedirs(options.outdir)
163
164 # These filenames are used only if the redirect_std* options are set
165 stdout_file = os.path.join(options.outdir, options.stdout_file)
166 stderr_file = os.path.join(options.outdir, options.stderr_file)
167
168 # Print redirection notices here before doing any redirection
169 if options.redirect_stdout and not options.redirect_stderr:
170 print "Redirecting stdout and stderr to", stdout_file
171 else:
172 if options.redirect_stdout:
173 print "Redirecting stdout to", stdout_file
174 if options.redirect_stderr:
175 print "Redirecting stderr to", stderr_file
176
177 # Now redirect stdout/stderr as desired
178 if options.redirect_stdout:
179 redir_fd = os.open(stdout_file, os. O_WRONLY | os.O_CREAT | os.O_TRUNC)
180 os.dup2(redir_fd, sys.stdout.fileno())
181 if not options.redirect_stderr:
182 os.dup2(redir_fd, sys.stderr.fileno())
183
184 if options.redirect_stderr:
185 redir_fd = os.open(stderr_file, os. O_WRONLY | os.O_CREAT | os.O_TRUNC)
186 os.dup2(redir_fd, sys.stderr.fileno())
187
188 done = False
189
190 if options.build_info:
191 done = True
192 print 'Build information:'
193 print
194 print 'compiled %s' % defines.compileDate;
195 print "revision %s" % defines.hgRev
196 print 'build options:'
197 keys = defines.buildEnv.keys()
198 keys.sort()
199 for key in keys:
200 val = defines.buildEnv[key]
201 print ' %s = %s' % (key, val)
202 print
203
204 if options.copyright:
205 done = True
206 print info.LICENSE
207 print
208
209 if options.authors:
210 done = True
211 print 'Author information:'
212 print
213 print info.AUTHORS
214 print
215
216 if options.readme:
217 done = True
218 print 'Readme:'
219 print
220 print info.README
221 print
222
223 if options.release_notes:
224 done = True
225 print 'Release Notes:'
226 print
227 print info.RELEASE_NOTES
228 print
229
230 if options.trace_help:
231 done = True
232 check_tracing()
233 trace.help()
234
235 if options.list_sim_objects:
236 import SimObject
237 done = True
238 print "SimObjects:"
239 objects = SimObject.allClasses.keys()
240 objects.sort()
241 for name in objects:
242 obj = SimObject.allClasses[name]
243 print " %s" % obj
244 params = obj._params.keys()
245 params.sort()
246 for pname in params:
247 param = obj._params[pname]
248 default = getattr(param, 'default', '')
249 print " %s" % pname
250 if default:
251 print " default: %s" % default
252 print " desc: %s" % param.desc
253 print
254 print
255
256 if done:
257 sys.exit(0)
258
259 # setting verbose and quiet at the same time doesn't make sense
260 if options.verbose > 0 and options.quiet > 0:
261 options.usage(2)
262
263 verbose = options.verbose - options.quiet
264 if options.verbose >= 0:
265 print "M5 Simulator System"
266 print brief_copyright
267 print
268
269 print "M5 compiled %s" % defines.compileDate;
270 print "M5 revision %s" % defines.hgRev
271
272 print "M5 started %s" % datetime.datetime.now().strftime("%b %e %Y %X")
273 print "M5 executing on %s" % socket.gethostname()
274
275 print "command line:",
276 for argv in sys.argv:
277 print argv,
278 print
279
280 # check to make sure we can find the listed script
281 if not arguments or not os.path.isfile(arguments[0]):
282 if arguments and not os.path.isfile(arguments[0]):
283 print "Script %s not found" % arguments[0]
284
285 options.usage(2)
286
287 # tell C++ about output directory
288 core.setOutputDir(options.outdir)
289
290 # update the system path with elements from the -p option
291 sys.path[0:0] = options.path
292
293 # set stats options
294 stats.initText(options.stats_file)
295
296 # set debugging options
297 debug.setRemoteGDBPort(options.remote_gdb_port)
298 for when in options.debug_break:
299 debug.schedBreakCycle(int(when))
300
301 if options.trace_flags:
302 check_tracing()
303
304 on_flags = []
305 off_flags = []
306 for flag in options.trace_flags:
307 off = False
308 if flag.startswith('-'):
309 flag = flag[1:]
310 off = True
311 if flag not in trace.flags.all and flag != "All":
312 print >>sys.stderr, "invalid trace flag '%s'" % flag
313 sys.exit(1)
314
315 if off:
316 off_flags.append(flag)
317 else:
318 on_flags.append(flag)
319
320 for flag in on_flags:
321 trace.set(flag)
322
323 for flag in off_flags:
324 trace.clear(flag)
325
326 if options.trace_start:
327 check_tracing()
328 e = event.create(trace.enable)
329 event.mainq.schedule(e, options.trace_start)
330 else:
331 trace.enable()
332
333 trace.output(options.trace_file)
334
335 for ignore in options.trace_ignore:
336 check_tracing()
337 trace.ignore(ignore)
338
339 sys.argv = arguments
340 sys.path = [ os.path.dirname(sys.argv[0]) ] + sys.path
341
342 filename = sys.argv[0]
343 filedata = file(filename, 'r').read()
344 filecode = compile(filedata, filename, 'exec')
345 scope = { '__file__' : filename,
346 '__name__' : '__m5_main__' }
347
348 # we want readline if we're doing anything interactive
349 if options.interactive or options.pdb:
350 exec "import readline" in scope
351
352 # if pdb was requested, execfile the thing under pdb, otherwise,
353 # just do the execfile normally
354 if options.pdb:
355 import pdb
356 import traceback
357
358 pdb = pdb.Pdb()
359 try:
360 pdb.run(filecode, scope)
361 except SystemExit:
362 print "The program exited via sys.exit(). Exit status: ",
363 print sys.exc_info()[1]
364 except:
365 traceback.print_exc()
366 print "Uncaught exception. Entering post mortem debugging"
367 t = sys.exc_info()[2]
368 while t.tb_next is not None:
369 t = t.tb_next
370 pdb.interaction(t.tb_frame,t)
371 else:
372 exec filecode in scope
373
374 # once the script is done
375 if options.interactive:
376 interact = code.InteractiveConsole(scope)
377 interact.interact("M5 Interactive Console")
378
379if __name__ == '__main__':
380 from pprint import pprint
381
382 # load the options.py config file to allow people to set their own
383 # default options
384 options_file = config.get('options.py')
385 if options_file:
386 scope = { 'options' : options }
387 execfile(options_file, scope)
388
389 arguments = options.parse_args()
390
391 print 'opts:'
392 pprint(options, indent=4)
393 print
394
395 print 'args:'
396 pprint(arguments, indent=4)
41usage="%prog [m5 options] script.py [script options]"
42version="%prog 2.0"
43brief_copyright='''
44Copyright (c) 2001-2008
45The Regents of The University of Michigan
46All Rights Reserved
47'''
48
49options = OptionParser(usage=usage, version=version,
50 description=brief_copyright)
51add_option = options.add_option
52set_group = options.set_group
53usage = options.usage
54
55# Help options
56add_option('-A', "--authors", action="store_true", default=False,
57 help="Show author information")
58add_option('-B', "--build-info", action="store_true", default=False,
59 help="Show build information")
60add_option('-C', "--copyright", action="store_true", default=False,
61 help="Show full copyright information")
62add_option('-R', "--readme", action="store_true", default=False,
63 help="Show the readme")
64add_option('-N', "--release-notes", action="store_true", default=False,
65 help="Show the release notes")
66
67# Options for configuring the base simulator
68add_option('-d', "--outdir", metavar="DIR", default="m5out",
69 help="Set the output directory to DIR [Default: %default]")
70add_option('-r', "--redirect-stdout", action="store_true", default=False,
71 help="Redirect stdout (& stderr, without -e) to file")
72add_option('-e', "--redirect-stderr", action="store_true", default=False,
73 help="Redirect stderr to file")
74add_option("--stdout-file", metavar="FILE", default="simout",
75 help="Filename for -r redirection [Default: %default]")
76add_option("--stderr-file", metavar="FILE", default="simerr",
77 help="Filename for -e redirection [Default: %default]")
78add_option('-i', "--interactive", action="store_true", default=False,
79 help="Invoke the interactive interpreter after running the script")
80add_option("--pdb", action="store_true", default=False,
81 help="Invoke the python debugger before running the script")
82add_option('-p', "--path", metavar="PATH[:PATH]", action='append', split=':',
83 help="Prepend PATH to the system path when invoking the script")
84add_option('-q', "--quiet", action="count", default=0,
85 help="Reduce verbosity")
86add_option('-v', "--verbose", action="count", default=0,
87 help="Increase verbosity")
88
89# Statistics options
90set_group("Statistics Options")
91add_option("--stats-file", metavar="FILE", default="stats.txt",
92 help="Sets the output file for statistics [Default: %default]")
93
94# Configuration Options
95set_group("Configuration Options")
96add_option("--dump-config", metavar="FILE", default="config.ini",
97 help="Dump configuration output file [Default: %default]")
98
99# Debugging options
100set_group("Debugging Options")
101add_option("--debug-break", metavar="TIME[,TIME]", action='append', split=',',
102 help="Cycle to create a breakpoint")
103add_option("--remote-gdb-port", type='int', default=7000,
104 help="Remote gdb base port")
105
106# Tracing options
107set_group("Trace Options")
108add_option("--trace-help", action='store_true',
109 help="Print help on trace flags")
110add_option("--trace-flags", metavar="FLAG[,FLAG]", action='append', split=',',
111 help="Sets the flags for tracing (-FLAG disables a flag)")
112add_option("--trace-start", metavar="TIME", type='int',
113 help="Start tracing at TIME (must be in ticks)")
114add_option("--trace-file", metavar="FILE", default="cout",
115 help="Sets the output file for tracing [Default: %default]")
116add_option("--trace-ignore", metavar="EXPR", action='append', split=':',
117 help="Ignore EXPR sim objects")
118
119# Help options
120set_group("Help Options")
121add_option("--list-sim-objects", action='store_true', default=False,
122 help="List all built-in SimObjects, their parameters and default values")
123
124def main():
125 import core
126 import debug
127 import defines
128 import event
129 import info
130 import stats
131 import trace
132
133 def check_tracing():
134 if defines.TRACING_ON:
135 return
136
137 fatal("Tracing is not enabled. Compile with TRACING_ON")
138
139 # load the options.py config file to allow people to set their own
140 # default options
141 options_file = config.get('options.py')
142 if options_file:
143 scope = { 'options' : options }
144 execfile(options_file, scope)
145
146 arguments = options.parse_args()
147
148 if not os.path.isdir(options.outdir):
149 os.makedirs(options.outdir)
150
151 # These filenames are used only if the redirect_std* options are set
152 stdout_file = os.path.join(options.outdir, options.stdout_file)
153 stderr_file = os.path.join(options.outdir, options.stderr_file)
154
155 # Print redirection notices here before doing any redirection
156 if options.redirect_stdout and not options.redirect_stderr:
157 print "Redirecting stdout and stderr to", stdout_file
158 else:
159 if options.redirect_stdout:
160 print "Redirecting stdout to", stdout_file
161 if options.redirect_stderr:
162 print "Redirecting stderr to", stderr_file
163
164 # Now redirect stdout/stderr as desired
165 if options.redirect_stdout:
166 redir_fd = os.open(stdout_file, os. O_WRONLY | os.O_CREAT | os.O_TRUNC)
167 os.dup2(redir_fd, sys.stdout.fileno())
168 if not options.redirect_stderr:
169 os.dup2(redir_fd, sys.stderr.fileno())
170
171 if options.redirect_stderr:
172 redir_fd = os.open(stderr_file, os. O_WRONLY | os.O_CREAT | os.O_TRUNC)
173 os.dup2(redir_fd, sys.stderr.fileno())
174
175 done = False
176
177 if options.build_info:
178 done = True
179 print 'Build information:'
180 print
181 print 'compiled %s' % defines.compileDate;
182 print "revision %s" % defines.hgRev
183 print 'build options:'
184 keys = defines.buildEnv.keys()
185 keys.sort()
186 for key in keys:
187 val = defines.buildEnv[key]
188 print ' %s = %s' % (key, val)
189 print
190
191 if options.copyright:
192 done = True
193 print info.LICENSE
194 print
195
196 if options.authors:
197 done = True
198 print 'Author information:'
199 print
200 print info.AUTHORS
201 print
202
203 if options.readme:
204 done = True
205 print 'Readme:'
206 print
207 print info.README
208 print
209
210 if options.release_notes:
211 done = True
212 print 'Release Notes:'
213 print
214 print info.RELEASE_NOTES
215 print
216
217 if options.trace_help:
218 done = True
219 check_tracing()
220 trace.help()
221
222 if options.list_sim_objects:
223 import SimObject
224 done = True
225 print "SimObjects:"
226 objects = SimObject.allClasses.keys()
227 objects.sort()
228 for name in objects:
229 obj = SimObject.allClasses[name]
230 print " %s" % obj
231 params = obj._params.keys()
232 params.sort()
233 for pname in params:
234 param = obj._params[pname]
235 default = getattr(param, 'default', '')
236 print " %s" % pname
237 if default:
238 print " default: %s" % default
239 print " desc: %s" % param.desc
240 print
241 print
242
243 if done:
244 sys.exit(0)
245
246 # setting verbose and quiet at the same time doesn't make sense
247 if options.verbose > 0 and options.quiet > 0:
248 options.usage(2)
249
250 verbose = options.verbose - options.quiet
251 if options.verbose >= 0:
252 print "M5 Simulator System"
253 print brief_copyright
254 print
255
256 print "M5 compiled %s" % defines.compileDate;
257 print "M5 revision %s" % defines.hgRev
258
259 print "M5 started %s" % datetime.datetime.now().strftime("%b %e %Y %X")
260 print "M5 executing on %s" % socket.gethostname()
261
262 print "command line:",
263 for argv in sys.argv:
264 print argv,
265 print
266
267 # check to make sure we can find the listed script
268 if not arguments or not os.path.isfile(arguments[0]):
269 if arguments and not os.path.isfile(arguments[0]):
270 print "Script %s not found" % arguments[0]
271
272 options.usage(2)
273
274 # tell C++ about output directory
275 core.setOutputDir(options.outdir)
276
277 # update the system path with elements from the -p option
278 sys.path[0:0] = options.path
279
280 # set stats options
281 stats.initText(options.stats_file)
282
283 # set debugging options
284 debug.setRemoteGDBPort(options.remote_gdb_port)
285 for when in options.debug_break:
286 debug.schedBreakCycle(int(when))
287
288 if options.trace_flags:
289 check_tracing()
290
291 on_flags = []
292 off_flags = []
293 for flag in options.trace_flags:
294 off = False
295 if flag.startswith('-'):
296 flag = flag[1:]
297 off = True
298 if flag not in trace.flags.all and flag != "All":
299 print >>sys.stderr, "invalid trace flag '%s'" % flag
300 sys.exit(1)
301
302 if off:
303 off_flags.append(flag)
304 else:
305 on_flags.append(flag)
306
307 for flag in on_flags:
308 trace.set(flag)
309
310 for flag in off_flags:
311 trace.clear(flag)
312
313 if options.trace_start:
314 check_tracing()
315 e = event.create(trace.enable)
316 event.mainq.schedule(e, options.trace_start)
317 else:
318 trace.enable()
319
320 trace.output(options.trace_file)
321
322 for ignore in options.trace_ignore:
323 check_tracing()
324 trace.ignore(ignore)
325
326 sys.argv = arguments
327 sys.path = [ os.path.dirname(sys.argv[0]) ] + sys.path
328
329 filename = sys.argv[0]
330 filedata = file(filename, 'r').read()
331 filecode = compile(filedata, filename, 'exec')
332 scope = { '__file__' : filename,
333 '__name__' : '__m5_main__' }
334
335 # we want readline if we're doing anything interactive
336 if options.interactive or options.pdb:
337 exec "import readline" in scope
338
339 # if pdb was requested, execfile the thing under pdb, otherwise,
340 # just do the execfile normally
341 if options.pdb:
342 import pdb
343 import traceback
344
345 pdb = pdb.Pdb()
346 try:
347 pdb.run(filecode, scope)
348 except SystemExit:
349 print "The program exited via sys.exit(). Exit status: ",
350 print sys.exc_info()[1]
351 except:
352 traceback.print_exc()
353 print "Uncaught exception. Entering post mortem debugging"
354 t = sys.exc_info()[2]
355 while t.tb_next is not None:
356 t = t.tb_next
357 pdb.interaction(t.tb_frame,t)
358 else:
359 exec filecode in scope
360
361 # once the script is done
362 if options.interactive:
363 interact = code.InteractiveConsole(scope)
364 interact.interact("M5 Interactive Console")
365
366if __name__ == '__main__':
367 from pprint import pprint
368
369 # load the options.py config file to allow people to set their own
370 # default options
371 options_file = config.get('options.py')
372 if options_file:
373 scope = { 'options' : options }
374 execfile(options_file, scope)
375
376 arguments = options.parse_args()
377
378 print 'opts:'
379 pprint(options, indent=4)
380 print
381
382 print 'args:'
383 pprint(arguments, indent=4)