From 3e16a0ab627a095605f14a5164c2d8e14a3bcaa9 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Mon, 1 Feb 2010 12:31:53 -0500 Subject: [PATCH] Made Bzr/Darcs.version_cmp() more robust in response to Chris' email. From: Chris Ball Subject: Test suite status ... I ran the wking@drexel.edu-20100130162439-pmh5tg6kuq92x3l5 testsuite on Fedora 13/Rawhide. Had to downgrade Mercurial (bzr-hg doesn't support 1.4.2 yet) and bzr (my Fedora package contained a "b4" in the version string, which breaks libbe/storage/vcs/bzr.py:version_cmp()). ... --- libbe/storage/vcs/bzr.py | 24 +++++++++++++++--------- libbe/storage/vcs/darcs.py | 24 +++++++++++++++--------- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/libbe/storage/vcs/bzr.py b/libbe/storage/vcs/bzr.py index ce140bc..01d9948 100644 --- a/libbe/storage/vcs/bzr.py +++ b/libbe/storage/vcs/bzr.py @@ -37,6 +37,7 @@ import re import shutil import StringIO import sys +import types import libbe import base @@ -82,22 +83,27 @@ class Bzr(base.VCS): >>> b._vcs_version = lambda : "2.0.0pre2" >>> b._parsed_version = None >>> b.version_cmp(3) + -1 + >>> b.version_cmp(2,0,1) Traceback (most recent call last): ... - NotImplementedError: Cannot parse "2.0.0pre2" portion of Bazaar version "2.0.0pre2" - invalid literal for int() with base 10: '0pre2' + NotImplementedError: Cannot parse non-integer portion "0pre2" of Bzr version "2.0.0pre2" """ if not hasattr(self, '_parsed_version') \ or self._parsed_version == None: num_part = self._vcs_version().split(' ')[0] - try: - self._parsed_version = [int(i) for i in num_part.split('.')] - except ValueError, e: + self._parsed_version = [] + for num in num_part.split('.'): + try: + self._parsed_version.append(int(num)) + except ValueError, e: + self._parsed_version.append(num) + for current,other in zip(self._parsed_version, args): + if type(current) != types.IntType: raise NotImplementedError( - 'Cannot parse "%s" portion of Bazaar version "%s"\n %s' - % (num_part, self._vcs_version(), str(e))) - cmps = [cmp(a,b) for a,b in zip(self._parsed_version, args)] - for c in cmps: + 'Cannot parse non-integer portion "%s" of Bzr version "%s"' + % (current, self._vcs_version())) + c = cmp(current,other) if c != 0: return c return 0 diff --git a/libbe/storage/vcs/darcs.py b/libbe/storage/vcs/darcs.py index 7c6f069..fd8b7d5 100644 --- a/libbe/storage/vcs/darcs.py +++ b/libbe/storage/vcs/darcs.py @@ -25,6 +25,7 @@ import re import shutil import sys import time # work around http://mercurial.selenic.com/bts/issue618 +import types try: # import core module, Python >= 2.5 from xml.etree import ElementTree except ImportError: # look for non-core module @@ -75,22 +76,27 @@ class Darcs(base.VCS): >>> d._vcs_version = lambda : "2.0.0pre2" >>> d._parsed_version = None >>> d.version_cmp(3) + -1 + >>> d.version_cmp(2,0,1) Traceback (most recent call last): ... - NotImplementedError: Cannot parse "2.0.0pre2" portion of Darcs version "2.0.0pre2" - invalid literal for int() with base 10: '0pre2' + NotImplementedError: Cannot parse non-integer portion "0pre2" of Darcs version "2.0.0pre2" """ if not hasattr(self, '_parsed_version') \ or self._parsed_version == None: num_part = self._vcs_version().split(' ')[0] - try: - self._parsed_version = [int(i) for i in num_part.split('.')] - except ValueError, e: + self._parsed_version = [] + for num in num_part.split('.'): + try: + self._parsed_version.append(int(num)) + except ValueError, e: + self._parsed_version.append(num) + for current,other in zip(self._parsed_version, args): + if type(current) != types.IntType: raise NotImplementedError( - 'Cannot parse "%s" portion of Darcs version "%s"\n %s' - % (num_part, self._vcs_version(), str(e))) - cmps = [cmp(a,b) for a,b in zip(self._parsed_version, args)] - for c in cmps: + 'Cannot parse non-integer portion "%s" of Darcs version "%s"' + % (current, self._vcs_version())) + c = cmp(current,other) if c != 0: return c return 0 -- 2.26.2