Bugfix
Sapan Bhatia [Tue, 27 Jan 2015 03:54:29 +0000 (03:54 +0000)]
planetstack/openstack_observer/toposort.py

index a2c9389..c717718 100644 (file)
@@ -41,23 +41,24 @@ def toposort(g, steps=None):
 
                while (stack):
                        n = stack[0]
+                       print stack
+                       print "Trying %s"%n
                        add = True
                        try:
                                for m in g[n]:
                                        if (m in unmarked):
-                                               if (m not in stack):
-                                                       add = False
-                                                       stack.insert(0,m)
-                                               else:
-                                                       # Should not happen, if so there's a loop
-                                                       print 'Loop at %s'%m
+                                           add = False
+                                           stack.insert(0,m)
                        except KeyError:
                                pass
                        if (add):
-                               if (n in steps):
+                               if (n in steps and n not in order):
                                        order.append(n)
                                item = stack.pop(0)
-                               unmarked.remove(item)
+                               try:
+                                       unmarked.remove(item)
+                               except ValueError:
+                                       pass
 
        noorder = list(set(steps) - set(order))
        return order + noorder