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