def METHOD_NAME(graph, node, resolved, seen):
    seen.append(node)
    for edge in graph[node]:
        if edge not in resolved:
            if edge in seen:
                raise RuntimeError("Packages %s and %s have " \
                        "a circular dependency in postinsts scripts." \
                        % (node, edge))
            METHOD_NAME(graph, edge, resolved, seen)
    resolved.append(node)