view python/unroll_deps.py @ 150:ef01512b2212

fixes; doesnt quite work
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 12 Jul 2011 17:25:21 -0700
parents 05e461e4b409
children f89c3615b414
line wrap: on
line source

#!/usr/bin/env python 

def unroll_dependencies(dependencies):
    """unroll dependencies"""
    order = []
    for package, deps in dependencies.items():
        print package, order
        try:
            index = order.index(package)
        except ValueError:
            order.append(package)
            index = len(order) - 1
        for dep in deps:
            try:
                dep_index = order.index(dep)
                assert dep_index < index, "Cyclic dependencies detected: %s, %s" % (package, dep)
            except ValueError:
                order.insert(index, dep)
    return order

if __name__ == '__main__':
    deps = {'packageA': set(['packageB', 'packageC']),
            'packageB': set(['packageC', 'packageD', 'packageE']),
            'packageC': set(['packageE'])}
    unrolled = unroll_dependencies(deps)
    print unrolled