1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 """The main module for relax execution."""
26
27
28 import dep_check
29
30
31 import os
32 if 'TERM' in os.environ and os.environ['TERM'] == 'xterm':
33 os.environ['TERM'] = 'linux'
34
35
36 import lib.compat
37
38
39 import numpy
40 from optparse import Option, OptionGroup, OptionParser
41 from os import F_OK, access, getpid, putenv
42 if dep_check.cprofile_module:
43 import cProfile as profile
44 elif dep_check.profile_module:
45 import profile
46 import pstats
47 from pydoc import pager
48 import sys
49
50
51 from info import Info_box
52 import lib.errors
53 from lib.io import io_streams_log, io_streams_tee
54 import lib.warnings
55 from multi import Application_callback, load_multiprocessor
56 from prompt import interpreter
57 from status import Status; status = Status()
58 import user_functions
59 import version
60
61
62
63 user_functions.initialise()
64
65
66 putenv('PDBVIEWER', 'vmd')
67
68
69 -def start(mode=None, profile_flag=False):
121
122
123 if not dep_check.profile_module:
124 sys.stderr.write("The profile module is not available, please install the Python development packages for profiling.\n\n")
125 sys.exit()
126
127
128 profile.Profile.print_stats = print_stats
129 profile.runctx('processor.run()', globals(), locals())
130
131
132
134 """The main relax class.
135
136 This contains information about the running state, for example the mode of operation of relax,
137 whether debugging is turned on, etc.
138 """
139
141 """The top level class for initialising the program.
142
143 @keyword mode: Force a relax mode, overriding the command line.
144 @type mode: str
145 """
146
147
148 self.pid = getpid()
149
150
151 self.exit_code = 0
152
276
277
279 """Process the command line arguments."""
280
281
282 parser = RelaxParser(self, usage="usage: %prog [options] [script_file]")
283
284
285 group = OptionGroup(parser, 'UI options')
286 group.add_option('-p', '--prompt', action='store_true', dest='prompt', default=0, help='launch relax in prompt mode after running any optionally supplied scripts')
287 group.add_option('-g', '--gui', action='store_true', dest='gui', default=0, help='launch the relax GUI')
288 group.add_option('-i', '--info', action='store_true', dest='info', default=0, help='display information about this version of relax')
289 group.add_option('-v', '--version', action='store_true', dest='version', default=0, help='show the version number and exit')
290 group.add_option('--licence', action='store_true', dest='licence', default=0, help='display the licence')
291 group.add_option('--test', action='store_true', dest='test', default=0, help='run relax in test mode')
292 parser.add_option_group(group)
293
294
295 group = OptionGroup(parser, 'Multi-processor options')
296 group.add_option('-m', '--multi', action='store', type='string', dest='multiprocessor', default='uni', help='set multi processor method')
297 group.add_option('-n', '--processors', action='store', type='int', dest='n_processors', default=-1, help='set number of processors (may be ignored)')
298 parser.add_option_group(group)
299
300
301 group = OptionGroup(parser, 'IO redirection options')
302 group.add_option('-l', '--log', action='store', type='string', dest='log', help='log relax output to the file LOG_FILE', metavar='LOG_FILE')
303 group.add_option('-t', '--tee', action='store', type='string', dest='tee', help='tee relax output to both stdout and the file LOG_FILE', metavar='LOG_FILE')
304 parser.add_option_group(group)
305
306
307 group = OptionGroup(parser, 'Test suite options')
308 group.add_option('-x', '--test-suite', action='store_true', dest='test_suite', default=0, help='execute the full relax test suite')
309 group.add_option('-s', '--system-tests', action='store_true', dest='system_tests', default=0, help='execute the system/functional tests. Test names, revealed with the --time option, can be supplied to perform a subset of all tests.')
310 group.add_option('-u', '--unit-tests', action='store_true', dest='unit_tests', default=0, help='execute the unit tests. Module names, revealed with the --time option, can be supplied to perform a subset of all tests.')
311 group.add_option('--gui-tests', action='store_true', dest='gui_tests', default=0, help='execute the GUI tests. Test names, revealed with the --time option, can be supplied to perform a subset of all tests.')
312 group.add_option('--verification-tests', action='store_true', dest='verification_tests', default=0, help='execute the software verification tests. Test names, revealed with the --time option, can be supplied to perform a subset of all tests.')
313 group.add_option('--time', action='store_true', dest='tt', default=0, help='print out the timings of individual tests in the test suite')
314 group.add_option('--no-skip', action='store_true', dest='no_skip', default=0, help='a debugging option for relax developers to turn on all blacklisted tests, even those that will fail')
315 parser.add_option_group(group)
316
317
318 group = OptionGroup(parser, 'Debugging options')
319 group.add_option('-d', '--debug', action='store_true', dest='debug', default=0, help='enable debugging output')
320 group.add_option('--error-state', action='store_true', dest='error_state', default=0, help='save a pickled state file when a RelaxError occurs')
321 group.add_option('--traceback', action='store_true', dest='traceback', default=0, help='show stack tracebacks on all RelaxErrors and RelaxWarnings')
322 group.add_option('-e', '--escalate', action='store_true', dest='escalate', default=0, help='escalate all warnings to errors')
323 group.add_option('--numpy-raise', action='store_true', dest='numpy_raise', default=0, help='convert numpy warnings to errors')
324 parser.add_option_group(group)
325
326
327 (options, args) = parser.parse_args()
328
329
330 if options.debug:
331 status.debug = True
332 if options.escalate:
333 lib.warnings.ESCALATE = True
334 if options.traceback:
335 status.traceback = True
336 lib.warnings.TRACEBACK = True
337 if options.numpy_raise:
338 numpy.seterr(all='raise')
339 if options.error_state:
340 lib.errors.SAVE_ERROR_STATE = True
341
342
343 if options.prompt:
344 status.prompt = True
345
346
347 if options.log:
348
349 if options.tee:
350 parser.error("the logging and tee options cannot be set simultaneously")
351
352
353 self.log_file = options.log
354
355
356 if access(self.log_file, F_OK):
357 parser.error("the log file " + repr(self.log_file) + " already exists")
358 else:
359 self.log_file = None
360
361
362 if options.tee:
363
364 if options.log:
365 parser.error("the tee and logging options cannot be set simultaneously")
366
367
368 self.tee_file = options.tee
369
370
371 if access(self.tee_file, F_OK):
372 parser.error("the tee file " + repr(self.tee_file) + " already exists")
373 else:
374 self.tee_file = None
375
376
377 if options.test_suite or options.system_tests or options.unit_tests or options.gui_tests or options.verification_tests:
378
379 self.tests = args
380
381
382 self.test_timings = False
383 if options.tt:
384 self.test_timings = True
385
386
387 status.skip_blacklisted_tests = True
388 if options.no_skip:
389 status.skip_blacklisted_tests = False
390
391
392 else:
393
394 if len(args) > 1:
395 parser.error("incorrect number of arguments")
396
397
398 self.script_file = None
399 if len(args) == 1:
400 self.script_file = args[0]
401
402
403 if not access(self.script_file, F_OK):
404 parser.error("the script file " + repr(self.script_file) + " does not exist")
405
406
407 self.multiprocessor_type = options.multiprocessor
408 self.n_processors = options.n_processors
409
410
411 if self.multiprocessor_type == 'mpi4py' and not dep_check.mpi4py_module:
412 parser.error(dep_check.mpi4py_message)
413
414
415
416
417
418
419 if options.version:
420 self.mode = 'version'
421
422
423 elif options.info:
424 self.mode = 'info'
425
426
427 elif options.test_suite or options.system_tests or options.unit_tests or options.gui_tests or options.verification_tests:
428
429 if options.test:
430 parser.error("executing the relax test suite and running relax in test mode are mutually exclusive")
431 elif options.licence:
432 parser.error("executing the relax test suite and running relax in licence mode are mutually exclusive")
433
434
435 if options.test_suite:
436 self.mode = 'test suite'
437 elif options.system_tests:
438 self.mode = 'system tests'
439 elif options.unit_tests:
440 self.mode = 'unit tests'
441 elif options.gui_tests:
442 self.mode = 'GUI tests'
443 elif options.verification_tests:
444 self.mode = 'verification tests'
445
446
447 status.test_mode = True
448
449
450 elif options.test:
451
452 if self.script_file:
453 parser.error("a script should not be supplied in test mode")
454
455
456 if options.test_suite or options.system_tests or options.unit_tests or options.gui_tests or options.verification_tests:
457 parser.error("the relax test mode and executing the test suite are mutually exclusive")
458 elif options.licence:
459 parser.error("the relax modes test and licence are mutually exclusive")
460
461
462 self.mode = 'test'
463
464
465 elif options.licence:
466
467 if self.script_file:
468 parser.error("a script should not be supplied in test mode")
469
470
471 if options.test_suite or options.system_tests or options.unit_tests or options.gui_tests or options.verification_tests:
472 parser.error("the relax licence mode and executing the test suite are mutually exclusive")
473 elif options.test:
474 parser.error("the relax modes licence and test are mutually exclusive")
475
476
477 self.mode = 'licence'
478
479
480 elif options.gui:
481
482 if options.test_suite or options.system_tests or options.unit_tests or options.gui_tests or options.verification_tests:
483 parser.error("the relax GUI mode and testing modes are mutually exclusive")
484 elif options.licence:
485 parser.error("the relax GUI mode and licence mode are mutually exclusive")
486
487
488 if not dep_check.wx_module:
489
490 if dep_check.wx_module_message == "No module named 'wx'":
491 parser.error("To use the GUI, the wxPython module must be installed.")
492
493
494 else:
495 parser.error("The wxPython installation is broken:\n%s." % dep_check.wx_module_message)
496
497
498 self.mode = 'gui'
499
500
501 elif self.script_file:
502 self.mode = 'script'
503
504
505 else:
506 self.mode = 'prompt'
507
508
510 """Function for displaying the licence."""
511
512
513 file = open('docs/COPYING')
514 pager(file.read())
515
516
518 """Relax test mode code."""
519
520
521 return
522
523
524
526 - def __init__(self, relax, usage=None, option_list=None, option_class=Option, version=None, conflict_handler="error", description=None, formatter=None, add_help_option=1, prog=None):
527 """Subclassed OptionParser class with a replacement error function."""
528
529
530 self.relax = relax
531
532
533 OptionParser.__init__(self, usage, option_list, option_class, version, conflict_handler, description, formatter, add_help_option, prog)
534
535
536 - def error(self, message):
551
552
553
554 if __name__ == "__main__":
555 start()
556