Add more relevant package metadata to the Packages index, including dependencies...
authorZac Medico <zmedico@gentoo.org>
Thu, 24 May 2007 03:09:01 +0000 (03:09 -0000)
committerZac Medico <zmedico@gentoo.org>
Thu, 24 May 2007 03:09:01 +0000 (03:09 -0000)
svn path=/main/trunk/; revision=6609

pym/portage/dbapi/bintree.py
pym/portage/dep.py

index fcceb5e0ddbf0d6f5ff05a21e339ef1f696fdeb3..6976d4de5d7c88d471053ff08724b33d70f09b3c 100644 (file)
@@ -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"))
index 468b997be2843b1741da0fb369f34f555188a5c3..d1e22376e9b2eab0e02fa81a1d042411f300e1d2 100644 (file)
@@ -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.