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

Change Node.monitor() to just return output.

It seems easier to rely on node.waiting for the moment.
parent a3d89912
No related branches found
No related tags found
No related merge requests found
...@@ -209,12 +209,10 @@ def default( self, line ): ...@@ -209,12 +209,10 @@ def default( self, line ):
rest = ' '.join( rest ) rest = ' '.join( rest )
# Run cmd on node: # Run cmd on node:
node.sendCmd( rest, printPid=True ) node.sendCmd( rest, printPid=True )
while True: while node.waiting:
try: try:
done, data = node.monitor() data = node.monitor()
info( '%s' % data ) info( '%s' % data )
if done:
break
except KeyboardInterrupt: except KeyboardInterrupt:
node.sendInt() node.sendInt()
else: else:
......
...@@ -161,7 +161,8 @@ def sendInt( self ): ...@@ -161,7 +161,8 @@ def sendInt( self ):
os.kill( self.lastPid, signal.SIGINT ) os.kill( self.lastPid, signal.SIGINT )
def monitor( self ): def monitor( self ):
"Monitor the output of a command, returning (done?, data)." """Monitor and return the output of a command.
Set self.waiting to False if command has completed."""
assert self.waiting assert self.waiting
self.waitReadable() self.waitReadable()
data = self.read( 1024 ) data = self.read( 1024 )
...@@ -175,11 +176,11 @@ def monitor( self ): ...@@ -175,11 +176,11 @@ def monitor( self ):
# Look for sentinel/EOF # Look for sentinel/EOF
if len( data ) > 0 and data[ -1 ] == chr( 127 ): if len( data ) > 0 and data[ -1 ] == chr( 127 ):
self.waiting = False self.waiting = False
return True, data[ :-1 ] data = data[ :-1 ]
elif chr( 127 ) in data: elif chr( 127 ) in data:
self.waiting = False self.waiting = False
return True, data.replace( chr( 127 ), '' ) data = data.replace( chr( 127 ), '' )
return False, data return data
def waitOutput( self, verbose=False ): def waitOutput( self, verbose=False ):
"""Wait for a command to complete. """Wait for a command to complete.
...@@ -189,9 +190,8 @@ def waitOutput( self, verbose=False ): ...@@ -189,9 +190,8 @@ def waitOutput( self, verbose=False ):
verbose: print output interactively""" verbose: print output interactively"""
log = info if verbose else debug log = info if verbose else debug
output = '' output = ''
done = False while self.waiting:
while not done: data = self.monitor()
done, data = self.monitor()
output += data output += data
log( data ) log( data )
return output return output
......
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