Esempio n. 1
0
    def drawDiag(self):
        diagram_definition = u"""seqdiag {\n"""
        #Set fontsize.
        diagram_definition += "default_fontsize = 16;\n"
        #Do not show activity line
        diagram_definition += "activation = none;\n"
        #Numbering edges automaticaly
        diagram_definition +="autonumber = True;\n"
        diagram_definition += self.diagstr
        diagram_definition += u""" }\n"""
        # generate the diag string and draw it
        self.logger.logger.info('seqdiag is ' + diagram_definition)
        #write the diagram string to file
        basename = os.path.basename(self.keylog)
        pngname = basename.split('.')[0] + '.png'
        diagname = basename.split('.')[0] + '.diag'
        pngname = self.diagdir + pngname
        diagname = self.diagdir + diagname
        print self.diagdir + '\n'
        print diagname + '\n'
        with open(diagname, 'w') as diagfile:
            diagfile.write(diagram_definition)

        self.utils.setup_imagedraw()
        self.utils.setup_noderenderers()
        tree = parser.parse_string(diagram_definition)
        diagram = builder.ScreenNodeBuilder.build(tree)

        self.logger.logger.info('diagram file is ' + pngname)
        draw = drawer.DiagramDraw('PNG', diagram, filename=pngname, debug=True)
        draw.draw()
        draw.save()
Esempio n. 2
0
    def drawOneDiag(self, diagstr, postfix):
        '''
        used to draw only one piece of pdf
        :param diagstr:
        :return:
        '''
        diagram_definition = u"""seqdiag {\n"""
        #Set fontsize.
        #http://blockdiag.com/en/blockdiag/attributes/diagram.attributes.html
        diagram_definition += " default_fontsize = 16;\n"
        diagram_definition += " node_width = 155;\n"
        diagram_definition += " edge_length = 300;\n"
        #Do not show activity line
        diagram_definition += " activation = none;\n"
        #Numbering edges automaticaly
        diagram_definition += " autonumber = True;\n"


        elementstr = "UE; CP;"
        diagram_definition +=elementstr + '\n'
        diagram_definition += '\n'
        print diagstr
        diagram_definition += diagstr
        diagram_definition += u""" }\n"""
        # generate the diag string and draw it
        #self.logger.logger.info('seqdiag is ' + diagram_definition)
        #write the diagram string to file
        basename = os.path.basename(self.radiolog)
        #print self.diagdirdiag + '\n'
        diagname = self.diagdirdiag + basename.split('.')[0] + '_' + str(postfix) + '.diag'
        #print diagname + '\n'
        pdfname = self.diagdirpdf + basename.split('.')[0] + '_' + str(postfix) + '.pdf'

        self.pdfList.append(pdfname)
        print diagram_definition
        with open(diagname, 'w') as diagfile:
            diagfile.write(diagram_definition)
        #
        #self.utils.setup_imagedraw()
        #self.utils.setup_plugins()
        self.utils.setup_imagedraw()
        self.utils.setup_noderenderers()
        tree = parser.parse_string(diagram_definition)
        diagram = builder.ScreenNodeBuilder.build(tree)

        estimatetime = 0.2 * int(self.splitgate)
        self.logger.logger.info('generation sector '+ str(postfix) + ', may take ' + str(estimatetime) + ' s')
        #set the font info
        options = dict()
        options['fontmap'] = ''
        options['font'] = list()
        options['font'].append(path + '/font/DejaVuSerif.ttf:1')
        options = utils.dotdict(options)
        fm = create_fontmap(options)
        pdfdraw = drawer.DiagramDraw('PDF', diagram, filename=pdfname, debug=True, fontmap=fm)
        pdfdraw.draw()
        pdfdraw.save()
