From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1Qry1O-0006Vc-6o for garchives@archives.gentoo.org; Fri, 12 Aug 2011 20:07:58 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 0C5D521C206; Fri, 12 Aug 2011 20:07:48 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id D209B21C206 for ; Fri, 12 Aug 2011 20:07:48 +0000 (UTC) Received: from pelican.gentoo.org (unknown [66.219.59.40]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 6791C1B405D for ; Fri, 12 Aug 2011 20:07:43 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id B9CAE80043 for ; Fri, 12 Aug 2011 20:07:42 +0000 (UTC) From: "Michał Górny" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Michał Górny" Message-ID: Subject: [gentoo-commits] proj/gentoopm:master commit in: gentoopm/, gentoopm/basepm/ X-VCS-Repository: proj/gentoopm X-VCS-Files: gentoopm/basepm/filter.py gentoopm/filters.py X-VCS-Directories: gentoopm/ gentoopm/basepm/ X-VCS-Committer: mgorny X-VCS-Committer-Name: Michał Górny X-VCS-Revision: a10932ded1ada106719b9265a00673e4114fcaae Date: Fri, 12 Aug 2011 20:07:42 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: X-Archives-Hash: 973aa8589be3f14a5e08d6e38e65639e commit: a10932ded1ada106719b9265a00673e4114fcaae Author: Micha=C5=82 G=C3=B3rny gentoo org> AuthorDate: Fri Aug 12 20:07:16 2011 +0000 Commit: Micha=C5=82 G=C3=B3rny gentoo org> CommitDate: Fri Aug 12 20:07:16 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/gentoopm.git;= a=3Dcommit;h=3Da10932de Add an attribute-matching package filter. --- gentoopm/basepm/filter.py | 2 ++ gentoopm/filters.py | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 0 deletions(-) diff --git a/gentoopm/basepm/filter.py b/gentoopm/basepm/filter.py index 9c66b6c..0851d84 100644 --- a/gentoopm/basepm/filter.py +++ b/gentoopm/basepm/filter.py @@ -81,6 +81,8 @@ class SmartAttrGetter(object): raise KeyError('Invalid keyword argument: %s' % self._k) =20 class PMTransformedKeywordFilter(PMPackageMatcher): + # XXX: transform this to subclass of ..filters.AttributeMatch + # hardcode 'foo_bar' -> 'foo.bar' mappings instead of doing magic def __init__(self, key, val): self._getter =3D SmartAttrGetter(key) self._val =3D val diff --git a/gentoopm/filters.py b/gentoopm/filters.py new file mode 100644 index 0000000..53f1826 --- /dev/null +++ b/gentoopm/filters.py @@ -0,0 +1,20 @@ +#!/usr/bin/python +# vim:fileencoding=3Dutf-8 +# (c) 2011 Micha=C5=82 G=C3=B3rny +# Released under the terms of the 2-clause BSD license. + +from operator import attrgetter + +from .basepm.filter import PMPackageMatcher + +class AttributeMatch(PMPackageMatcher): + """ + A filter matching package attributes with values. + """ + + def __init__(self, key, val): + self._getter =3D attrgetter(key) + self._val =3D val + + def __call__(self, pkg): + return self._val =3D=3D self._getter(pkg)