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