Esempio n. 3
0
def main(args, results_dir: Path, scenario_dir: Path):
    scenario(args, results_dir, scenario_dir)

    if not getattr(args, 'sequence_diagram', False):
        return
    routers = set()
    messages = {}
    for router, tracefile in all_tracefiles([scenario_dir], 'rx.msg.valid'):
        routers.add(router)
        for time, message in extract_messages(tracefile):
            messages.setdefault(time, []).append((router, message))

    diag = []
    diag_skel = '{sender} -> {receiver} [label="{time}\n{type}\n{data}"]'
    for time in sorted(messages, key=float):
        for receiver, message in messages[time]:
            message = json.loads(message)
            sender = message['id']
            type = message['type']
            data = []
            if 'routing-data' in message:
                for policy in message['routing-data']:
                    for node, path in message['routing-data'][policy].items():
                        if path is not None:
                            path = path['path']
                        data.append('{}: {}'.format(node, path))
            data = '\n'.join(sorted(data))

            diag.append(
                diag_skel.format(sender=sender,
                                 receiver=receiver,
                                 type=type,
                                 data=data,
                                 time=time))

    diag.insert(0, ';'.join(sorted(routers)) + ';')
    result = skel.format('\n'.join(diag))

    tree = seq_parser.parse_string(result)
    diagram = builder.ScreenNodeBuilder.build(tree)
    filename = str(results_dir / 'sequence_diagram.svg')
    try:
        results_dir.mkdir(parents=True)
    except FileExistsError:
        pass
    draw = drawer.DiagramDraw(args.seq_diag_type, diagram, filename=filename)
    draw.draw()
    draw.save()
