Revision 9d0dbe48

View differences:

mininet/cli.py
50 50
        self.stdin = stdin
51 51
        self.inPoller = poll()
52 52
        self.inPoller.register( stdin )
53
        self.inputFile = None
53 54
        Cmd.__init__( self )
54 55
        info( '*** Starting CLI:\n' )
55 56
        while True:
......
247 248
        if self.isatty():
248 249
            quietRun( 'stty -echo' )
249 250
        self.default( line )
250
        # default() fixes tty
251
        if self.isatty():
252
            quietRun( 'stty echo' )
253

  
254
    def do_source( self, line ):
255
        "Read commands from an input file."
256
        args = line.split()
257
        if len(args) != 1:
258
            error( 'usage: source <file>\n' )
259
            return
260
        try:
261
            self.inputFile = open( args[ 0 ] )
262
            while True:
263
                line = self.inputFile.readline()
264
                if len( line ) > 0:
265
                    self.onecmd( line )
266
                else:
267
                    break
268
        except IOError:
269
            pass
270
        self.inputFile = None
251 271

  
252 272
    def default( self, line ):
253 273
        """Called on an input line when the command prefix is not recognized.
......
256 276
        corresponding IP addrs."""
257 277

  
258 278
        first, args, line = self.parseline( line )
259
        if len(args) > 0 and args[ -1 ] == '\n':
279
        if args and len(args) > 0 and args[ -1 ] == '\n':
260 280
            args = args[ :-1 ]
261 281
        rest = args.split( ' ' )
262 282

  
......
273 293
            self.waitForNode( node )
274 294
        else:
275 295
            error( '*** Unknown command: %s\n' % first )
296
        
276 297

  
277 298
    # pylint: enable-msg=W0613,R0201
278 299

  
......
291 312
        while True:
292 313
            try:
293 314
                bothPoller.poll()
315
                if self.inputFile:
316
                    key = self.inputFile.read( 1 )
317
                    if key is not '':
318
                        node.write(key)
319
                    else:
320
                        self.inputFile = None
294 321
                if isReadable( self.inPoller ):
295 322
                    key = self.stdin.read( 1 )
296 323
                    node.write( key )

Also available in: Unified diff