Major bugfix to toposort.
diff --git a/planetstack/observer/event_loop.py b/planetstack/observer/event_loop.py
index 6dc34da..5dd011b 100644
--- a/planetstack/observer/event_loop.py
+++ b/planetstack/observer/event_loop.py
@@ -22,7 +22,14 @@
class StepNotReady(Exception):
pass
-def toposort(g, steps):
+def toposort(g, steps=None):
+ if (not steps):
+ keys = set(g.keys())
+ values = set({})
+ for v in g.values():
+ values=values | set(v)
+
+ steps=list(keys|values)
reverse = {}
for k,v in g.items():
@@ -42,7 +49,7 @@
if (not v):
sources.append(k)
- order = []
+ rev_order = []
marked = []
while sources:
@@ -54,8 +61,10 @@
marked.append(m)
except KeyError:
pass
- order.append(n)
+ if (n in steps):
+ rev_order.append(n)
+ order = rev_order.reverse()
order.extend(set(steps)-set(order))
return order
diff --git a/planetstack/observer/toposort.py b/planetstack/observer/toposort.py
index 34bf6f5..bfedee9 100755
--- a/planetstack/observer/toposort.py
+++ b/planetstack/observer/toposort.py
@@ -9,7 +9,15 @@
from datetime import datetime
from collections import defaultdict
-def toposort(g, steps):
+def toposort(g, steps=None):
+ if (not steps):
+ keys = set(g.keys())
+ values = set({})
+ for v in g.values():
+ values=values | set(v)
+
+ steps=list(keys|values)
+
reverse = {}
for k,v in g.items():
@@ -24,15 +32,14 @@
if not reverse.has_key(k):
sources.append(k)
-
for k,v in reverse.iteritems():
if (not v):
sources.append(k)
- order = []
+ rev_order = []
marked = []
while sources:
- n = sources.pop()
+ n = sources.pop(0)
try:
for m in g[n]:
if m not in marked:
@@ -41,8 +48,13 @@
except KeyError:
pass
if (n in steps):
- order.append(n)
+ rev_order.append(n)
+ order = rev_order.reverse()
return order
-print toposort({'a':'b','b':'c','c':'d','d':'c'},['d','c','b','a'])
+graph_file=open('model-deps').read()
+g = json.loads(graph_file)
+print toposort(g)
+
+#print toposort({'a':'b','b':'c','c':'d','d':'c'},['d','c','b','a'])