Mercurial > hg > config
annotate python/unroll_deps.py @ 149:05e461e4b409
add an unroll-deps example prog
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Tue, 12 Jul 2011 13:48:50 -0700 |
parents | |
children | ef01512b2212 |
rev | line source |
---|---|
149
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
2 |
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
3 def unroll_dependencies(dependencies): |
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
4 """unroll dependencies""" |
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
5 order = [] |
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
6 for package, deps in dependencies.items(): |
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
7 try: |
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
8 index = order.index(package) |
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
9 except ValueError: |
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
10 order.append(package) |
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
11 index = len(order) - 1 |
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
12 for dep in deps: |
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
13 try: |
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
14 dep_index = order.index(dep) |
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
15 assert dep_index < index, "Cyclic dependencies detected" |
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
16 except ValueError: |
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
17 order.insert(index, dep) |
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
18 return order |
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
19 |
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
20 if __name__ == '__main__': |
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
21 deps = {'packageA': set(['packageB', 'packageC']), |
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
22 'packageB': set(['packageC', 'packageD']), |
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
23 'packageC': set()} |
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
24 unrolled = unroll_dependencies(deps) |
05e461e4b409
add an unroll-deps example prog
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
25 print unrolled |