Skip to content
Snippets Groups Projects
Commit 23c70f60 authored by Bob Lantz's avatar Bob Lantz
Browse files

Add px command which uses exec() vs. py's eval()

This is necessary since exec() isn't really a function, and
eval can't evaluate statements.
fixes #104
parent f0181372
No related branches found
No related tags found
No related merge requests found
......@@ -121,12 +121,12 @@ def do_sh( self, line ):
"Run an external shell command"
call( line, shell=True )
# do_py() needs to catch any exception during eval()
# do_py() and do_px() need to catch any exception during eval()/exec()
# pylint: disable-msg=W0703
def do_py( self, line ):
"""Evaluate a Python expression.
Node names may be used, e.g.: h1.cmd('ls')"""
Node names may be used, e.g.: py h1.cmd('ls')"""
try:
result = eval( line, globals(), self.locals )
if not result:
......@@ -138,7 +138,18 @@ def do_py( self, line ):
except Exception, e:
output( str( e ) + '\n' )
# pylint: enable-msg=W0703
# We are in fact using the exec() pseudo-function
# pylint: disable-msg=W0122
def do_px( self, line ):
"""Execute a Python statement.
Node names may be used, e.g.: px print h1.cmd('ls')"""
try:
exec( line, globals(), self.locals )
except Exception, e:
output( str( e ) + '\n' )
# pylint: enable-msg=W0703,W0122
def do_pingall( self, _line ):
"Ping between all hosts."
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment