ATLAS Offline Software
Loading...
Searching...
No Matches
python.Interactive.ShellEscapes Class Reference

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

Collaboration diagram for python.Interactive.ShellEscapes:

Public Member Functions

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

Protected Attributes

 _orig_ehook = sys.excepthook

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__()

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__()

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

Definition at line 29 of file Interactive.py.

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

◆ uninstall()

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 = sys.excepthook
protected

Definition at line 22 of file Interactive.py.


The documentation for this class was generated from the following file: