From: "Michał Górny" <mgorny@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/gentoopm:master commit in: gentoopm/basepm/
Date: Sat, 23 Jul 2011 09:27:43 +0000 (UTC) [thread overview]
Message-ID: <c8215544b599af6015c0a8f92345492b3288a5d6.mgorny@gentoo> (raw)
commit: c8215544b599af6015c0a8f92345492b3288a5d6
Author: Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Sat Jul 23 08:34:10 2011 +0000
Commit: Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Sat Jul 23 08:34:10 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoopm.git;a=commit;h=c8215544
PMPackageSet: introduce .sorted property.
---
gentoopm/basepm/pkgset.py | 34 +++++++++++++++++++++++++++-------
1 files changed, 27 insertions(+), 7 deletions(-)
diff --git a/gentoopm/basepm/pkgset.py b/gentoopm/basepm/pkgset.py
index be8b9b2..b301968 100644
--- a/gentoopm/basepm/pkgset.py
+++ b/gentoopm/basepm/pkgset.py
@@ -55,15 +55,15 @@ class PMPackageSet(ABCObject, BoolCompat):
match the condition
"""
- l = sorted(self, reverse = True)
- try:
- best = l[0]
- except IndexError:
+ best = None
+ for p in self.sorted:
+ if best is not None and p.key != best.key:
+ raise AmbiguousPackageSetError('.best called on a set of differently-named packages')
+ best = p
+
+ if best is None:
raise EmptyPackageSetError('.best called on an empty set')
- for p in l:
- if p.key != best.key:
- raise AmbiguousPackageSetError('.best called on a set of differently-named packages')
return best
def select(self, *args, **kwargs):
@@ -90,6 +90,19 @@ class PMPackageSet(ABCObject, BoolCompat):
except AmbiguousPackageSetError:
raise AmbiguousPackageSetError('Ambiguous filter (matches more than a single package name).')
+ @property
+ def sorted(self):
+ """
+ Return a sorted variant of the package set. The packages will be sorted
+ in a standard PM manner, with better packages coming later. The key
+ ordering is undefined, although usually they will come sorted
+ lexically.
+
+ @return: sorted package set
+ @rtype: L{PMSortedPackageSet}
+ """
+ return PMSortedPackageSet(self)
+
def __getitem__(self, filt):
"""
Select a single package matching an atom (or filter). Unlike L{select()},
@@ -161,3 +174,10 @@ class PMFilteredPackageSet(PMPackageSet):
for el in self._src:
if el._matches(*self._args, **self._kwargs):
yield el
+
+class PMSortedPackageSet(PMPackageSet):
+ def __init__(self, src):
+ self._src = src
+
+ def __iter__(self):
+ return iter(sorted(self._src))
next reply other threads:[~2011-07-23 9:27 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-23 9:27 Michał Górny [this message]
-- strict thread matches above, loose matches on Subject: below --
2015-08-07 9:18 [gentoo-commits] proj/gentoopm:master commit in: gentoopm/basepm/ Michał Górny
2013-08-05 16:04 Michał Górny
2011-12-24 9:18 Michał Górny
2011-09-10 8:28 Michał Górny
2011-08-15 8:48 Michał Górny
2011-08-15 8:48 Michał Górny
2011-08-15 7:57 Michał Górny
2011-08-13 9:17 Michał Górny
2011-08-12 20:38 Michał Górny
2011-08-12 17:43 Michał Górny
2011-07-28 16:24 Michał Górny
2011-07-26 20:10 Michał Górny
2011-07-26 20:10 Michał Górny
2011-07-26 16:36 Michał Górny
2011-07-26 7:24 Michał Górny
2011-07-25 17:33 Michał Górny
2011-07-25 17:33 Michał Górny
2011-07-25 17:06 Michał Górny
2011-07-24 20:05 Michał Górny
2011-07-23 9:27 Michał Górny
2011-07-21 8:47 Michał Górny
2011-07-20 9:41 Michał Górny
2011-07-17 22:39 Michał Górny
2011-07-17 22:10 Michał Górny
2011-07-17 22:10 Michał Górny
2011-07-17 22:10 Michał Górny
2011-07-17 9:09 Michał Górny
2011-07-15 23:56 Michał Górny
2011-07-15 23:56 Michał Górny
2011-07-15 22:24 Michał Górny
2011-07-15 22:24 Michał Górny
2011-07-15 22:24 Michał Górny
2011-07-15 13:32 Michał Górny
2011-07-15 12:34 Michał Górny
2011-07-15 12:34 Michał Górny
2011-07-15 12:34 Michał Górny
2011-07-15 9:52 Michał Górny
2011-07-15 9:52 Michał Górny
2011-07-14 22:51 Michał Górny
2011-07-14 13:31 Michał Górny
2011-07-14 13:31 Michał Górny
2011-07-14 13:31 Michał Górny
2011-07-13 16:30 Michał Górny
2011-07-13 16:09 Michał Górny
2011-07-11 9:39 Michał Górny
2011-07-11 9:39 Michał Górny
2011-07-10 12:34 Michał Górny
2011-07-08 12:49 Michał Górny
2011-07-08 12:49 Michał Górny
2011-07-07 12:52 Michał Górny
2011-07-07 12:52 Michał Górny
2011-07-07 12:52 Michał Górny
2011-07-07 9:51 Michał Górny
2011-07-06 20:54 Michał Górny
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c8215544b599af6015c0a8f92345492b3288a5d6.mgorny@gentoo \
--to=mgorny@gentoo.org \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox