summaryrefslogtreecommitdiffstats
path: root/pym/portage_dep.py
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2008-05-25 03:59:35 +0000
committerZac Medico <zmedico@gentoo.org>2008-05-25 03:59:35 +0000
commit6c6ac86ee1505015bd5f671e4ae6cdad8d7b53c1 (patch)
tree122325584e45e0e748844c12608b8c81c3781cc8 /pym/portage_dep.py
parentddfd90ccf7aa26c18c29d8aa82c38f384fe3b9a6 (diff)
downloadportage-6c6ac86ee1505015bd5f671e4ae6cdad8d7b53c1.tar.gz
portage-6c6ac86ee1505015bd5f671e4ae6cdad8d7b53c1.tar.bz2
portage-6c6ac86ee1505015bd5f671e4ae6cdad8d7b53c1.zip
Merge the Atom class and dbapi._iter_match() from trunk r10387 and r10394.
Everything related to USE deps has been omitted for now. svn path=/main/branches/2.1.2/; revision=10403
Diffstat (limited to 'pym/portage_dep.py')
-rw-r--r--pym/portage_dep.py44
1 files changed, 40 insertions, 4 deletions
diff --git a/pym/portage_dep.py b/pym/portage_dep.py
index bad51b646..26737d618 100644
--- a/pym/portage_dep.py
+++ b/pym/portage_dep.py
@@ -20,7 +20,7 @@
import re, sys, types
import portage_exception
-from portage_exception import InvalidData
+from portage_exception import InvalidAtom, InvalidData
from portage_versions import catpkgsplit, catsplit, pkgcmp, pkgsplit, ververify
def cpvequal(cpv1, cpv2):
@@ -274,6 +274,20 @@ def dep_opconvert(deplist):
x += 1
return retlist
+class Atom(str):
+
+ def __init__(self, s):
+ str.__init__(self, s)
+ if not isvalidatom(s, allow_blockers=True):
+ raise InvalidAtom(s)
+ self.blocker = "!" == s[:1]
+ if self.blocker:
+ s = s[1:]
+ self.cp = dep_getkey(s)
+ self.cpv = dep_getcpv(s)
+ self.slot = dep_getslot(s)
+ self.operator = get_operator(s)
+
def get_operator(mydep):
"""
Return the operator used in a depstring.
@@ -289,6 +303,9 @@ def get_operator(mydep):
@return: The operator. One of:
'~', '=', '>', '<', '=*', '>=', or '<='
"""
+ operator = getattr(mydep, "operator", None)
+ if operator is not None:
+ return operator
if mydep:
mydep = remove_slot(mydep)
if not mydep:
@@ -325,6 +342,9 @@ def dep_getcpv(mydep):
@rtype: String
@return: The depstring with the operator removed
"""
+ cpv = getattr(mydep, "cpv", None)
+ if cpv is not None:
+ return cpv
global _dep_getcpv_cache
retval = _dep_getcpv_cache.get(mydep, None)
if retval is not None:
@@ -358,13 +378,20 @@ def dep_getslot(mydep):
@rtype: String
@return: The slot
"""
- colon = mydep.rfind(":")
+ slot = getattr(mydep, "slot", None)
+ if slot is not None:
+ return slot
+ colon = mydep.find(":")
if colon != -1:
return mydep[colon+1:]
return None
def remove_slot(mydep):
- colon = mydep.rfind(":")
+ """
+ Removes dep components from the right side of an atom:
+ * slot
+ """
+ colon = mydep.find(":")
if colon != -1:
mydep = mydep[:colon]
return mydep
@@ -389,6 +416,10 @@ def isvalidatom(atom, allow_blockers=False):
1) 0 if the atom is invalid
2) 1 if the atom is valid
"""
+ if isinstance(atom, Atom):
+ if atom.blocker and not allow_blockers:
+ return 0
+ return 1
global _invalid_atom_chars_regexp
if _invalid_atom_chars_regexp.search(atom):
return 0
@@ -490,6 +521,9 @@ def dep_getkey(mydep):
@rtype: String
@return: The package category/package-version
"""
+ cp = getattr(mydep, "cp", None)
+ if cp is not None:
+ return cp
mydep = dep_getcpv(mydep)
if mydep and isspecific(mydep):
mysplit = catpkgsplit(mydep)
@@ -565,8 +599,10 @@ def match_from_list(mydep, candidate_list):
"""
from portage_util import writemsg
- if mydep[0] == "!":
+ if "!" == mydep[:1]:
mydep = mydep[1:]
+ if not isinstance(mydep, Atom):
+ mydep = Atom(mydep)
mycpv = dep_getcpv(mydep)
mycpv_cps = catpkgsplit(mycpv) # Can be None if not specific