diff --git a/mininet/test/test_walkthrough.py b/mininet/test/test_walkthrough.py index 39be95f..2e01bdf 100755 --- a/mininet/test/test_walkthrough.py +++ b/mininet/test/test_walkthrough.py @@ -19,12 +19,13 @@ from mininet.clean import cleanup def tsharkVersion(): "Return tshark version" versionStr = quietRun( 'tshark -v' ) - versionMatch = re.findall( r'TShark[^\d]*(\d+.\d+.\d+)', versionStr ) - return versionMatch[ 0 ] + versionMatch = re.findall( r'TShark[^\d]*(\d+\.\d+\.\d+)', versionStr ) + return versionMatch[ 0 ] if versionMatch else '0.0.0' # pylint doesn't understand pexpect.match, unfortunately! # pylint:disable=maybe-no-member +@unittest.skipIf( pexpect is None, 'pexpect is not installed' ) class testWalkthrough( unittest.TestCase ): "Test Mininet walkthrough" diff --git a/mininet/util.py b/mininet/util.py index e776e9f..e3110bf 100644 --- a/mininet/util.py +++ b/mininet/util.py @@ -59,8 +59,53 @@ try: import packaging.version # replacement for distutils.version StrictVersion = packaging.version.parse except ImportError: # python2.7 lacks ModuleNotFoundError - import distutils.version # pylint: disable=deprecated-module - StrictVersion = distutils.version.StrictVersion + try: + import distutils.version # pylint: disable=deprecated-module + StrictVersion = distutils.version.StrictVersion + except ( ImportError, AttributeError ): + import re + + class FallbackStrictVersion( object ): + "Fallback version comparator when packaging/distutils are unavailable" + def __init__( self, vstring=None ): + self.vstring = str( vstring ) if vstring is not None else '' + self.version = self._parse( self.vstring ) + + @staticmethod + def _parse( vstring ): + components = re.findall( r'\d+|\D+', vstring.strip() ) + return tuple( int( c ) if c.isdigit() else c for c in components ) + + def __lt__( self, other ): + other_ver = other.version if isinstance( other, FallbackStrictVersion ) else self._parse( str( other ) ) + return self.version < other_ver + + def __le__( self, other ): + other_ver = other.version if isinstance( other, FallbackStrictVersion ) else self._parse( str( other ) ) + return self.version <= other_ver + + def __gt__( self, other ): + other_ver = other.version if isinstance( other, FallbackStrictVersion ) else self._parse( str( other ) ) + return self.version > other_ver + + def __ge__( self, other ): + other_ver = other.version if isinstance( other, FallbackStrictVersion ) else self._parse( str( other ) ) + return self.version >= other_ver + + def __eq__( self, other ): + other_ver = other.version if isinstance( other, FallbackStrictVersion ) else self._parse( str( other ) ) + return self.version == other_ver + + def __ne__( self, other ): + return not self.__eq__( other ) + + def __repr__( self ): + return "StrictVersion('%s')" % self.vstring + + def __str__( self ): + return self.vstring + + StrictVersion = FallbackStrictVersion try: oldpexpect = None @@ -79,7 +124,7 @@ try: return getattr( oldpexpect, name ) pexpect = Pexpect() except ImportError: - pass + pexpect = None # Command execution support diff --git a/util/install.sh b/util/install.sh index 60d7b64..00ee5e6 100755 --- a/util/install.sh +++ b/util/install.sh @@ -190,7 +190,7 @@ function mn_deps { $install gcc make socat psmisc xterm ssh iperf telnet \ ethtool help2man $pf pylint $pep8 \ - net-tools ${PYPKG}-tk + net-tools ${PYPKG}-tk ${PYPKG}-packaging || true # Install pip $install ${PYPKG}-pip || $install ${PYPKG}-pip-whl @@ -203,7 +203,7 @@ function mn_deps { sudo ${PYTHON} get-pip.py rm get-pip.py fi - ${python} -m pip install pexpect + ${PYTHON} -m pip install pexpect || true $install iproute2 || $install iproute $install cgroup-tools || $install cgroup-bin $install cgroupfs-mount diff --git a/util/versioncheck.py b/util/versioncheck.py index a9d6cfc..ddc69d5 100755 --- a/util/versioncheck.py +++ b/util/versioncheck.py @@ -13,7 +13,7 @@ version = 'Mininet ' + run( 'PYTHONPATH=. bin/mn --version 2>&1', shell=True ) version = version.strip() # Find all Mininet path references -lines = run( "egrep -or 'Mininet [0-9\.\+]+\w*' *", shell=True ) +lines = run( r"egrep -or 'Mininet [0-9\.\+]+\w*' *", shell=True ) error = False