chiark / gitweb /
I'm sure I've done something since I remembered to commit...
[familyTree.git] / cgiFiles / test.py
1 #!/usr/bin/python
2
3 import cgi
4 #import cgitb
5
6 import pygraph
7 from pygraph.classes.graph import graph
8 from pygraph.classes.digraph import digraph
9 from pygraph.algorithms.searching import breadth_first_search
10 from pygraph.readwrite.dot import write
11 import gv
12 import StringIO
13
14
15
16 def make_graph(Self,parents,children,otherparents):
17         # Graph creation
18         gr = digraph()
19
20         # Add nodes and edges
21         gr.add_nodes([Self])
22
23         for p in parents:
24                 gr.add_nodes([p])
25                 gr.add_edge((p,Self))
26
27         for i in range(len(children)):
28                 gr.add_nodes([children[i]])
29                 gr.add_edge((Self,children[i]))
30                 if not gr.has_node(otherparents[i]):
31                         gr.add_nodes([otherparents[i]])
32                 gr.add_edge((otherparents[i],children[i]))
33
34
35
36
37          #Draw as PNG
38 #       dot = write(gr)
39 #       gvv = gv.readstring(dot)
40 #       gv.layout(gvv,'dot')
41
42 #       print "Content-type: image/png\n"
43 #       print gv.render(gvv,'png')
44
45 form = cgi.FieldStorage()
46
47 Self = 'naath'
48 p = ['Bob','Susan']
49 c = ['Jane','Alice']
50 op = ['Mary','Mary']
51
52 make_graph(Self,p,c,op)