changeset 149:05e461e4b409

add an unroll-deps example prog
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 12 Jul 2011 13:48:50 -0700
parents 7a4c86310463
children ef01512b2212
files python/unroll_deps.py
diffstat 1 files changed, 25 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/python/unroll_deps.py	Tue Jul 12 13:48:50 2011 -0700
@@ -0,0 +1,25 @@
+#!/usr/bin/env python 
+
+def unroll_dependencies(dependencies):
+    """unroll dependencies"""
+    order = []
+    for package, deps in dependencies.items():
+        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"
+            except ValueError:
+                order.insert(index, dep)
+    return order
+
+if __name__ == '__main__':
+    deps = {'packageA': set(['packageB', 'packageC']),
+            'packageB': set(['packageC', 'packageD']),
+            'packageC': set()}
+    unrolled = unroll_dependencies(deps)
+    print unrolled