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

Added "source" command and restored echo after noecho command.

Interactive commands should "work", sort of.
parent 272d496d
No related branches found
No related tags found
No related merge requests found
...@@ -50,6 +50,7 @@ def __init__( self, mininet, stdin=sys.stdin ): ...@@ -50,6 +50,7 @@ def __init__( self, mininet, stdin=sys.stdin ):
self.stdin = stdin self.stdin = stdin
self.inPoller = poll() self.inPoller = poll()
self.inPoller.register( stdin ) self.inPoller.register( stdin )
self.inputFile = None
Cmd.__init__( self ) Cmd.__init__( self )
info( '*** Starting CLI:\n' ) info( '*** Starting CLI:\n' )
while True: while True:
...@@ -217,7 +218,26 @@ def do_noecho( self, line ): ...@@ -217,7 +218,26 @@ def do_noecho( self, line ):
if self.isatty(): if self.isatty():
quietRun( 'stty -echo' ) quietRun( 'stty -echo' )
self.default( line ) self.default( line )
# default() fixes tty if self.isatty():
quietRun( 'stty echo' )
def do_source( self, line ):
"Read commands from an input file."
args = line.split()
if len(args) != 1:
error( 'usage: source <file>\n' )
return
try:
self.inputFile = open( args[ 0 ] )
while True:
line = self.inputFile.readline()
if len( line ) > 0:
self.onecmd( line )
else:
break
except IOError:
pass
self.inputFile = None
def default( self, line ): def default( self, line ):
"""Called on an input line when the command prefix is not recognized. """Called on an input line when the command prefix is not recognized.
...@@ -226,7 +246,7 @@ def default( self, line ): ...@@ -226,7 +246,7 @@ def default( self, line ):
corresponding IP addrs.""" corresponding IP addrs."""
first, args, line = self.parseline( line ) first, args, line = self.parseline( line )
if len(args) > 0 and args[ -1 ] == '\n': if args and len(args) > 0 and args[ -1 ] == '\n':
args = args[ :-1 ] args = args[ :-1 ]
rest = args.split( ' ' ) rest = args.split( ' ' )
...@@ -243,6 +263,7 @@ def default( self, line ): ...@@ -243,6 +263,7 @@ def default( self, line ):
self.waitForNode( node ) self.waitForNode( node )
else: else:
error( '*** Unknown command: %s\n' % first ) error( '*** Unknown command: %s\n' % first )
# pylint: enable-msg=W0613,R0201 # pylint: enable-msg=W0613,R0201
...@@ -261,6 +282,12 @@ def waitForNode( self, node ): ...@@ -261,6 +282,12 @@ def waitForNode( self, node ):
while True: while True:
try: try:
bothPoller.poll() bothPoller.poll()
if self.inputFile:
key = self.inputFile.read( 1 )
if key is not '':
node.write(key)
else:
self.inputFile = None
if isReadable( self.inPoller ): if isReadable( self.inPoller ):
key = self.stdin.read( 1 ) key = self.stdin.read( 1 )
node.write( key ) node.write( key )
......
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