class Walker(object): def __init__(self, workspace): self.workspace = workspace self.forward = DependencyMap(workspace) self.backward = DependencyMap(workspace, True) def starting_at(self, *nodes): retval = Traversal(self, None) retval._cache = set(nodes) return retval def most_depended(self): matches = set() for node, dependencies in self.backward.items(): if len(dependencies) > 0: continue matches.add(node) retval = Traversal(self, None) retval._cache = matches return retval def least_depended(self): matches = set() for node, dependencies in self.forward.items(): if len(dependencies) > 0: continue matches.add(node) retval = Traversal(self, None) retval._cache = matches return retval def find(self, selectors): expr = self.least_depended() for selector in selectors: expr = expr.outgoing(selector) return expr
def __init__(self, workspace): self.workspace = workspace self.forward = DependencyMap(workspace) self.backward = DependencyMap(workspace, True)