From f17fc818cca41668bb6358e490ff3278e64fa493 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 5 Oct 2011 10:32:04 +0200 Subject: * tests/test_apt_cache.py: - add __cmp__ to apt.Package so that sort() sorts by name on list of package objects --- apt/package.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'apt/package.py') diff --git a/apt/package.py b/apt/package.py index 4104f93e..cb373c2e 100644 --- a/apt/package.py +++ b/apt/package.py @@ -707,6 +707,9 @@ class Package(object): return '' % (self._pkg.name, self._pkg.architecture, self._pkg.id) + def __cmp__(self, other): + return cmp(self.name, other.name) + def candidate(self): """Return the candidate version of the package. -- cgit v1.2.3 From f2cd844828de310dc510505612395ef60ded8731 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 17 Nov 2011 16:46:53 +0100 Subject: * apt/package.py: - add new "suggests" property, thanks to Christop Groth --- apt/package.py | 5 +++++ debian/changelog | 2 ++ 2 files changed, 7 insertions(+) (limited to 'apt/package.py') diff --git a/apt/package.py b/apt/package.py index cb373c2e..e09acca4 100644 --- a/apt/package.py +++ b/apt/package.py @@ -454,6 +454,11 @@ class Version(object): """Return the recommends of the package version.""" return self.get_dependencies("Recommends") + @property + def suggests(self): + """Return the suggests of the package version.""" + return self.get_dependencies("Suggests") + @property def origins(self): """Return a list of origins for the package version.""" diff --git a/debian/changelog b/debian/changelog index 14ee705e..afffdf12 100644 --- a/debian/changelog +++ b/debian/changelog @@ -22,6 +22,8 @@ python-apt (0.8.2) UNRELEASED; urgency=low * apt/cache.py: - set Dir::bin::dpkg if a alternate rootdir is given (LP: #885895) + * apt/package.py: + - add new "suggests" property, thanks to Christop Groth [ Tshepang Lekhonkhobe ] * rm usage of camelcase in cache.py doc (closes: #626617) -- cgit v1.2.3 From add08632b8a66c7ba5de7ab44d8a10ec9462692e Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 17 Nov 2011 17:57:34 +0100 Subject: allow Dependency object to be iteratable, this allows to write code like: for or_dep_group in pkg.candidate.dependencies: for dep in or_dep_group: do_something() --- apt/package.py | 3 +++ debian/changelog | 4 ++++ tests/test_apt_cache.py | 4 ++-- 3 files changed, 9 insertions(+), 2 deletions(-) (limited to 'apt/package.py') diff --git a/apt/package.py b/apt/package.py index e09acca4..ab692788 100644 --- a/apt/package.py +++ b/apt/package.py @@ -107,6 +107,9 @@ class Dependency(object): def __repr__(self): return repr(self.or_dependencies) + def __iter__(self): + return self.or_dependencies.__iter__() + class DeprecatedProperty(property): """A property which gives DeprecationWarning on access. diff --git a/debian/changelog b/debian/changelog index afffdf12..7d939702 100644 --- a/debian/changelog +++ b/debian/changelog @@ -24,6 +24,10 @@ python-apt (0.8.2) UNRELEASED; urgency=low (LP: #885895) * apt/package.py: - add new "suggests" property, thanks to Christop Groth + - allow Dependency object to be iteratable, this allows to write + code like: + for or_dep_group in pkg.candidate.dependencies: + for dep in or_dep_group: do_something() [ Tshepang Lekhonkhobe ] * rm usage of camelcase in cache.py doc (closes: #626617) diff --git a/tests/test_apt_cache.py b/tests/test_apt_cache.py index 0d80f617..7784a25f 100644 --- a/tests/test_apt_cache.py +++ b/tests/test_apt_cache.py @@ -55,8 +55,8 @@ class TestAptCache(unittest.TestCase): # that is possible and does not crash for pkg in cache: if pkg.candidate: - for or_dep in pkg.candidate.dependencies: - for dep in or_dep.or_dependencies: + for or_deps in pkg.candidate.dependencies: + for dep in or_deps: self.assertTrue(dep.name) self.assertTrue(isinstance(dep.relation, str)) self.assertTrue(dep.pre_depend in (True, False)) -- cgit v1.2.3 From a01e314df3ceaf0cc99102beb511a2ecbd973057 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 17 Nov 2011 20:28:10 +0100 Subject: make Dependency a list (it should probably also renamed to DependencyOrGroup or something), thanks to Christop Groth --- apt/package.py | 14 ++++++-------- debian/changelog | 4 +++- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'apt/package.py') diff --git a/apt/package.py b/apt/package.py index ab692788..8b79c420 100644 --- a/apt/package.py +++ b/apt/package.py @@ -94,7 +94,7 @@ class BaseDependency(object): preDepend = AttributeDeprecatedBy('pre_depend') -class Dependency(object): +class Dependency(list): """Represent an Or-group of dependencies. Attributes defined here: @@ -102,14 +102,12 @@ class Dependency(object): """ def __init__(self, alternatives): - self.or_dependencies = alternatives - - def __repr__(self): - return repr(self.or_dependencies) - - def __iter__(self): - return self.or_dependencies.__iter__() + super(Dependency, self).__init__() + self.extend(alternatives) + @property + def or_dependencies(self): + return self class DeprecatedProperty(property): """A property which gives DeprecationWarning on access. diff --git a/debian/changelog b/debian/changelog index 7d939702..6e750980 100644 --- a/debian/changelog +++ b/debian/changelog @@ -27,7 +27,9 @@ python-apt (0.8.2) UNRELEASED; urgency=low - allow Dependency object to be iteratable, this allows to write code like: for or_dep_group in pkg.candidate.dependencies: - for dep in or_dep_group: do_something() + for dep in or_dep_group: + do_something() + (thanks to Christop Groth) [ Tshepang Lekhonkhobe ] * rm usage of camelcase in cache.py doc (closes: #626617) -- cgit v1.2.3 From fb4ef05de0a64f75f2896d9e74c88a3bb3db00c7 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 22 Nov 2011 18:36:46 +0100 Subject: apt/package.py: use lt() instead of cmp() --- apt/package.py | 4 ++-- debian/changelog | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'apt/package.py') diff --git a/apt/package.py b/apt/package.py index cb373c2e..45d6044b 100644 --- a/apt/package.py +++ b/apt/package.py @@ -707,8 +707,8 @@ class Package(object): return '' % (self._pkg.name, self._pkg.architecture, self._pkg.id) - def __cmp__(self, other): - return cmp(self.name, other.name) + def __lt__(self, other): + return self.name < other.name def candidate(self): """Return the candidate version of the package. diff --git a/debian/changelog b/debian/changelog index cc922735..fece12fb 100644 --- a/debian/changelog +++ b/debian/changelog @@ -18,7 +18,7 @@ python-apt (0.8.2) UNRELEASED; urgency=low * apt/cache.py: - remove "print" when creating dirs in apt.Cache(rootdir=dir), thanks to Martin Pitt - - add __cmp__ to apt.Package so that sort() sorts by name + - add __lt__ to apt.Package so that sort() sorts by name on list of package objects * debian/control: - add recommends to xz-lzma to ensure we have the unlzma command -- cgit v1.2.3