Commits

Dinu Gherman committed 1834666

Added function namespace2dot_str(), re issue #1.

  • Participants
  • Parent commits 14177b1

Comments (0)

Files changed (1)

src/pyrels/pyrels2dot.py

 #   - handle cyclic datastructures
 
 
-import re, sys, os
+import re
+import sys
+import os
+from cStringIO import StringIO
 from types import *
 
 # make sure we have decimal package
     return nodes, edges
     
 
+def namespace2dot_str(ns):
+    "Generate GraphViz DOT string for a given namespace." 
+    
+    nodes, edges = ns2dot(ns)
+
+    # create DOT file
+    f = StringIO()
+    write = lambda line: f.write("%s\n" % line)
+    write("digraph G {")
+    write("    overlap=false;")
+    # write("    concentrate=true;")
+    # write("    nodesep=1.0;")
+    write("")
+    for n in nodes: 
+        write(n)
+    write("")
+    for e in edges: 
+        write(e)
+    write("")
+    write("}")
+
+    f.seek(0)
+    return f.read()
+
+
 def namespace2dot(ns, path=None, gvtool=None, format="pdf", debug=False):
     "Generate GraphViz DOT file for a given namespace."