aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Varner <fuzzyray@gentoo.org>2013-01-04 22:16:36 (GMT)
committerPaul Varner <fuzzyray@gentoo.org>2013-01-04 22:16:36 (GMT)
commitde264bbe75fe45ff7d457343a8a8a5f96cd14a7f (patch)
treefdaea8b80ef2452b87f98f9cac675ce753ae4883
parentFix unicode error when printing unicode strings in set_version. (diff)
downloadgentoolkit-de264bbe75fe45ff7d457343a8a8a5f96cd14a7f.zip
gentoolkit-de264bbe75fe45ff7d457343a8a8a5f96cd14a7f.tar.gz
gentoolkit-de264bbe75fe45ff7d457343a8a8a5f96cd14a7f.tar.bz2
Fix regular expression queries to work properly. (Bug 447406)
There were two issues in the code: 1. query.py was trying to treat regular expressions as CPVs 2. helpers.py get_cpv functions were applying the predicate to only the CPs and not all of the CPVs
-rw-r--r--pym/gentoolkit/helpers.py52
-rw-r--r--pym/gentoolkit/query.py15
2 files changed, 36 insertions, 31 deletions
diff --git a/pym/gentoolkit/helpers.py b/pym/gentoolkit/helpers.py
index 637d3a7..55fecdb 100644
--- a/pym/gentoolkit/helpers.py
+++ b/pym/gentoolkit/helpers.py
@@ -386,17 +386,15 @@ def get_cpvs(predicate=None, include_installed=True):
Portage tree
"""
- if predicate:
- all_cps = iter(
- x for x
- in portage.db[portage.root]["porttree"].dbapi.cp_all()
- if predicate(x))
- else:
- all_cps = portage.db[portage.root]["porttree"].dbapi.cp_all()
+ if not predicate:
+ predicate = lambda x: x
+
+ all_cps = portage.db[portage.root]["porttree"].dbapi.cp_all()
- all_cpvs = chain.from_iterable(
+ all_cpvs = iter(x for x in chain.from_iterable(
portage.db[portage.root]["porttree"].dbapi.cp_list(x)
- for x in all_cps)
+ for x in all_cps) if predicate(x))
+
all_installed_cpvs = set(get_installed_cpvs(predicate))
if include_installed:
@@ -427,18 +425,16 @@ def get_installed_cpvs(predicate=None):
from VARDB
"""
- if predicate:
- installed_cps = iter(
- x for x
- in portage.db[portage.root]["vartree"].dbapi.cp_all()
- if predicate(x))
- else:
- installed_cps = (
- portage.db[portage.root]["vartree"].dbapi.cp_all())
+ if not predicate:
+ predicate = lambda x: x
+
+ installed_cps = portage.db[portage.root]["vartree"].dbapi.cp_all()
- for cpv in chain.from_iterable(
+ installed_cpvs = iter(x for x in chain.from_iterable(
portage.db[portage.root]["vartree"].dbapi.cp_list(x)
- for x in installed_cps):
+ for x in installed_cps) if predicate(x))
+
+ for cpv in installed_cpvs:
yield cpv
@@ -452,18 +448,16 @@ def get_bintree_cpvs(predicate=None):
from BINDB
"""
- if predicate:
- installed_cps = iter(
- x for x
- in portage.db[portage.root]["bintree"].dbapi.cp_all()
- if predicate(x))
- else:
- installed_cps = (
- portage.db[portage.root]["bintree"].dbapi.cp_all())
+ if not predicate:
+ predicate = lambda x: x
- for cpv in chain.from_iterable(
+ installed_cps = portage.db[portage.root]["bintree"].dbapi.cp_all()
+
+ installed_cpvs = iter(x for x in chain.from_iterable(
portage.db[portage.root]["bintree"].dbapi.cp_list(x)
- for x in installed_cps):
+ for x in installed_cps) if predicate(x))
+
+ for cpv in installed_cpvs:
yield cpv
diff --git a/pym/gentoolkit/query.py b/pym/gentoolkit/query.py
index cd8efcc..c0ce977 100644
--- a/pym/gentoolkit/query.py
+++ b/pym/gentoolkit/query.py
@@ -89,7 +89,11 @@ class Query(CPV):
cat_str = ""
pkg_str = pp.emph(self.query)
else:
- cat, pkg = self.category, self.name + self.fullversion
+ try:
+ cat, pkg = self.category, self.name + self.fullversion
+ except errors.GentoolkitInvalidCPV:
+ cat = ''
+ pkg = self.atom
if cat and not self.is_regex:
cat_str = "in %s " % pp.emph(cat.lstrip('><=~!'))
else:
@@ -303,7 +307,10 @@ class Query(CPV):
if show_progress and not CONFIG["piping"]:
self.print_summary()
- cat = CPV(self.query).category
+ try:
+ cat = CPV(self.query).category
+ except errors.GentoolkitInvalidCPV:
+ cat = ''
pre_filter = []
# The "get_" functions can pre-filter against the whole package key,
@@ -322,6 +329,10 @@ class Query(CPV):
# Post-filter
if self.is_regex:
+ try:
+ re.compile(self.query)
+ except re.error:
+ raise errors.GentoolkitInvalidRegex(self.query)
predicate = lambda x: re.search(self.query, x)
else:
if cat: