From 0cb44e7c914bf98d92a85d83b0bdc15ebc73525d Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Thu, 30 Jul 2009 17:44:49 +0200 Subject: apt/package.py: Make comparisons of Version object more robust. --- apt/package.py | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) (limited to 'apt') diff --git a/apt/package.py b/apt/package.py index f5bdc47d..0b8d4bf8 100644 --- a/apt/package.py +++ b/apt/package.py @@ -189,17 +189,47 @@ class Version(object): self.package = package self._cand = cand + def _cmp(self, other): + try: + return apt_pkg.VersionCompare(self._cand.VerStr, other.version) + except AttributeError: + return apt_pkg.VersionCompare(self._cand.VerStr, other) + def __eq__(self, other): - return self._cand.ID == other._cand.ID + try: + return self._cmp(other) == 0 + except TypeError: + return NotImplemented + + def __ge__(self): + try: + return self._cmp(other) >= 0 + except TypeError: + return NotImplemented def __gt__(self, other): - return apt_pkg.VersionCompare(self.version, other.version) > 0 + try: + return self._cmp(other) > 0 + except TypeError: + return NotImplemented + + def __le__(self): + try: + return self._cmp(other) <= 0 + except TypeError: + return NotImplemented def __lt__(self, other): - return apt_pkg.VersionCompare(self.version, other.version) < 0 + try: + return self._cmp(other) < 0 + except TypeError: + return NotImplemented def __ne__(self, other): - return not self.__eq__(other) + try: + return self._cmp(other) != 0 + except TypeError: + return NotImplemented def __hash__(self): return self._cand.Hash @@ -488,7 +518,7 @@ class Package(object): def candidate(self): """Return the candidate version of the package. - + This property is writeable to allow you to set the candidate version of the package. Just assign a Version() object, and it will be set as the candidate version. -- cgit v1.2.3 From e1fe8a0fdc56452f820c837a323729d93f57f581 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Thu, 30 Jul 2009 17:49:35 +0200 Subject: Return VersionList objects in Package.versions, which are sequences and also provide features of mappings. (partial API BREAK) --- apt/package.py | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- debian/changelog | 2 ++ 2 files changed, 85 insertions(+), 3 deletions(-) (limited to 'apt') diff --git a/apt/package.py b/apt/package.py index 0b8d4bf8..73ca5da0 100644 --- a/apt/package.py +++ b/apt/package.py @@ -29,11 +29,16 @@ import subprocess import urllib2 import warnings +try: + from collections import Sequence +except ImportError: + Sequence = object + import apt_pkg import apt.progress __all__ = ('BaseDependency', 'Dependency', 'Origin', 'Package', 'Record', - 'Version') + 'Version', 'VersionList') def _(string): @@ -499,6 +504,81 @@ class Version(object): return os.path.abspath(dsc) +class VersionList(Sequence): + """Provide a mapping & sequence interface to all versions of a package. + + This class can be used like a dictionary, where version strings are the + keys. It can also be used as a sequence, where integers are the keys. + + You can also convert this to a dictionary or a list, using the usual way + of dict(version_list) or list(version_list). This is useful if you need + to access the version objects multiple times, because they do not have to + be recreated this way. + + Examples ('package.versions' being a version list): + '0.7.92' in package.versions # Check whether 0.7.92 is a valid version. + package.versions[0] # Return first version or raise IndexError + package.versions[0:2] # Return a new VersionList for objects 0-2 + package.versions['0.7.92'] # Return version 0.7.92 or raise KeyError + package.versions.keys() # All keys, as strings. + max(package.versions) + """ + + def __init__(self, package, slice=None): + self._package = package # apt.package.Package() + self._versions = package._pkg.VersionList # [apt_pkg.Version(), ...] + if slice: + self._versions = self._versions[slice] + + def __getitem__(self, item): + if isinstance(item, slice): + return self.__class__(self._package, item) + try: + # Sequence interface, item is an integer + return Version(self._package, self._versions[item]) + except TypeError: + # Dictionary interface item is a string. + for ver in self._versions: + if ver.ver_str == item: + return Version(self._package, ver) + raise KeyError("Version: %r not found." % (item)) + + def __repr__(self): + return '' % self.keys() + + def __iter__(self): + """Return an iterator over all value objects.""" + return (Version(self._package, ver) for ver in self._versions) + + def __contains__(self, item): + if isinstance(item, Version): # Sequence interface + item = item.version + # Dictionary interface. + for ver in self._versions: + if ver.ver_str == item: + return True + return False + + def __eq__(self, other): + return list(self) == list(other) + + def __len__(self): + return len(self._versions) + + # Mapping interface + + def keys(self): + """Return a list of all versions, as strings.""" + return [ver.VerStr for ver in self._versions] + + def get(self, key, default=None): + """Return the key or the default.""" + try: + return self[key] + except LookupError: + return default + + class Package(object): """Representation of a package in a cache. @@ -911,11 +991,11 @@ class Package(object): @property def versions(self): - """Return a list of versions. + """Return a VersionList() object for all available versions. :since: 0.7.9 """ - return [Version(self, ver) for ver in self._pkg.VersionList] + return VersionList(self) # depcache actions diff --git a/debian/changelog b/debian/changelog index 122ebe92..c4ba63fc 100644 --- a/debian/changelog +++ b/debian/changelog @@ -19,6 +19,8 @@ python-apt (0.7.12.0) unstable; urgency=low + Support assignments to the 'candidate' property of Package objects. + Initial patch by Sebastian Heinlein - Make comparisons of Version object more robust. + - Return VersionList objects in Package.versions, which are sequences + and also provide features of mappings. (partial API BREAK) * Use debhelper 7 instead of CDBS [ Stefano Zacchiroli ] -- cgit v1.2.3 From bb517c1da9e82d36b2c599f308d5451be68fadcb Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Thu, 30 Jul 2009 18:29:13 +0200 Subject: apt/progress/__init__.py: Fix InstallProgress.waitChild() - Do not break out of InstallProgress.waitChild()'s loop just because it is hitting EINTR, but only on child exit or on ECHILD. --- apt/progress/__init__.py | 5 +++-- debian/changelog | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'apt') diff --git a/apt/progress/__init__.py b/apt/progress/__init__.py index b9288c2c..337bd161 100644 --- a/apt/progress/__init__.py +++ b/apt/progress/__init__.py @@ -112,7 +112,7 @@ class FetchProgress(object): This happens eg. when the downloads fails or is completed. """ - def update_status_full(self, uri, descr, short_descr, status, file_size, + def update_status_full(self, uri, descr, short_descr, status, file_size, partial_size): """Called when the status of an item changes. @@ -291,7 +291,6 @@ class InstallProgress(DumbInstallProgress): except select.error, (errno_, errstr): if errno_ != errno.EINTR: raise - break self.updateInterface() try: (pid, res) = os.waitpid(self.child_pid, os.WNOHANG) @@ -300,6 +299,8 @@ class InstallProgress(DumbInstallProgress): except OSError, (errno_, errstr): if errno_ != errno.EINTR: raise + if errno_ == errno.ECHILD: + break return res def run(self, pm): diff --git a/debian/changelog b/debian/changelog index c2d30cf9..49c74106 100644 --- a/debian/changelog +++ b/debian/changelog @@ -22,6 +22,9 @@ python-apt (0.7.12.0) unstable; urgency=low - Return VersionList objects in Package.versions, which are sequences and also provide features of mappings. (partial API BREAK) + Allows to get a specific version (Closes: #523998) + * apt/progress/__init__.py: + - Do not break out of InstallProgress.waitChild()'s loop just because it + is hitting EINTR, but only on child exit or on ECHILD. * Use debhelper 7 instead of CDBS [ Stefano Zacchiroli ] -- cgit v1.2.3 From 057b8847b0645f501c34662ba60313cb4792b992 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Fri, 31 Jul 2009 12:39:17 +0200 Subject: * apt/package.py: Add missing argument to Version.__le__() and Version.__ge__() --- apt/package.py | 4 ++-- debian/changelog | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) (limited to 'apt') diff --git a/apt/package.py b/apt/package.py index 73ca5da0..308bd223 100644 --- a/apt/package.py +++ b/apt/package.py @@ -206,7 +206,7 @@ class Version(object): except TypeError: return NotImplemented - def __ge__(self): + def __ge__(self, other): try: return self._cmp(other) >= 0 except TypeError: @@ -218,7 +218,7 @@ class Version(object): except TypeError: return NotImplemented - def __le__(self): + def __le__(self, other): try: return self._cmp(other) <= 0 except TypeError: diff --git a/debian/changelog b/debian/changelog index 49c74106..ca1227d0 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +python-apt (0.7.12.1) UNRELEASED; urgency=low + + * apt/package.py: + - Add missing argument to Version.__le__() and Version.__ge__() + + -- Julian Andres Klode Fri, 31 Jul 2009 12:38:18 +0200 + python-apt (0.7.12.0) unstable; urgency=low [ Julian Andres Klode ] -- cgit v1.2.3 From c3b546fad60e0d0afa99bab32b1669592c457d4e Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Mon, 3 Aug 2009 12:35:03 +0200 Subject: * apt/debfile.py: Fix missing space in message (Closes: #539704) --- apt/debfile.py | 2 +- debian/changelog | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'apt') diff --git a/apt/debfile.py b/apt/debfile.py index 0406a250..0e455508 100644 --- a/apt/debfile.py +++ b/apt/debfile.py @@ -78,7 +78,7 @@ class DebPackage(object): member) break except SystemError: - return [_("List of files for '%s'could not be read" % + return [_("List of files for '%s' could not be read" % self.filename)] return files diff --git a/debian/changelog b/debian/changelog index a7cf71a3..9595128c 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,5 +1,7 @@ python-apt (0.7.12.1) UNRELEASED; urgency=low + * apt/debfile.py: + - Fix missing space in message (Closes: #539704) * apt/package.py: - Add missing argument to Version.__le__() and Version.__ge__() * debian/control: -- cgit v1.2.3