diff options
Diffstat (limited to 'portato/backend/package.py')
-rw-r--r-- | portato/backend/package.py | 49 |
1 files changed, 39 insertions, 10 deletions
diff --git a/portato/backend/package.py b/portato/backend/package.py index ab3f82a..4d3803f 100644 --- a/portato/backend/package.py +++ b/portato/backend/package.py @@ -12,7 +12,9 @@ from __future__ import absolute_import -from ..helper import debug +from ..helper import debug, paren_reduce +from ..dependency import DependencyTree + from . import _Package, system, flags class Package (_Package): @@ -167,6 +169,42 @@ class Package (_Package): import string return string.join(sp[:-1],"/") + def get_dependencies (self): + """ + Returns the tree of dependencies that this package needs. + + @rtype: L{DependencyTree} + """ + deps = " ".join(map(self.get_package_settings, ("RDEPEND", "PDEPEND", "DEPEND"))) + deps = paren_reduce(deps) + + tree = DependencyTree() + + def add (tree, deps): + iter = (x for x in deps) + for dep in iter: + if dep.endswith("?"): + ntree = tree.add_flag(dep[:-1]) + n = iter.next() + if not hasattr(n, "__iter__"): + n = (n,) + add(ntree, n) + + elif dep == "||": + n = iter.next() # skip + if not hasattr(n, "__iter__"): + n = tuple(n,) + else: + n = tuple(n) + + tree.add_or(n) + + else: + tree.add(dep) + + add(tree, deps) + return tree + # # Not implemented # @@ -328,15 +366,6 @@ class Package (_Package): raise NotImplementedError - def get_dependencies (self): - """ - Returns the tree of dependencies that this package needs. - - @rtype: L{DependencyTree} - """ - - raise NotImplementedError - def get_package_settings(self, var, tree = None): """Returns a package specific setting, such as DESCRIPTION, SRC_URI, IUSE ... |