diff options
author | Florian Weimer <fw@deneb.enyo.de> | 2007-10-17 10:15:30 +0000 |
---|---|---|
committer | Florian Weimer <fw@deneb.enyo.de> | 2007-10-17 10:15:30 +0000 |
commit | 33f7049e330046f3818f8f7442059f8b86e08c57 (patch) | |
tree | 9d56acf2ec8c3d9cb149bc42acac0cf1cb0827cf /lib | |
parent | e4554700bde0b4bf951f5c2059a8511a5e880412 (diff) |
* lib/python/debian_support.py: Remove fallback for missing python-apt
These days, we need the APT algorithm, not the one described in
policy. Requiring python-apt leads to a clear error message up front,
instead of an obscure one much later in the process.
git-svn-id: svn+ssh://svn.debian.org/svn/secure-testing@6994 e39458fd-73e7-0310-bf30-c45bca0a0e42
Diffstat (limited to 'lib')
-rw-r--r-- | lib/python/debian_support.py | 127 |
1 files changed, 25 insertions, 102 deletions
diff --git a/lib/python/debian_support.py b/lib/python/debian_support.py index 0167707e0e..eb16311b25 100644 --- a/lib/python/debian_support.py +++ b/lib/python/debian_support.py @@ -22,11 +22,8 @@ import re import sha import types -try: - import apt_pkg - __have_apt_pkg = True -except ImportError: - __have_apt_pkg = False +import apt_pkg +apt_pkg.init() class ParseError(Exception): """An exception which is used to signal a parse failure. @@ -58,104 +55,30 @@ class ParseError(Exception): file.write("%s:%d: %s\n" % (self.filename, self.lineno, self.msg)) file.flush() -if __have_apt_pkg: - class Version: - """Version class which uses the original APT comparison algorithm.""" - - def __init__(self, version): - """Creates a new Version object.""" - t = type(version) - if t == types.UnicodeType: - version = version.encode('UTF-8') - else: - assert t == types.StringType, `version` - assert version <> "" - self.__asString = version - - def __str__(self): - return self.__asString - - def __repr__(self): - return 'Version(%s)' % `self.__asString` - - def __cmp__(self, other): - return apt_pkg.VersionCompare(self.__asString, other.__asString) - - - version_compare = apt_pkg.VersionCompare - apt_pkg.init() - -else: - letterValue = [None] * 256 - def initLetterValue(): - c = 0 - for x in range(ord('A'), ord('Z') + 1): - letterValue[x] = chr(c) - c += 1 - for x in range(ord('a'), ord('z') + 1): - letterValue[x] = chr(c) - c += 1 - for x in "+-.:": - letterValue[ord(x)] = chr(c) - c += 1 - initLetterValue() - del initLetterValue - - class Version: - """This class implements Debian version numbers.""" - - def __init__(self, version): - """Creates a new Version object.""" - assert type(version) == types.StringType, `version` - assert version <> "" - self.__asString = version - self.__parsed = self.__parse(version) - - def __str__(self): - return self.__asString - - def __repr__(self): - return 'Version(%s)' % `self.__asString` - - def __cmp__(self, other): - """Compares two versions. - - This method implements the algorithm in the Debian Policy.""" - return cmp(self.__parsed, other.__parsed) - - def __parse(self, v, regexp=\ - re.compile(r'^(?:(\d+):)?([A-Za-z0-9.+~:-]+?)' - + r'(?:-([A-Za-z0-9.+~]+))?$')): - match = regexp.match(v) - if match is None: - raise ValueError, "invalid Debian version string" - (epoch, upstream, debian) = match.groups() - if epoch is None: - epoch = 0 - else: - epoch = int(epoch) - return (epoch, self.__parse_1(upstream), self.__parse_1(debian)) - - def __parse_1(self, x, non_digits=re.compile(r'^([^0-9]*)(.*)$'), - digits=re.compile(r'^([0-9]*)(.*)$')): - l = [] - while x is not None and x <> '': - (nd, x) = non_digits.match(x).groups() - (d, x) = digits.match(x).groups() - nd_l = [] - for ch in nd: - nd_l.append(letterValue[ord(ch)]) - nd = ''.join(nd_l) - if d == '': - d = 0 - else: - d = int(d) - l.append(nd) - l.append(d) - return l +class Version: + """Version class which uses the original APT comparison algorithm.""" + + def __init__(self, version): + """Creates a new Version object.""" + t = type(version) + if t == types.UnicodeType: + version = version.encode('UTF-8') + else: + assert t == types.StringType, `version` + assert version <> "" + self.__asString = version + + def __str__(self): + return self.__asString + + def __repr__(self): + return 'Version(%s)' % `self.__asString` + + def __cmp__(self, other): + return apt_pkg.VersionCompare(self.__asString, other.__asString) + - def version_compare(a,b): - return cmp(Version(a), Version(b)) +version_compare = apt_pkg.VersionCompare class PackageFile: """A Debian package file. |