From 39f7fae846ccc5883870a989a7c9951233a0c22d Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Thu, 24 May 2007 03:09:01 +0000 Subject: [PATCH] Add more relevant package metadata to the Packages index, including dependencies with USE conditionals collapsed. svn path=/main/trunk/; revision=6609 --- pym/portage/dbapi/bintree.py | 23 ++++++++++++++++++++++ pym/portage/dep.py | 38 ++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/pym/portage/dbapi/bintree.py b/pym/portage/dbapi/bintree.py index fcceb5e0d..6976d4de5 100644 --- a/pym/portage/dbapi/bintree.py +++ b/pym/portage/dbapi/bintree.py @@ -636,6 +636,29 @@ class binarytree(object): d["MTIME"] = str(long(s.st_mtime)) d["SIZE"] = str(s.st_size) d["MD5"] = str(md5) + keys = ["USE", "IUSE", "DESCRIPTION", "LICENSE", "PROVIDE", \ + "RDEPEND", "DEPEND", "PDEPEND"] + from itertools import izip + d.update(izip(keys, self.dbapi.aux_get(cpv, keys))) + use = d["USE"].split() + iuse = set(d["IUSE"].split()) + use = [f for f in use if f in iuse] + del iuse, d["IUSE"] + use.sort() + d["USE"] = " ".join(use) + d["DESC"] = d["DESCRIPTION"] + del d["DESCRIPTION"] + from portage.dep import paren_reduce, use_reduce, \ + paren_normalize, paren_enclose + for k in "LICENSE", "RDEPEND", "DEPEND", "PDEPEND", "PROVIDE": + deps = paren_reduce(d[k]) + deps = use_reduce(deps, uselist=use) + deps = paren_normalize(deps) + deps = paren_enclose(deps) + if deps: + d[k] = deps + else: + del d[k] pkgindex.packages[cpv] = d from portage.util import atomic_ofstream f = atomic_ofstream(os.path.join(self.pkgdir, "Packages")) diff --git a/pym/portage/dep.py b/pym/portage/dep.py index 468b997be..d1e22376e 100644 --- a/pym/portage/dep.py +++ b/pym/portage/dep.py @@ -114,6 +114,44 @@ def paren_reduce(mystr,tokenize=1): mylist = mylist + [subsec] return mylist +class paren_normalize(list): + """Take a dependency structure as returned by paren_reduce or use_reduce + and generate an equivalent structure that has no redundant lists.""" + def __init__(self, src): + self._zap_parens(src, self) + + def _zap_parens(self, src, dest, disjunction=False): + if not src: + return dest + i = iter(src) + for x in i: + if isinstance(x, basestring): + if x == '||': + x = i.next() + if len(x) == 1: + if isinstance(x[0], basestring): + dest.append(x[0]) + else: + self._zap_parens(x, dest, disjunction=disjunction) + else: + dest.append("||") + dest.append(self._zap_parens(x, [], disjunction=True)) + elif x.endswith("?"): + dest.append(x) + dest.append(self._zap_parens(i.next(), [])) + else: + dest.append(x) + else: + if disjunction: + x = self._zap_parens(x, []) + if len(x) == 1: + dest.append(x[0]) + else: + dest.append(x) + else: + self._zap_parens(x, dest) + return dest + def paren_enclose(mylist): """ Convert a list to a string with sublists enclosed with parens. -- 2.26.2