[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: routing tables to dia network map



Hi,

On Mon, 8 Mar 2004, Hans Breuer wrote:

> [a script]

Thanks for this script.
It helped me a lot to write sth.

Here is the context :
A first script read rulsets, netstat, etc, and make a GraphViz graph
(.dot). neato, twopi or fdp (from GraphViz) places the nodes of the graph
and output another graph that looks like :
graph toto {
        node [label="\N"];
        graph [bb="0,0,260,149"];
        a [shape="router", pos="28,130", width="0.75", height="0.50"];
        b [shape="cloud", pos="88,88", width="0.75", height="0.50"];
        c [shape="could", pos="113,19", width="0.75", height="0.50"];
        d [shape="router", pos="160,74", width="0.75", height="0.50"];
        e [shape="router", pos="232,91", width="0.75", height="0.50"];
        a -- b [pos="47,117 55,112 62,106 69,101"];
        b -- c [pos="94,70 99,59 103,48 107,37"];
        c -- d [pos="126,35 133,43 140,50 147,58"];
        b -- d [pos="114,83 120,82 127,80 134,79"];
        e -- d [pos="206,85 199,83 193,82 186,80"];
}

Then, I want to convert this into dia.
If someone wants to write a dot2dia, his work will surely be widely used !

I've taken the approach to use the python plugin.
It sort of works, but here are my questions (I'm sorry I've got so little
time I did not take a lot of it finding by myself) :

***  why can't I do this :
>>> r=dia.get_object_type("Network - Modem")
>>> r.create(10,10)
Traceback (most recent call last):
  File "/usr/share/dia/python/gtkcons.py", line 297, in run
    r = eval(cmd, self.namespace, self.namespace)
  File "<string>", line 0, in ?
RuntimeError: could not create new object

At the same time, I get :
** (dia:29110): CRITICAL **: file custom_object.c: line 1088
(custom_create): assertion `info!=NULL' failed

(It works well with Hans' script, ie with UML objects :()

*** How am I supposed to do if I don't want to copy paste my code into the
    gtk console ?


*** Is there a good way to connect 2 objects with the right connection
    point (the one on the good side of the box) ?

*** I have an object that is connected to more than 50 others, how can I
    do ?

*** Is there a way to create more connections ?

*** Is there a way to put connections on the back ?


Here is my code, for the moment :

import re

d = dia.active_display().diagram
lay = d.layers[0]


re_l = re.compile(r'\s*"?([^" -]*)"?\s+(--\s+)?"?([^"]*)"?\s+\[(.*)\]')


kwords = ["graph","node"]

shapes = { "": "Network - Cloud" ,
           "none" : "Cisco - Router",
           "ellipse" : "Network - Cloud" }

shapes = { "": "UML - LargePackage" ,
           "none" : "UML - LargePackage" ,
           "ellipse" : "UML - LargePackage"  }

for k in shapes:
    shapes[k] = dia.get_object_type(shapes[k])


lineobj = dia.get_object_type("Standard - Line")

def parse(p):
    prop = {}
    for i in p.split(" "):
        a,b = i.split("=")
        a = a.strip()
        b = b.strip()
        b = b.strip(",")
        b = b.strip('"')
        try:
            b = float(b)
        except ValueError:
            pass
        prop[a] = b
    return prop


objs = {}

f=open("r2.dot")

for l in f.readlines():
    m=re_l.match(l)
    if not m:
        continue
    a,tiret,b,prop = m.groups()
    if b in kwords:
        continue
    if tiret is None:
        p = parse(prop)
        shape = p.get("shape", "none")
        shape = shapes.get(shape, shapes[""])
        cx,cy = map(int,p["pos"].split(","))
        cx = cx/10
        cy = cy/10
        o,h1,h2 = shape.create(cx,cy)
        o.properties["name"] = b
        lay.add_object(o)
        objs[b] = (o,cx,cy,0)
    else:
        if a not in objs or b not in objs:
            continue
        oa,cax,cay,can = objs[a]
        ob,cbx,cby,cbn = objs[b]
        line,h1,h2 = lineobj.create((cax+cbx)/2,(cay+cby)/2)
        lay.add_object(line)
        try:
            h1.connect(oa.connections[can])
        except IndexError:
            pass
        try:
            h2.connect(ob.connections[cbn])
        except IndexError:
            pass
        objs[a] = (oa,cax,cay,can+1)
        objs[b] = (ob,cbx,cby,cbn+1)
        print "lnk %s -- %s" % (a,b)

f.close()

lay.update_extents()

dia.active_display().add_update_all()




-- 
Philippe Biondi <phil@ secdev.org>      SecDev.org
Security Consultant/R&D                 http://www.secdev.org
PGP KeyID:3D9A43E2  FingerPrint:C40A772533730E39330DC0985EE8FF5F3D9A43E2





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index] Mail converted by Mofo Magic and the Flying D

 
All trademarks and copyrights are the property of their respective owners.

Other Directory Sites: SeekWonder | Directory Owners Forum

GuideSMACK