Commits

Michał Górny  committed a10932d

Add an attribute-matching package filter.

  • Participants
  • Parent commits 40bbcf2

Comments (0)

Files changed (2)

File gentoopm/basepm/filter.py

 			raise KeyError('Invalid keyword argument: %s' % self._k)
 
 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 = SmartAttrGetter(key)
 		self._val = val

File gentoopm/filters.py

+#!/usr/bin/python
+#	vim:fileencoding=utf-8
+# (c) 2011 Michał Górny <mgorny@gentoo.org>
+# 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 = attrgetter(key)
+		self._val = val
+
+	def __call__(self, pkg):
+		return self._val == self._getter(pkg)