ATLAS Offline Software
Public Member Functions | Private Attributes | List of all members
python.Interactive.ShellEscapes Class Reference

LazyPython based hook for shell commands ====================================. More...

Collaboration diagram for python.Interactive.ShellEscapes:

Public Member Functions

def __init__ (self)
 
def uninstall (self)
 
def __call__ (self, exctype, value, traceb)
 

Private Attributes

 _orig_ehook
 

Detailed Description

LazyPython based hook for shell commands ====================================.

Provide shell escapes from the prompt by catching name and syntax errors.

Definition at line 18 of file Interactive.py.

Constructor & Destructor Documentation

◆ __init__()

def python.Interactive.ShellEscapes.__init__ (   self)

Definition at line 21 of file Interactive.py.

21  def __init__( self ):
22  self._orig_ehook = sys.excepthook
23  log.debug( 'shell short-cuts enabled' )
24 

Member Function Documentation

◆ __call__()

def python.Interactive.ShellEscapes.__call__ (   self,
  exctype,
  value,
  traceb 
)

Definition at line 29 of file Interactive.py.

29  def __call__( self, exctype, value, traceb ):
30  global _shellCommands
31 
32  cmd = None
33 
34  # catch name and syntax errors to perform shell escapes if known
35  if isinstance( value, NameError ):
36  res = _NAMEREX.search( str(value) )
37  if res:
38  cmd = res.group( _NAME )
39 
40  # disallow selected commands/executables
41  if cmd in _unacceptable:
42  cmd = None
43 
44  elif isinstance( value, SyntaxError ):
45  cmd = value.text[:-1]
46 
47  # execute command, if any
48  if cmd is not None:
49  args = cmd.split()
50  exe = args[0]
51 
52  # special cases
53  if exe == 'cd' and len(args) == 2:
54  os.chdir( args[1] )
55  log.info( 'new directory: %s', os.getcwd() )
56  return
57 
58  if exe == 'help' and len(args) == 2:
59  import __main__
60  exec ('help( %s )' % args[1] in __main__.__dict__, __main__.__dict__)
61  return
62 
63  # cache shell command
64  if exe not in _shellCommands:
65  log.debug( 'accepting executable "%s"', exe )
66  if unixtools.which( exe ):
67  _shellCommands.append( exe )
68  else:
69  exe = None
70 
71  if exe is not None:
72  log.debug( 'executing shell command "%s"', cmd )
73  os.system( cmd )
74  return
75 
76  # nothing recognizable: normal exception processing
77  self._orig_ehook( exctype, value, traceb )
78 
79 

◆ uninstall()

def python.Interactive.ShellEscapes.uninstall (   self)

Definition at line 25 of file Interactive.py.

25  def uninstall( self ):
26  sys.excepthook = self._orig_ehook
27  log.debug( 'shell short-cuts disabled' )
28 

Member Data Documentation

◆ _orig_ehook

python.Interactive.ShellEscapes._orig_ehook
private

Definition at line 22 of file Interactive.py.


The documentation for this class was generated from the following file:
python.processes.powheg.ZZ.ZZ.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZ.py:18
str
Definition: BTagTrackIpAccessor.cxx:11
uninstall
void uninstall()
Definition: memory_hooks-tcmalloc.h:130