aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Bersenev <bay@hackerdom.ru>2011-08-21 21:24:28 +0000
committerAlexander Bersenev <bay@hackerdom.ru>2011-08-21 21:24:28 +0000
commit51564746247441766cdfbd7d74860f01477059ef (patch)
treef65e8803b4b9363cbb6844cf445c65146f06cd82
parentchanged include path (diff)
downloadautodep-51564746247441766cdfbd7d74860f01477059ef.tar.gz
autodep-51564746247441766cdfbd7d74860f01477059ef.tar.bz2
autodep-51564746247441766cdfbd7d74860f01477059ef.zip
add expand_new_virt function from portage
-rw-r--r--src/autodep/package_utils/portage_misc_functions.py80
1 files changed, 76 insertions, 4 deletions
diff --git a/src/autodep/package_utils/portage_misc_functions.py b/src/autodep/package_utils/portage_misc_functions.py
index aa95845..d05c4be 100644
--- a/src/autodep/package_utils/portage_misc_functions.py
+++ b/src/autodep/package_utils/portage_misc_functions.py
@@ -2,7 +2,7 @@
# Thanks to Zac Medico <zmedico@gentoo.org> for working example of using an api
import portage
-from portage.dbapi._expand_new_virt import expand_new_virt
+from portage.dep import Atom, _get_useflag_re
# to not use own emerge option parser. Options may change but I hope
# parse_opts function will always be there
@@ -32,6 +32,78 @@ class portage_api:
self.metadata_keys = [k for k in portage.auxdbkeys if not k.startswith("UNUSED_")]
self.use=self.settings["USE"]
+ # This function is from portage and almost unchanged
+ # It is here because old versions of portage not have this function
+ def expand_new_virt(self,atom):
+ """
+ Iterate over the recursively expanded RDEPEND atoms of
+ a new-style virtual. If atom is not a new-style virtual
+ or it does not match an installed package then it is
+ yielded without any expansion.
+ """
+ vardb=self.vartree.dbapi
+
+ if not isinstance(atom, Atom):
+ atom = Atom(atom)
+
+ if not atom.cp.startswith("virtual/"):
+ yield atom
+ return
+
+ traversed = set()
+ stack = [atom]
+
+ while stack:
+ atom = stack.pop()
+ if atom.blocker or \
+ not atom.cp.startswith("virtual/"):
+ yield atom
+ continue
+
+ matches = vardb.match(atom)
+ if not (matches and matches[-1].startswith("virtual/")):
+ yield atom
+ continue
+
+ virt_cpv = matches[-1]
+ if virt_cpv in traversed:
+ continue
+
+ traversed.add(virt_cpv)
+ eapi, iuse, rdepend, use = vardb.aux_get(virt_cpv,
+ ["EAPI", "IUSE", "RDEPEND", "USE"])
+ if not portage.eapi_is_supported(eapi):
+ yield atom
+ continue
+
+ # Validate IUSE and IUSE, for early detection of vardb corruption.
+ useflag_re = _get_useflag_re(eapi)
+ valid_iuse = []
+ for x in iuse.split():
+ if x[:1] in ("+", "-"):
+ x = x[1:]
+ if useflag_re.match(x) is not None:
+ valid_iuse.append(x)
+ valid_iuse = frozenset(valid_iuse)
+
+ iuse_implicit_match = vardb.settings._iuse_implicit_match
+ valid_use = []
+ for x in use.split():
+ if x in valid_iuse or iuse_implicit_match(x):
+ valid_use.append(x)
+ valid_use = frozenset(valid_use)
+
+ success, atoms = portage.dep_check(rdepend,
+ None, vardb.settings, myuse=valid_use,
+ myroot=vardb.root, trees={vardb.root:{"porttree":vardb.vartree,
+ "vartree":vardb.vartree}})
+
+ if success:
+ stack.extend(atoms)
+ else:
+ yield atom
+
+
def get_best_visible_pkg(self,pkg):
"""
Gets best candidate on installing. Returns empty string if no found
@@ -145,7 +217,7 @@ class portage_api:
if not atomname:
continue
- for unvirt_pkg in expand_new_virt(self.vartree.dbapi,'='+atomname):
+ for unvirt_pkg in self.expand_new_virt('='+atomname):
for pkg in self.vartree.dep_match(unvirt_pkg):
ret.add(pkg)
@@ -211,7 +283,7 @@ class portage_api:
if not atomname:
continue
- for unvirt_pkg in expand_new_virt(self.vartree.dbapi,'='+atomname):
+ for unvirt_pkg in expand_new_virt('='+atomname):
for pkg in self.vartree.dep_match(unvirt_pkg):
ret.add(pkg)
unknown_packages.add(pkg)
@@ -239,7 +311,7 @@ class portage_api:
ret=[]
for atom in self.settings.packages:
for pre_pkg in self.vartree.dep_match(atom):
- for unvirt_pkg in expand_new_virt(self.vartree.dbapi,'='+pre_pkg):
+ for unvirt_pkg in self.expand_new_virt('='+pre_pkg):
for pkg in self.vartree.dep_match(unvirt_pkg):
ret.append(pkg)
return ret