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