From af4921adc5bdb340737ea957a86f8abc754dc69b Mon Sep 17 00:00:00 2001 From: Bob Lantz Date: Thu, 12 Jul 2018 08:20:36 +0000 Subject: [PATCH] Minor changes for Python 3 items() vs. iteritems() and decode() bytes in monitorFiles Probably not strictly correct if bytes are split - we still need to deal with this properly. --- examples/cluster.py | 2 +- examples/controlnet.py | 2 +- examples/multipoll.py | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/cluster.py b/examples/cluster.py index 8959868..078dca4 100755 --- a/examples/cluster.py +++ b/examples/cluster.py @@ -126,7 +126,7 @@ class ClusterCleanup( object ): def cleanup( cls ): "Clean up" info( '*** Cleaning up cluster\n' ) - for server, user in cls.serveruser.iteritems(): + for server, user in cls.serveruser.items(): if server == 'localhost': # Handled by mininet.clean.cleanup() continue diff --git a/examples/controlnet.py b/examples/controlnet.py index 9633089..e5cf765 100755 --- a/examples/controlnet.py +++ b/examples/controlnet.py @@ -49,7 +49,7 @@ class MininetFacade( object ): args: unnamed networks passed as arguments kwargs: named networks passed as arguments""" self.net = net - self.nets = [ net ] + list( args ) + kwargs.values() + self.nets = [ net ] + list( args ) + list( kwargs.values() ) self.nameToNet = kwargs self.nameToNet['net'] = net diff --git a/examples/multipoll.py b/examples/multipoll.py index 0b735ba..bb1c9d3 100755 --- a/examples/multipoll.py +++ b/examples/multipoll.py @@ -9,6 +9,7 @@ monitoring them from mininet.topo import SingleSwitchTopo from mininet.net import Mininet from mininet.log import info, setLogLevel +from mininet.util import decode from time import time from select import poll, POLLIN @@ -19,7 +20,7 @@ def monitorFiles( outfiles, seconds, timeoutms ): "Monitor set of files and return [(host, line)...]" devnull = open( '/dev/null', 'w' ) tails, fdToFile, fdToHost = {}, {}, {} - for h, outfile in outfiles.iteritems(): + for h, outfile in outfiles.items(): tail = Popen( [ 'tail', '-f', outfile ], stdout=PIPE, stderr=devnull ) fd = tail.stdout.fileno() @@ -40,7 +41,7 @@ def monitorFiles( outfiles, seconds, timeoutms ): host = fdToHost[ fd ] # Wait for a line of output line = f.readline().strip() - yield host, line + yield host, decode( line ) else: # If we timed out, return nothing yield None, ''