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 compat
38
39
40 import dep_check
41
42
43 from optparse import Option, OptionParser
44 from os import F_OK, access, getpid, putenv
45 if dep_check.profile_module:
46 import profile
47 import pstats
48 from pydoc import pager
49 from re import match
50 import sys
51
52
53 from info import Info_box
54 from multi import Application_callback, load_multiprocessor
55 from prompt import interpreter
56 import relax_errors
57 from relax_io import io_streams_log, io_streams_tee
58 import relax_warnings
59 from status import Status; status = Status()
60 import version
61
62
63 putenv('PDBVIEWER', 'vmd')
64
65
66 -def start(mode=None, profile_flag=False):
117
118
119 if not dep_check.profile_module:
120 sys.stderr.write("The profile module is not available, please install the Python development packages for profiling.\n\n")
121 sys.exit()
122
123
124 profile.Profile.print_stats = print_stats
125 profile.runctx('processor.run()', globals(), locals())
126
127
128
130 """The main relax class.
131
132 This contains information about the running state, for example the mode of operation of relax,
133 whether debugging is turned on, etc.
134 """
135
137 """The top level class for initialising the program.
138
139 @keyword mode: Force a relax mode, overriding the command line.
140 @type mode: str
141 """
142
143
144 self.pid = getpid()
145
146
261
262
264 """Process the command line arguments."""
265
266
267 parser = RelaxParser(self, usage="usage: %prog [options] [script_file]")
268
269
270 parser.add_option('-d', '--debug', action='store_true', dest='debug', default=0, help='enable debugging output')
271 parser.add_option('-l', '--log', action='store', type='string', dest='log', help='log relax output to the file LOG_FILE', metavar='LOG_FILE')
272 parser.add_option('--licence', action='store_true', dest='licence', default=0, help='display the licence')
273 parser.add_option('-t', '--tee', action='store', type='string', dest='tee', help='tee relax output to stdout and the file LOG_FILE', metavar='LOG_FILE')
274 parser.add_option('-g', '--gui', action='store_true', dest='gui', default=0, help='launch the relax GUI')
275 parser.add_option('-p', '--pedantic', action='store_true', dest='pedantic', default=0, help='escalate all warnings to errors')
276 parser.add_option('--test', action='store_true', dest='test', default=0, help='run relax in test mode')
277 parser.add_option('-x', '--test-suite', action='store_true', dest='test_suite', default=0, help='execute the relax test suite')
278 parser.add_option('-s', '--system-tests', action='store_true', dest='system_tests', default=0, help='execute the relax system/functional tests (part of the test suite)')
279 parser.add_option('-u', '--unit-tests', action='store_true', dest='unit_tests', default=0, help='execute the relax unit tests (part of the test suite)')
280 parser.add_option('--gui-tests', action='store_true', dest='gui_tests', default=0, help='execute the relax GUI tests (part of the test suite)')
281 parser.add_option('-i', '--info', action='store_true', dest='info', default=0, help='display information about this version of relax')
282 parser.add_option('-v', '--version', action='store_true', dest='version', default=0, help='show the version number and exit')
283 parser.add_option('-m', '--multi', action='store', type='string', dest='multiprocessor', default='uni', help='set multi processor method')
284 parser.add_option('-n', '--processors', action='store', type='int', dest='n_processors', default=-1, help='set number of processors (may be ignored)')
285
286
287 (options, args) = parser.parse_args()
288
289
290 if options.debug:
291 status.debug = True
292
293
294 if options.pedantic:
295 status.pedantic = True
296
297
298 if options.log:
299
300 if options.tee:
301 parser.error("the logging and tee options cannot be set simultaneously")
302
303
304 self.log_file = options.log
305
306
307 if access(self.log_file, F_OK):
308 parser.error("the log file " + repr(self.log_file) + " already exists")
309 else:
310 self.log_file = None
311
312
313 if options.tee:
314
315 if options.log:
316 parser.error("the tee and logging options cannot be set simultaneously")
317
318
319 self.tee_file = options.tee
320
321
322 if access(self.tee_file, F_OK):
323 parser.error("the tee file " + repr(self.tee_file) + " already exists")
324 else:
325 self.tee_file = None
326
327
328 if options.test_suite or options.system_tests or options.unit_tests or options.gui_tests:
329 self.tests = args
330
331
332 else:
333
334 if len(args) > 1:
335 parser.error("incorrect number of arguments")
336
337
338 self.script_file = None
339 if len(args) == 1:
340 self.script_file = args[0]
341
342
343 if not access(self.script_file, F_OK):
344 parser.error("the script file " + repr(self.script_file) + " does not exist")
345
346
347 self.multiprocessor_type = options.multiprocessor
348 self.n_processors = options.n_processors
349
350
351 if self.multiprocessor_type == 'mpi4py' and not dep_check.mpi4py_module:
352 parser.error(dep_check.mpi4py_message)
353
354
355
356
357
358
359 if options.version:
360 self.mode = 'version'
361
362
363 elif options.info:
364 self.mode = 'info'
365
366
367 elif options.test_suite or options.system_tests or options.unit_tests or options.gui_tests:
368
369 if options.test:
370 parser.error("executing the relax test suite and running relax in test mode are mutually exclusive")
371 elif options.licence:
372 parser.error("executing the relax test suite and running relax in licence mode are mutually exclusive")
373
374
375 if options.test_suite:
376 self.mode = 'test suite'
377 elif options.system_tests:
378 self.mode = 'system tests'
379 elif options.unit_tests:
380 self.mode = 'unit tests'
381 elif options.gui_tests:
382 self.mode = 'GUI tests'
383
384
385 status.test_mode = True
386
387
388 elif options.test:
389
390 if self.script_file:
391 parser.error("a script should not be supplied in test mode")
392
393
394 if options.test_suite or options.system_tests or options.unit_tests or options.gui_tests:
395 parser.error("the relax test mode and executing the test suite are mutually exclusive")
396 elif options.licence:
397 parser.error("the relax modes test and licence are mutually exclusive")
398
399
400 self.mode = 'test'
401
402
403 elif options.licence:
404
405 if self.script_file:
406 parser.error("a script should not be supplied in test mode")
407
408
409 if options.test_suite or options.system_tests or options.unit_tests or options.gui_tests:
410 parser.error("the relax licence mode and executing the test suite are mutually exclusive")
411 elif options.test:
412 parser.error("the relax modes licence and test are mutually exclusive")
413
414
415 self.mode = 'licence'
416
417
418 elif options.gui:
419
420 if options.test_suite or options.system_tests or options.unit_tests or options.gui_tests:
421 parser.error("the relax GUI mode and testing modes are mutually exclusive")
422 elif options.licence:
423 parser.error("the relax GUI mode and licence mode are mutually exclusive")
424
425
426 if not dep_check.wx_module:
427 parser.error("To use the GUI, the wx python module must be installed.")
428
429
430 self.mode = 'gui'
431
432
433 elif self.script_file:
434 self.mode = 'script'
435
436
437 else:
438 self.mode = 'prompt'
439
440
442 """Function for displaying the licence."""
443
444
445 file = open('docs/COPYING')
446 pager(file.read())
447
448
450 """Relax test mode code."""
451
452
453 return
454
455
456
458 - 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):
459 """Subclassed OptionParser class with a replacement error function."""
460
461
462 self.relax = relax
463
464
465 OptionParser.__init__(self, usage, option_list, option_class, version, conflict_handler, description, formatter, add_help_option, prog)
466
467
468 - def error(self, message):
483
484
485
486 if __name__ == "__main__":
487 start()
488