diff options
Diffstat (limited to '')
-rw-r--r-- | portato/backend/catapult/package.py | 7 | ||||
-rw-r--r-- | portato/backend/package.py | 49 | ||||
-rw-r--r-- | portato/backend/portage/package.py | 34 | ||||
-rw-r--r-- | portato/helper.py | 45 |
4 files changed, 85 insertions, 50 deletions
diff --git a/portato/backend/catapult/package.py b/portato/backend/catapult/package.py index 5ab8743..e2dd54e 100644 --- a/portato/backend/catapult/package.py +++ b/portato/backend/catapult/package.py @@ -147,12 +147,6 @@ class CatapultPackage(Package): def get_files (self): return self.proxy.get_files(self.get_cpv()) - def get_dependencies (self): - from ...dependency import DependencyTree - d = DependencyTree() - d.add("Dependency calculation not supported for Catapult Backend") - return d - def get_name(self): return str(self.proxy.get_name(self.get_cpv())) @@ -161,4 +155,3 @@ class CatapultPackage(Package): def get_category(self): return str(self.proxy.get_category(self.get_cpv())) - 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 ... diff --git a/portato/backend/portage/package.py b/portato/backend/portage/package.py index 16f00a4..767df5b 100644 --- a/portato/backend/portage/package.py +++ b/portato/backend/portage/package.py @@ -17,7 +17,6 @@ from .. import flags from .. import system from ..exceptions import BlockedException, PackageNotFoundException, DependencyCalcError from ...helper import debug, error, unique_array -from ...dependency import DependencyTree import portage, portage_dep @@ -318,35 +317,4 @@ class PortagePackage (Package): return portage.pkgcmp(v1[1:],v2[1:]) def matches (self, criterion): - return system.cpv_matches(self.get_cpv(), criterion) - - def get_dependencies (self): - deps = " ".join(map(self.get_package_settings, ("RDEPEND", "PDEPEND", "DEPEND"))) - deps = portage_dep.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 + return system.cpv_matches(self.get_cpv(), criterion) diff --git a/portato/helper.py b/portato/helper.py index 5cf57a0..331bf9a 100644 --- a/portato/helper.py +++ b/portato/helper.py @@ -45,6 +45,51 @@ def send_signal_to_group (sig): pgid = os.getpgrp() os.killpg(pgid, sig) +def paren_reduce(mystr): + """ + Take a string and convert all paren enclosed entities into sublists, optionally + futher splitting the list elements by spaces. + + This function is copied from portage. + + Example usage: + >>> paren_reduce('foobar foo ( bar baz )') + ['foobar', 'foo', ['bar', 'baz']] + + @param mystr: The string to reduce + @type mystr: String + @rtype: Array + @return: The reduced string in an array + """ + mylist = [] + while mystr: + left_paren = mystr.find("(") + has_left_paren = left_paren != -1 + right_paren = mystr.find(")") + has_right_paren = right_paren != -1 + if not has_left_paren and not has_right_paren: + freesec = mystr + subsec = None + tail = "" + elif mystr[0] == ")": + return [mylist,mystr[1:]] + elif has_left_paren and not has_right_paren: + error(_("Invalid dependency string")) + return [] + elif has_left_paren and left_paren < right_paren: + freesec,subsec = mystr.split("(",1) + subsec,tail = paren_reduce(subsec) + else: + subsec,tail = mystr.split(")",1) + subsec = filter(None, subsec.split(" ")) + return [mylist+subsec,tail] + mystr = tail + if freesec: + mylist = mylist + filter(None, freesec.split(" ")) + if subsec is not None: + mylist = mylist + [subsec] + return mylist + def flatten (listOfLists): """Flattens the given list of lists. |