Esempio n. 4
0
    def drawOneDiag(self, diagstr, postfix):
        diagram_definition = u"""seqdiag {\n"""
        #Set fontsize.
        diagram_definition += " edge_length = 300;\n  // default value is 192"
        diagram_definition += "default_fontsize = 30;\n"
        #Do not show activity line
        diagram_definition += "activation = none;\n"
        #Numbering edges automaticaly
        diagram_definition += "autonumber = True;\n"
        diagram_definition += diagstr
        diagram_definition += u""" }\n"""
        # generate the diag string and draw it
        #self.logger.logger.info('seqdiag is ' + diagram_definition)
        #write the diagram string to file
        basename = os.path.basename(self.log)
        pngname = basename.split('.')[0] + '_' + str(postfix) + '.png'
        diagname = basename.split('.')[0] + '_' + str(postfix) + '.diag'

        pngname = self.diagtempdir + pngname
        diagname = self.diagtempdir + diagname
        pdfname = self.diagtempdir + basename.split('.')[0] + '_' + str(
            postfix) + '.pdf'
        self.pdfList.append(pdfname)
        with open(diagname, 'w') as diagfile:
            diagfile.write(diagram_definition)
        #self.utils.setup_imagedraw()
        #self.utils.setup_plugins()
        self.utils.setup_imagedraw()
        self.utils.setup_noderenderers()

        tree = parser.parse_string(diagram_definition)
        diagram = builder.ScreenNodeBuilder.build(tree)

        self.logger.logger.info('diagram file is ' + pngname)
        options = dict()
        options['fontmap'] = ''
        options['font'] = list()
        options['font'].append(path + '/font/DejaVuSerif.ttf:1')
        options = utils.dotdict(options)
        fm = create_fontmap(options)
        pdfdraw = drawer.DiagramDraw('PDF',
                                     diagram,
                                     filename=pdfname,
                                     debug=True,
                                     fontmap=fm)
        pdfdraw.draw()
        pdfdraw.save()
        '''
Esempio n. 5
0
def image(request):

    ret = {}
    response = HttpResponse(content_type='application/json')

    try:
        QueryDict = request.GET
        id = QueryDict.get('id')
        download = QueryDict.get('download')

        if id is None:
            raise Exception("ID required")

        data = getSeqDiagDataAndMap(id, download)

        buffer = ''

        if data['status'] == "OK":
            tree = parser.parse_string(data['flow'])
            diagram = builder.ScreenNodeBuilder.build(tree)

            draw = drawer.DiagramDraw(
                'png',
                diagram,
                buffer,
                antialias=False,
                font='/usr/share/fonts/wine-tahoma-fonts/tahoma.ttf')
            draw.draw()
            img = draw.save()

            ret['image'] = 'data:image/png;base64,%s' % base64.b64encode(img)
            ret['imageMap'] = data['areaImgMap']
            ret['msg'] = data['msg']
        else:
            response.status_code = 500
            ret['image'] = data['flow']

    except Exception as e:
        ret['image'] = str(e)
        response.status_code = 500
        pass

    json_data = json.dumps(ret)

    response.content = json_data

    return response
Esempio n. 6
0
def seq_diag_draw():
    print("***Sequence diagram draw*****")
    global var_Entry_class, var_fun, var_Exit_class
    var_function_flow = ""
    len_class = len(var_Entry_class) - 6000
    i = 0
    for i in range(len_class):
        #    while i < len_class:
        #        print(i,"=",var_Entry_class[i],"=",var_fun[i],"=",var_Exit_class[i])
        if (var_Entry_class[i] != "0" and var_Exit_class[i] == "0"):
            var_in_function = var_Entry_class[i]
            if (var_fun[i] != "0"):
                _tmp_strp_fun = var_fun[i].split("(")
                var_fun_name = _tmp_strp_fun[0]
                if ((i + 1) < len(var_Entry_class)):
                    if (var_Exit_class[i + 1] != "0"):
                        var_out_function = var_Exit_class[i + 1]

                    else:
                        var_out_function = var_Entry_class[i + 1]

                else:
                    break


#    var_fun_name = "Functioncall"
#    var_in_function = "BROWS    "
#    var_out_function = "Websvr"
            var_function_in_flow = u"""%s  -> %s [label = %s];""" % (
                var_in_function, var_out_function, var_fun_name)
            #            var_function_out_flow = u"""%s <- %s;"""%(var_in_function,var_out_function)
            var_function_flow = var_function_flow + var_function_in_flow + "\n"

    diagram_definition = u"""
       seqdiag {
default_fontsize = 14;  // default value is 11
       %s
        }
    """ % (var_function_flow)
    #    diagram_definition = diagram_definition + "\n" +var_function_in_flow + "\n"+ var_function_out_flow
    print(diagram_definition)
    tree = parser.parse_string(diagram_definition)
    print(tree)
    diagram = builder.ScreenNodeBuilder.build(tree)
    draw = drawer.DiagramDraw('PNG', diagram, filename="seg_test_new.png")
    draw.draw()
    draw.save()
Esempio n. 7
0
def seqdiag_generate_image(source, format):
    from seqdiag import parser, builder, drawer

    try:
        tree = parser.parse_string(source)
        diagram = builder.ScreenNodeBuilder.build(tree)
        draw = drawer.DiagramDraw(format,
                                  diagram,
                                  fontmap=get_fontmap(),
                                  ignore_pil=True)
        draw.draw()

        image = draw.save()
        etype = None
        error = None
    except Exception, e:
        image = ''
        etype = e.__class__.__name__
        error = str(e)
        logging.exception(e)
Esempio n. 8
0
def draw_diag(path):

    read_file_and_process(path)
    diagram_definition = convert_to_origin_seqdiag()

    print('Converted definition : {}'.format(diagram_definition))

    tree = parser.parse_string(diagram_definition)
    diagram = builder.ScreenNodeBuilder.build(tree)

    fm = FontMap()
    fm.set_default_font('./malgun.ttf')

    draw = drawer.DiagramDraw('PNG',
                              diagram,
                              filename='{}.png'.format(
                                  path.split('/\\')[-1].split('.')[0]),
                              fontmap=fm)
    draw.draw()
    draw.save()
    pass
Esempio n. 9
0
    //span_height = 80;
    default_fontsize = 12;
    autonumber = true;
    default_note_color = "lightblue";
    
    // no activity line
    //activation = none;

    // Nester Init Routines
    init => runblock [label = "Call", return = "Return status"]
        runblock => Card1 [label = "Card Init", return = "Status"]
        Card1 => browser [label = "Start Web", return = "status"]

      === Card To Card ===
      Card1 -> Card2 [note = "request", label = "<new label> "];
      Card2 -> Card1 [rightnote = "Response back", label = "new label", textcolor="red" ];
      ... Card To Web Server ...
      browser <- Card1 [diagonal, label="Card1-Card3"];
      browser  -> webserver [label = "GET /index.html"];
      browser <- webserver;
      browser <- webserver [label="failed request", failed]
      browser -> browser [label = "Loop inside"];
   }
"""

seq_tree = parser.parse_string(seq_diagram_definition)
seq_diagram = builder.ScreenNodeBuilder.build(seq_tree)
seq_draw = drawer.DiagramDraw('PNG', seq_diagram, filename="seq-diagram.png")
seq_draw.draw()
seq_draw.save()
Esempio n. 10
0
      Shiba2Fe1600 <- DiagFe1600  [ label="Init, devid" ];
      Shiba2Fe1600 -> Shiba2Fe1600 [ label="Initialze Shiba2 FE1600"];
      DiagFe1600  -> Shiba2Fe1600 [label="GetDeviceBaseAddress(<DevId>)"];
      Shiba2Fe1600 -> DiagFe1600  [label="FE0/1 Mapped BAR Address"];
      DiagFe1600  -> BCM-SDK [ label="bcm driver init"];
      BCM-SDK -> BCM-SDK [label="CM SAL Init"];
      BCM-SDK -> BCM-SDK [label="Device Attach"];
      BCM-SDK -> BCM-SDK [label="soc_reset_Init"];
      BCM-SDK -> BCM-SDK [label="bcm_init"];

      CDiagScript -> CDiagFunc   [label="<< Call Fe1600 Function >"];
      CDiagFunc -> DiagFe1600  [label="dev-reset"];
      CDiagFunc -> DiagFe1600  [label="dev-init"];
      CDiagFunc -> DiagFe1600  [label="get-avs"];
      CDiagFunc -> DiagFe1600  [label="pll-rst-on"];
      CDiagFunc -> DiagFe1600  [label="pll-rst-off"];
      CDiagFunc -> DiagFe1600  [label="pll-status"];
      CDiagFunc -> DiagFe1600  [label="snake-test"];
      CDiagFunc -> DiagFe1600  [label="prbs-test"];
      CDiagFunc -> DiagFe1600  [label="fabric_tuning"];
      CDiagFunc -> DiagFe1600  [label="fabric-stats"];
   
    } """

tree = parser.parse_string(diagram_definition)
diagram = builder.ScreenNodeBuilder.build(tree)
draw = drawer.DiagramDraw('PNG', diagram, filename="fe1600-seqdiag.png")
draw.draw()
draw.save()

Esempio n. 11
0
      // Numbering edges automaticaly
      //autonumber = True;

      // Change note color
      //default_note_color = lightblue;
        
        Caldera-IDEFIX -> RP [label="Telnet to RP"];
        === RP Configuration ===
        RP -> RP [note = "Configure RP SSH Server sshd_config for Alive Interval and Modes"];
        RP -> RP [note = "Generate keys: ssh-keygen -v -N -f /root/.ssh/id_rsa"];
        RP -> RP [note = "Remove Existing Authorized Keys and hosts"];
        === RP to LC ===
        RP --> LC [diagonal, label = "Verify SSH connection from RP to LC"];
         RP -> LC [label= "Copy RP Public key to LC", note="ssh-copy-id -i /root/.ssh/id_rsa.pub"];
        RP -> LC [label = "Passwordless Connection" note="ssh -v -o ServerAliveInterval=10 -o ServerAliveCountMax=20 ", color=blue];
        === LC Configuration ===
        LC -> LC [note = "Configure LC SSH server sshd_config for Alive Intervals"];
        LC -> LC [label = "Generate keys", note="ssh-keygen -v -N -f /root/.ssh/id_rsa"];
        === LC to RP ===
        LC -> RP [label = "Copy LC Public key to RP", note="ssh-copy-id -i /root/.ssh/id_rsa.pub"];
        LC --> RP [diagonal, label = "Verify SSH connection from LC to RP"];
        LC -> RP [label = "Passwordless Connection", note="scp files from RP to LC", color=blue];
   }
"""
tree = parser.parse_string(diagram_definition)
diagram = builder.ScreenNodeBuilder.build(tree)
draw = drawer.DiagramDraw('PNG', diagram, filename="SSH-Passwordless.png")
draw.draw()
draw.save()
Esempio n. 12
0
# -*- coding: utf-8 -*-
"""
Created on Tue Aug  7 13:50:54 2018

@author: harisbha
"""

from seqdiag import parser, builder, drawer

diagram_definition = u"""
   seqdiag {
      browser  -> webserver [label = "GET /index.html"];
      browser <- webserver;
   }
"""
tree = parser.parse_string(diagram_definition)
diagram = builder.ScreenNodeBuilder.build(tree)
draw = drawer.DiagramDraw('PDF', diagram, filename="diagram.pdf")
draw.draw()
draw.save()
Esempio n. 13
0
#!/usr/bin/python
# -*- coding:utf-8

from seqdiag import parser, builder, drawer
import sys
sys.path.append("..")

diagram_definition = u"""
   seqdiag {
       "c:Contestant" -> ":WebServer" [label = "GET /IDIOpen/accounts/register/"];
       ":WebServer" -> "
   }
"""
tree = parser.parse_string(diagram_definition)
diagram = builder.ScreenNodeBuilder.build(tree)
draw = drawer.DiagramDraw('PNG', diagram, filename="RegisterContestantSeq.png")
draw.draw()
draw.save()

# EOF
Esempio n. 14
0
        sys.stderr.write("Unable to determine event name for index: %d\n" %
                         event.event)
        sys.exit(1)
    delayed_events = ""
    for delayed in event.delayed:
        delayed_events += "%s -> %s [label='Delayed:\\n%s', color=blue, failed];\n" % (
            enter_state_name, enter_state_name, all_names["events"][delayed])
    log_text = "\\n".join(event.log)
    transition = "%s -> %s [label='%s:\\n%s', color=%s, leftnote='%s'] { %s };" % (
        enter_state_name, exit_state_name, StateResults.names[event.result],
        event_name, StateResults.colors[event.result], log_text,
        delayed_events)
    transition_spec += "    %s\n" % transition

used_states_text = ""
for state in set(used_states):
    used_states_text += "%s [width = 200];\n" % state

diag_spec = u"""
seqdiag {
    %s
    %s
}
""" % (used_states_text, transition_spec)

tree = parser.parse_string(diag_spec)
diagram = builder.ScreenNodeBuilder.build(tree)
draw = drawer.DiagramDraw('SVG', diagram, filename="diagram.svg")
draw.draw()
draw.save()
Esempio n. 15
0
   seqdiag {

        // Set edge metrix.
        //edge_length = 300;  // default value is 192
        //span_height = 580;  // default value is 40
        //span_width = 1580;  // default value is 40

        // Set fontsize.
        default_fontsize = 16;  // default value is 11

        // Do not show activity line
        //activation = none;

        // Numbering edges automaticaly
        autonumber = False;

        // Change note color
        default_note_color = lightgrey;

      browser  -> webserver [label = "GET /index.html"];
      browser <- webserver;
      browser -> browser [label = "Loop inside"];
   }
"""
tree = parser.parse_string(diagram_definition)
diagram = builder.ScreenNodeBuilder.build(tree)
draw = drawer.DiagramDraw('PNG', diagram, filename="diagram.png")
draw.draw()
draw.save()