| Trees | Indices | Help |
|---|
|
|
1 ################################################################################
2 #
3 # Copyright (c) 2009 The MadGraph Development team and Contributors
4 #
5 # This file is a part of the MadGraph 5 project, an application which
6 # automatically generates Feynman diagrams and matrix elements for arbitrary
7 # high-energy processes in the Standard Model and beyond.
8 #
9 # It is subject to the MadGraph license which should accompany this
10 # distribution.
11 #
12 # For more information, please visit: http://madgraph.phys.ucl.ac.be
13 #
14 ################################################################################
15 """A user friendly command line interface to access all MadGraph features.
16 Uses the cmd package for command interpretation and tab completion.
17 """
18
19
20 import atexit
21 import logging
22 import optparse
23 import os
24 import pydoc
25 import re
26 import subprocess
27 import sys
28 import traceback
29 import time
30
31 root_path = os.path.split(os.path.dirname(os.path.realpath( __file__ )))[0]
32 root_path = os.path.split(root_path)[0]
33 sys.path.insert(0, root_path)
34
35 #usefull shortcut
36 pjoin = os.path.join
37
38 import madgraph
39 import madgraph.interface.extended_cmd as cmd
40 import madgraph.interface.madgraph_interface as MGcmd
41 import madgraph.iolibs.files as files
42
43 from madgraph import MG4DIR, MG5DIR, MadGraph5Error
44
45 logger = logging.getLogger('cmdprint') # -> stdout
46
47
49 """ Helping class containing all the switching routine """
50
52
53 # define the interface
54 self.change_principal_cmd(main)
55 self.cmd.__init__(self, *args, **opt)
56
57
58
59
61 """redefine all the command to call directly the appropriate child"""
62
63 correct = True
64 # function which should be self.cmd dependent but which doesn't start
65 # by do_xxxx, help_xxx, check_xxxx or complete_xxx
66 overwritable = []
67 # list of item overwritten by the MasterClass
68 self.to_preserve = [key for key,method in Switcher.__dict__.items() if
69 hasattr(method, '__call__') ]
70 self.to_preserve += ['do_shell', 'help_shell', 'complete_shell']
71
72 ff = open(pjoin(MG5DIR, 'additional_command'), 'w')
73
74 for key in dir(self):
75 # by pass all not over-writable command
76 if key in self.to_preserve:
77 continue
78 if not (key.startswith('do_') or key.startswith('complete_') or \
79 key.startswith('help_') or key.startswith('check_') or \
80 key in overwritable):
81 continue
82 text = """\
83 def %(key)s(self, *args, **opts):
84 return self.cmd.%(key)s(self, *args, **opts)
85
86 """ % {'key': key}
87 logger.warning("""Command %s not define in the Master.
88 The line to add to the master_interface.py are written in 'additional_command' file""" % key)
89 ff.write(text)
90 correct = False
91
92
93 # Check that all function define in more than one subclass is define
94 # in the Switcher or in one of the MasterClass
95 define = {}
96 for mother in MasterCmd.__mro__:
97 if mother.__name__ in ['Cmd', 'BasicCmd', 'ExtendedCmd']:
98 continue
99
100
101 for data in mother.__dict__:
102 #check if define in Switcher
103 if data in Switcher.__dict__ or data.startswith('__'):
104 continue
105 if data in MasterCmd.__dict__:
106 #always overwritten in the main class
107 continue
108 if data not in define:
109 define[data] = mother.__name__
110 else:
111 logger.warning('%s define in %s and in %s but not in Switcher.' % (data, define[data], mother.__name__))
112 correct = False
113
114 # Do the same for the WEb MasterClass
115 define = {}
116 for mother in MasterCmdWeb.__mro__:
117 if mother.__name__ in ['Cmd', 'BasicCmd', 'ExtendedCmd']:
118 continue
119
120 for data in mother.__dict__:
121 #check if define in Switcher
122 if data in Switcher.__dict__ or data.startswith('__'):
123 continue
124 if data in MasterCmdWeb.__dict__:
125 #always overwritten in the main class
126 continue
127 if data not in define:
128 define[data] = mother.__name__
129 else:
130 logger.warning('%s define in %s and in %s but not in Switcher.' % (data, define[data], mother.__name__))
131 correct = False
132
133 if not correct:
134 raise Exception, 'The Cmd interface has dangerous features. Please see previous warnings and correct those.'
135
136
137
138
139
141 return self.cmd.check_add(self, *args, **opts)
142
144 return self.cmd.check_answer_in_input_file(self, *args, **opts)
145
147 return self.cmd.check_check(self, *args, **opts)
148
150 return self.cmd.check_define(self, *args, **opts)
151
153 return self.cmd.check_display(self, *args, **opts)
154
156 return self.cmd.check_draw(self, *args, **opts)
157
159 return self.cmd.check_for_export_dir(self, *args, **opts)
160
162 return self.cmd.check_generate(self, *args, **opts)
163
165 return self.cmd.check_history(self, *args, **opts)
166
168 return self.cmd.check_import(self, *args, **opts)
169
171 return self.cmd.check_install(self, *args, **opts)
172
174 return self.cmd.check_launch(self, *args, **opts)
175
177 return self.cmd.check_load(self, *args, **opts)
178
180 return self.cmd.check_open(self, *args, **opts)
181
183 return self.cmd.check_output(self, *args, **opts)
184
186 return self.cmd.check_process_format(self, *args, **opts)
187
189 return self.cmd.check_save(self, *args, **opts)
190
192 return self.cmd.check_set(self, *args, **opts)
193
195 return self.cmd.check_stored_line(self, *args, **opts)
196
198 return self.cmd.complete_add(self, *args, **opts)
199
201 return self.cmd.complete_check(self, *args, **opts)
202
204 return self.cmd.complete_define(self, *args, **opts)
205
207 return self.cmd.complete_display(self, *args, **opts)
208
210 return self.cmd.complete_draw(self, *args, **opts)
211
213 return self.cmd.complete_generate(self, *args, **opts)
214
216 return self.cmd.complete_help(self, *args, **opts)
217
219 return self.cmd.complete_history(self, *args, **opts)
220
222 return self.cmd.complete_import(self, *args, **opts)
223
225 return self.cmd.complete_install(self, *args, **opts)
226
228 return self.cmd.complete_launch(self, *args, **opts)
229
231 return self.cmd.complete_load(self, *args, **opts)
232
234 return self.cmd.complete_open(self, *args, **opts)
235
237 return self.cmd.complete_output(self, *args, **opts)
238
240 return self.cmd.complete_save(self, *args, **opts)
241
243 return self.cmd.complete_set(self, *args, **opts)
244
246 return self.cmd.complete_tutorial(self, *args, **opts)
247
249 return self.cmd.do_EOF(self, *args, **opts)
250
252 return self.cmd.do_add(self, *args, **opts)
253
255 return self.cmd.do_check(self, *args, **opts)
256
258 return self.cmd.do_define(self, *args, **opts)
259
261 return self.cmd.do_display(self, *args, **opts)
262
264 return self.cmd.do_exit(self, *args, **opts)
265
267 return self.cmd.do_generate(self, *args, **opts)
268
270 return self.cmd.do_help(self, *args, **opts)
271
273 return self.cmd.do_history(self, *args, **opts)
274
276 return self.cmd.do_import(self, *args, **opts)
277
279 return self.cmd.do_install(self, *args, **opts)
280
282 return self.cmd.do_launch(self, *args, **opts)
283
285 return self.cmd.do_load(self, *args, **opts)
286
288 return self.cmd.do_open(self, *args, **opts)
289
291 return self.cmd.do_output(self, *args, **opts)
292
294 return self.cmd.do_quit(self, *args, **opts)
295
297 return self.cmd.do_save(self, *args, **opts)
298
300 return self.cmd.do_set(self, *args, **opts)
301
303 return self.cmd.do_tutorial(self, *args, **opts)
304
306 return self.cmd.help_EOF(self, *args, **opts)
307
309 return self.cmd.help_add(self, *args, **opts)
310
312 return self.cmd.help_check(self, *args, **opts)
313
315 return self.cmd.help_define(self, *args, **opts)
316
318 return self.cmd.help_display(self, *args, **opts)
319
321 return self.cmd.help_generate(self, *args, **opts)
322
324 return self.cmd.help_help(self, *args, **opts)
325
327 return self.cmd.help_history(self, *args, **opts)
328
330 return self.cmd.help_import(self, *args, **opts)
331
333 return self.cmd.help_install(self, *args, **opts)
334
336 return self.cmd.help_launch(self, *args, **opts)
337
339 return self.cmd.help_load(self, *args, **opts)
340
342 return self.cmd.help_open(self, *args, **opts)
343
345 return self.cmd.help_output(self, *args, **opts)
346
348 return self.cmd.help_quit(self, *args, **opts)
349
351 return self.cmd.help_save(self, *args, **opts)
352
354 return self.cmd.help_set(self, *args, **opts)
355
357 return self.cmd.help_tutorial(self, *args, **opts)
358
360 return self.cmd.test_interface(self, *args, **opts)
361
363 return self.cmd.set_configuration(self, *args, **opts)
364
365
367
368
370 if name == 'MadGraph':
371 self.cmd = MGcmd.MadGraphCmd
372 else:
373 raise MadGraph5Error, 'Type of interface not valid'
374
375 if __debug__:
376 self.debug_link_to_command()
377
379
381
382 if os.environ.has_key('_CONDOR_SCRATCH_DIR'):
383 self.writing_dir = pjoin(os.environ['_CONDOR_SCRATCH_DIR'], \
384 os.path.pardir)
385 else:
386 self.writing_dir = pjoin(os.environ['MADGRAPH_DATA'],
387 os.environ['REMOTE_USER'])
388
389
390 #standard initialization
391 Switcher.__init__(self, mgme_dir = '', *arg, **opt)
392
393 self.options['timeout'] = 1 # time authorize to answer question [0 is no time limit]
394
396 if name == 'MadGraph':
397 self.cmd = MGcmd.MadGraphCmdWeb
398 # elif name == 'Loop':
399 # self.cmd = NLOcmd.LoopInterfaceWeb
400 else:
401 raise MadGraph5Error, 'Type of interface not valid'
402
403 if __debug__:
404 self.debug_link_to_command()
405
410
411 # Generate a new amplitude
413 """Generate an amplitude for a given process"""
414
415 try:
416 Switcher.do_generate(self, line)
417 except:
418 # put the stop logo on the web
419 files.cp(self._export_dir+'/HTML/stop.jpg',self._export_dir+'/HTML/card.jpg')
420 raise
421
422 # Add a process to the existing multiprocess definition
424 """Generate an amplitude for a given process and add to
425 existing amplitudes
426 syntax:
427 """
428 try:
429 Switcher.do_add(self, line)
430 except:
431 # put the stop logo on the web
432 files.cp(self._export_dir+'/HTML/stop.jpg',self._export_dir+'/HTML/card.jpg')
433 raise
434
435 # Use the cluster file for the configuration
437
438 """Force to use the web configuration file only"""
439 config_path = pjoin(os.environ['MADGRAPH_BASE'], 'mg5_configuration.txt')
440 return Switcher.set_configuration(self, config_path=config_path)
441
442
444 """Save information to file"""
445
446 if check:
447 self.check_save([])
448 raise #useless but full security
449
450 args = self.split_arg(line)
451 if args[0] != 'options':
452 Switcher.do_save(self, line,check)
453 else:
454 # put default options since
455 # in the web the local file is not used
456 # in download the default file is more usefull
457 files.cp(pjoin(MG5DIR,'input','mg5_configuration.txt'), args[1])
458
| Trees | Indices | Help |
|---|
| Generated by Epydoc 3.0.1 on Tue Jul 24 08:02:13 2012 | http://epydoc.sourceforge.net |