From: "Michał Górny" <mgorny@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/gentoopm:master commit in: gentoopm/basepm/
Date: Thu, 7 Jul 2011 09:51:32 +0000 (UTC) [thread overview]
Message-ID: <5ef78b31ae1493ed1ccffb2cb6a6640f8d051bbf.mgorny@gentoo> (raw)
commit: 5ef78b31ae1493ed1ccffb2cb6a6640f8d051bbf
Author: Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Thu Jul 7 08:43:02 2011 +0000
Commit: Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Thu Jul 7 08:43:02 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoopm.git;a=commit;h=5ef78b31
Update filtering description/API.
---
gentoopm/basepm/pkg.py | 43 +++++++++++++++++++++----------------------
1 files changed, 21 insertions(+), 22 deletions(-)
diff --git a/gentoopm/basepm/pkg.py b/gentoopm/basepm/pkg.py
index 4c71c62..8f94833 100644
--- a/gentoopm/basepm/pkg.py
+++ b/gentoopm/basepm/pkg.py
@@ -17,21 +17,19 @@ class PMPackageSet(ABCObject):
def filter(self, *args, **kwargs):
"""
- Filter the packages based on keys passed as arguments. Positional
- arguments refer to keys by their level (with first arg being the
- top-level key), None means match-all. Keyword arguments refer to keys
- by their names.
+ Filter the packages based on arguments. Return a PMFilteredPackageSet
+ evaluating to a number of PMPackages.
- If an argument doesn't match any key (i.e. too many args are passed),
- a KeyError or IndexError will be raised. If the same key is referred
- through positional and keyword arguments, a TypeError will be raised.
+ The positional arguments can provide a number of PMPackageMatchers (see
+ gentoopm.basepm.filter) and/or an atom string. The keyword arguments
+ match metadata keys using '==' comparison with passed values (objects).
- The filtering will result in an iterable of PMKeyedPackageDicts
- or PMPackages, depending on whether the filtering criteria are able
- to uniquely identify packages.
+ Multiple filters will be AND-ed together. Same applies for .filter()
+ called multiple times. You should, however, avoid passing multiple
+ atoms as it is not supported by all PMs.
- The '==' operator is used to match packages. To extend matching, you
- can provide a class with __eq__() redefined as an argument.
+ This function can raise KeyError when a keyword argument does reference
+ an incorrect metadata key.
"""
return PMFilteredPackageSet(iter(self), args, kwargs)
@@ -70,8 +68,8 @@ class PMFilteredPackageSet(PMPackageSet):
def __iter__(self):
for el in self._iter:
- for x in el.filter(*self._args, **self._kwargs):
- yield x
+ if el._matches(*self._args, **self._kwargs):
+ yield el
class PMPackage(ABCObject):
"""
@@ -79,16 +77,17 @@ class PMPackage(ABCObject):
in the package tree.
"""
- def filter(self, **kwargs):
+ def _matches(self, *args, **kwargs):
"""
- Filter packages on metadata. This is mostly to extend superclass
- .filter() method.
+ Check whether the package matches passed filters. Please note that this
+ method may not be called at all if PM is capable of a more efficient
+ filtering.
- If args are non-empty, raises an IndexError (unused args). If kwargs
- contains keys not matching metadata, raises a KeyError. Otherwise,
- returns an iterator -- either over the package itself or an empty one.
+ If kwargs reference incorrect metadata keys, a KeyError will be raised.
"""
+ # XXX: apply filters
+
for k, m in kwargs.items():
try:
v = self.metadata[k]
@@ -96,9 +95,9 @@ class PMPackage(ABCObject):
raise KeyError('Unmatched keyword argument: %s' % k)
else:
if not m == v:
- return
+ return False
- yield self
+ return True
@abstractproperty
def id(self):
next reply other threads:[~2011-07-07 9:51 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-07 9:51 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-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-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=5ef78b31ae1493ed1ccffb2cb6a6640f8d051bbf.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