aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfuzzyray <fuzzyray@gentoo.org>2010-09-22 21:51:32 +0000
committerfuzzyray <fuzzyray@gentoo.org>2010-09-22 21:51:32 +0000
commite12c500456f3a03a45a217a1e13a732f28294289 (patch)
treef7252a9df20ecbb34e3760700a24dca66a719c80 /pym/gentoolkit/query.py
parentMerge from genscripts r446: brian.dolbec (diff)
downloadgentoolkit-e12c500456f3a03a45a217a1e13a732f28294289.tar.gz
gentoolkit-e12c500456f3a03a45a217a1e13a732f28294289.tar.bz2
gentoolkit-e12c500456f3a03a45a217a1e13a732f28294289.zip
Merge from genscripts r459: douglasjanderson
Fixing a traceback when Query is passed an invalid atom, and merging some _incomplete_ work on has.py Merge from genscripts r454: brian.dolbec make the needed changes to fix bug 114086 in the has module. Merge from genscripts r452: douglasjanderson gentoolkit.query.Query can't subclass gentoolkit.atom.Atom because we can't control what portage.dep.Atom takes as input. Merge from genscripts r451: douglasjanderson Revert r438 because the problem it addresses can be taken care of more robustly. Merge from genscripts r449: douglasjanderson Make some modifications to fix bug #309091 Merge from genscripts r444: brian.dolbec add more help about the env_var's Merge from genscripts r443: douglasjanderson Simplify a func for ease of testing Merge from genscripts r442: brian.dolbec initial commit of a general purpose equery has module useable for nearly all the available vardb ENVIRONMENT data" Merge from genscripts r438: brian.dolbec rework the dpendencies _parser() tok == '' trap in an attempt to trap the InvalidAtom error, add '' removal from matches in query, add more detail in the error from Atom, add a trap to skirt around a null atom in the ChangeLog class. Hopefully I either solved it or have it printing out more info this time. Merge from genscripts r436: brian.dolbec fix the error in the raising of the GentoolkitInvalidAtom error, find and changethe info printed out in the error message to help track down the problem. Merge from genscripts r428: andkit Fix globbing for python-2.6.5/3.1.2 (fixes #315665) Apply the regexp only to the category instead of trying to modify the regexp to match the full package key to avoid relying on a specific layout of the regexp return by fnmatch.translate. svn path=/trunk/gentoolkit/; revision=811
Diffstat (limited to 'pym/gentoolkit/query.py')
-rw-r--r--pym/gentoolkit/query.py33
1 files changed, 23 insertions, 10 deletions
diff --git a/pym/gentoolkit/query.py b/pym/gentoolkit/query.py
index c18d19e..9ad9017 100644
--- a/pym/gentoolkit/query.py
+++ b/pym/gentoolkit/query.py
@@ -27,6 +27,7 @@ from gentoolkit import CONFIG
from gentoolkit import errors
from gentoolkit import helpers
from gentoolkit import pprinter as pp
+from gentoolkit.atom import Atom
from gentoolkit.cpv import CPV
from gentoolkit.dbapi import PORTDB, VARDB
from gentoolkit.package import Package
@@ -36,7 +37,7 @@ from gentoolkit.sets import get_set_atoms, SETPREFIX
# Classes
# =======
-class Query(object):
+class Query(CPV):
"""Provides common methods on a package query."""
def __init__(self, query, is_regex=False):
@@ -60,6 +61,16 @@ class Query(object):
self.is_regex = is_regex
self.query_type = self._get_query_type()
+ # Name the rest of the chunks, if possible
+ if self.query_type != "set":
+ try:
+ atom = Atom(self.query)
+ self.__dict__.update(atom.__dict__)
+ except errors.GentoolkitInvalidAtom:
+ CPV.__init__(self, self.query)
+ self.operator = ''
+ self.atom = self.cpv
+
def __repr__(self):
rx = ''
if self.is_regex:
@@ -79,8 +90,7 @@ class Query(object):
cat_str = ""
pkg_str = pp.emph(self.query)
else:
- cpv = CPV(self.query)
- cat, pkg = cpv.category, cpv.name + cpv.fullversion
+ cat, pkg = self.category, self.name + self.fullversion
if cat and not self.is_regex:
cat_str = "in %s " % pp.emph(cat.lstrip('><=~!'))
else:
@@ -185,7 +195,9 @@ class Query(object):
if in_installed:
matches.extend(VARDB.match(self.query))
except portage.exception.InvalidAtom as err:
- raise errors.GentoolkitInvalidAtom(str(err))
+ message = "query.py: find(), query=%s, InvalidAtom=%s" %(
+ self.query, str(err))
+ raise errors.GentoolkitInvalidAtom(message)
return [Package(x) for x in set(matches)]
@@ -221,7 +233,9 @@ class Query(object):
try:
best = PORTDB.xmatch("bestmatch-visible", self.query)
except portage.exception.InvalidAtom as err:
- raise errors.GentoolkitInvalidAtom(err)
+ message = "query.py: find_best(), bestmatch-visible, " + \
+ "query=%s, InvalidAtom=%s" %(self.query, str(err))
+ raise errors.GentoolkitInvalidAtom(message)
# xmatch can return an empty string, so checking for None is not enough
if not best:
if not (include_keyworded or include_masked):
@@ -229,7 +243,9 @@ class Query(object):
try:
matches = PORTDB.xmatch("match-all", self.query)
except portage.exception.InvalidAtom as err:
- raise errors.GentoolkitInvalidAtom(err)
+ message = "query.py: find_best(), match-all, query=%s, InvalidAtom=%s" %(
+ self.query, str(err))
+ raise errors.GentoolkitInvalidAtom(message)
masked = portage.best(matches)
keywordable = []
for m in matches:
@@ -302,10 +318,7 @@ class Query(object):
cat_re = cat
else:
cat_re = fnmatch.translate(cat)
- # [::-1] reverses a sequence, so we're emulating an ".rreplace()"
- # except we have to put our "new" string on backwards
- cat_re = cat_re[::-1].replace('$', '*./', 1)[::-1]
- predicate = lambda x: re.match(cat_re, x)
+ predicate = lambda x: re.match(cat_re, x.split("/", 1)[0])
pre_filter = self.package_finder(predicate=predicate)
# Post-filter