diff options
Diffstat (limited to '')
-rw-r--r-- | portato/dependency.py | 260 |
1 files changed, 130 insertions, 130 deletions
diff --git a/portato/dependency.py b/portato/dependency.py index cce7360..ef06e41 100644 --- a/portato/dependency.py +++ b/portato/dependency.py @@ -23,176 +23,176 @@ from .backend import system class Dependency (object): - """ - A simple dependency as it also is noted inside ebuilds. + """ + A simple dependency as it also is noted inside ebuilds. - :IVariables: + :IVariables: - dep : string - The dependency string. It is immutable. + dep : string + The dependency string. It is immutable. - satisfied : boolean - Is this dependency satisfied? - """ + satisfied : boolean + Is this dependency satisfied? + """ - def __init__ (self, dep): - """ - Creates a dependency out of a dep string. + def __init__ (self, dep): + """ + Creates a dependency out of a dep string. - :param dep: dependency string - :type dep: string - """ - self._dep = dep + :param dep: dependency string + :type dep: string + """ + self._dep = dep - def is_satisfied (self): - """ - Checks if this dependency is satisfied. + def is_satisfied (self): + """ + Checks if this dependency is satisfied. - :rtype: boolean - """ - return system.find_best_match(self.dep, only_cpv = True, only_installed = True) is not None + :rtype: boolean + """ + return system.find_best_match(self.dep, only_cpv = True, only_installed = True) is not None - def __cmp__ (self, b): - return cmp(self.dep, b.dep) + def __cmp__ (self, b): + return cmp(self.dep, b.dep) - def __hash__ (self): - return hash(self.dep) + def __hash__ (self): + return hash(self.dep) - def __str__ (self): - return "<Dependency '%s'>" % self.dep + def __str__ (self): + return "<Dependency '%s'>" % self.dep - __repr__ = __str__ + __repr__ = __str__ - @property - def dep (self): - return self._dep + @property + def dep (self): + return self._dep - satisfied = property(is_satisfied) + satisfied = property(is_satisfied) class OrDependency (Dependency): - """ - Dependency representing an "or". - - :note: Order is important. ``|| ( a b )`` != ``|| ( b a )`` - - :IVariables: - - dep : tuple(`Dependency`,...) - The dependencies. The tuple and the dependencies are immutable. - """ - - def __init__ (self, deps): - """ - Creates an or-dependency out of a list (or tuple) of deps. - - :param deps: The or'ed dependencies. - :type deps: iter<string> - """ - - _dep = [] - for dep in deps: - if not hasattr(dep, "__iter__"): - assert not dep.endswith("?") - _dep.append(Dependency(dep)) - else: - _dep.append(AllOfDependency(dep)) - - self._dep = tuple(_dep) - - def __str__ (self): - return "<|| %s>" % str(self.dep) - - __repr__ = __str__ + """ + Dependency representing an "or". + + :note: Order is important. ``|| ( a b )`` != ``|| ( b a )`` + + :IVariables: + + dep : tuple(`Dependency`,...) + The dependencies. The tuple and the dependencies are immutable. + """ + + def __init__ (self, deps): + """ + Creates an or-dependency out of a list (or tuple) of deps. + + :param deps: The or'ed dependencies. + :type deps: iter<string> + """ + + _dep = [] + for dep in deps: + if not hasattr(dep, "__iter__"): + assert not dep.endswith("?") + _dep.append(Dependency(dep)) + else: + _dep.append(AllOfDependency(dep)) + + self._dep = tuple(_dep) + + def __str__ (self): + return "<|| %s>" % str(self.dep) + + __repr__ = __str__ class AllOfDependency (Dependency): - """ - Dependency representing a set of packages inside "or". - If the or is: ``|| (a ( b c ) )`` the `AllOfDependency` would be the ``( b c )``. + """ + Dependency representing a set of packages inside "or". + If the or is: ``|| (a ( b c ) )`` the `AllOfDependency` would be the ``( b c )``. - :IVariables: + :IVariables: - dep : tuple(`Dependency`,...) - The dependencies . The tuple and the deps are immutable. - """ + dep : tuple(`Dependency`,...) + The dependencies . The tuple and the deps are immutable. + """ - def __init__ (self, deps): - """ - Creates an or-dependency out of a list (or tuple) of deps. + def __init__ (self, deps): + """ + Creates an or-dependency out of a list (or tuple) of deps. - :param deps: The dependencies. - :type deps: iter<string> - """ + :param deps: The dependencies. + :type deps: iter<string> + """ - self._dep = tuple(Dependency(dep) for dep in deps) + self._dep = tuple(Dependency(dep) for dep in deps) - def __str__ (self): - return "<ALL %s>" % str(self.dep) - - __repr__ = __str__ + def __str__ (self): + return "<ALL %s>" % str(self.dep) + + __repr__ = __str__ class DependencyTree (object): - """ - The DependencyTree shows all dependencies for a package and shows which useflags want which dependencies. + """ + The DependencyTree shows all dependencies for a package and shows which useflags want which dependencies. - :IVariables: + :IVariables: - deps : set(`Dependency`) - The list of dependencies which are not dependent on a useflag. + deps : set(`Dependency`) + The list of dependencies which are not dependent on a useflag. - flags : string -> `DependencyTree` - Holds the additional dependency trees per useflag. - """ + flags : string -> `DependencyTree` + Holds the additional dependency trees per useflag. + """ - def __init__ (self): + def __init__ (self): - self.deps = set() - self.flags = {} + self.deps = set() + self.flags = {} - def add (self, dep, *moredeps): - """ - Adds one or more normal dependencies to the tree. + def add (self, dep, *moredeps): + """ + Adds one or more normal dependencies to the tree. - :Parameters: + :Parameters: - dep : string - A dependency string. + dep : string + A dependency string. - moredeps - More parameters are allowed :) - """ - self.deps.add(Dependency(dep)) + moredeps + More parameters are allowed :) + """ + self.deps.add(Dependency(dep)) - for dep in moredeps: - self.deps.add(Dependency(dep)) + for dep in moredeps: + self.deps.add(Dependency(dep)) - def add_or (self, orlist): - """ - Adds a list of dependencies, which are or'ed. + def add_or (self, orlist): + """ + Adds a list of dependencies, which are or'ed. - :param orlist: the dependency list - :type orlist: iter<string> - """ - self.deps.add(OrDependency(orlist)) + :param orlist: the dependency list + :type orlist: iter<string> + """ + self.deps.add(OrDependency(orlist)) - def add_flag (self, flag): - """ - Adds a new useflag to this tree. - For convenience the newly created sub-tree is returned. + def add_flag (self, flag): + """ + Adds a new useflag to this tree. + For convenience the newly created sub-tree is returned. - :param flag: the new flag - :rtype: `DependencyTree` - """ - if not flag in self.flags: - self.flags[flag] = DependencyTree() + :param flag: the new flag + :rtype: `DependencyTree` + """ + if not flag in self.flags: + self.flags[flag] = DependencyTree() - return self.get_flag_tree(flag) + return self.get_flag_tree(flag) - def get_flag_tree (self, flag): - """ - Returns the sub-tree of a specific tree. + def get_flag_tree (self, flag): + """ + Returns the sub-tree of a specific tree. - :raises KeyError: if the flag is not (yet) in this tree - :rtype: `DependencyTree` - """ - return self.flags[flag] + :raises KeyError: if the flag is not (yet) in this tree + :rtype: `DependencyTree` + """ + return self.flags[flag] |