diff req_dep.py @ 2:e07789816ca5

adding more python files from lib/python on origen
author Henry Thompson <ht@markup.co.uk>
date Mon, 09 Mar 2020 16:48:09 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/req_dep.py	Mon Mar 09 16:48:09 2020 +0000
@@ -0,0 +1,48 @@
+#!/usr/bin/python2.7
+import sys
+kids={}
+parents={}
+known=set(())
+l=sys.stdin.readline()
+while l:
+  ff=l.strip().split()
+  if len(ff)!=0:
+    d=ff[0]
+    sys.stdin.readline()
+    pp=sys.stdin.readline().strip().replace(',','').split()[2:]
+    parents[d]=pp
+    known.add(d)
+    for p in pp:
+      known.add(p)
+      try:
+        c=kids[p]
+        c.add(d)
+      except KeyError:
+        c=set([d])
+        kids[p]=c
+  l=sys.stdin.readline()
+roots={}
+still=set(())
+for k in known:
+  if k in parents:
+    still.add(k)
+  else:
+    roots[k]=set([k])
+#print len(parents),len(kids),len(roots),len(still),roots
+print roots.keys()
+while len(still)>0:
+  #print len(still),len(roots)
+  pend=still
+  still=set([])
+  while len(pend)>0:
+    x=pend.pop()
+    #print x,len(pend)
+    for p in parents[x]:
+      try:
+        r=roots[p]
+        roots[x]=roots.get(x,set(())).union(r)
+      except KeyError:
+        if p in parents:
+          still.add(x)
+for x,r in sorted(roots.items()):
+  print x,r