Change Node.monitor() to just return output.

It seems easier to rely on node.waiting for the moment.
This commit is contained in:
Bob Lantz
2010-03-16 14:59:45 -07:00
parent a3d899123d
commit e4c82e526e
2 changed files with 9 additions and 11 deletions
+2 -4
View File
@@ -209,12 +209,10 @@ class CLI( Cmd ):
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:
+7 -7
View File
@@ -161,7 +161,8 @@ class Node( object ):
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 @@ class Node( object ):
# 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 @@ class Node( object ):
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