From: Zooko O'Whielacronx Date: Thu, 16 Aug 2007 23:16:41 +0000 (-0700) Subject: version_class.py: if you don't have pkg_resources for comparing version numbers,... X-Git-Url: https://git.rkrishnan.org/COPYING.TGPPL.html?a=commitdiff_plain;h=5a1d4aa8b70e929672dad19c99d08c4888e5d940;p=tahoe-lafs%2Ftahoe-lafs.git version_class.py: if you don't have pkg_resources for comparing version numbers, use distutils.version.LooseVersion --- diff --git a/src/allmydata/util/version_class.py b/src/allmydata/util/version_class.py index dbab3b87..da6fe488 100644 --- a/src/allmydata/util/version_class.py +++ b/src/allmydata/util/version_class.py @@ -10,7 +10,15 @@ extended version number class """ # from setuptools, but intended to be included in future version of Python Standard Library (PEP 365) -import pkg_resources +try: + import pkg_resources +except ImportError: + import distutils.version + def cmp_version(v1, v2): + return cmp(distutils.version.LooseVersion(str(v1)), distutils.version.LooseVersion(str(v2))) +else: + def cmp_version(v1, v2): + return cmp(pkg_resources.parse_version(str(v1)), pkg_resources.parse_version(str(v2))) # bindann, by Nathan Wilcox (needed only for debugging) try: @@ -130,4 +138,4 @@ class Version(object): return self.__str__() def __cmp__ (self, other): - return cmp(pkg_resources.parse_version(str(self)), pkg_resources.parse_version(str(other))) + return cmp_version(self, other)