def execute(macro, args):
    formatter = macro.formatter
    macro.request.page.formatter = formatter
    request = macro.request
    _ = request.getText

    if not args:
        args = request.page.page_name

    key = cache_key(request, (macro.name, args, latest_edit(request)))

    map_text = 'usemap="#%s" ' % (key)

    if not cache_exists(request, key):
        succ, data, mappi = draw_topology(request, args, key)
        if not succ:
            return mappi

        mappi = encode_page(mappi)
        cache.put(request, key, data, content_type='image/png')
        cache.put(request, key + '-map', mappi, content_type='text/html')
    else:
        mappifile = cache._get_datafile(request, key + '-map')
        mappi = mappifile.read()
        mappifile.close()

    div = u'<div class="ClarifiedTopology">\n' + \
        u'<img %ssrc="%s" alt="%s">\n</div>\n' % \
        (map_text, cache.url(request, key), _('topology'))

    map = u'<map id="%s" name="%s">\n' % (key, key)
    map += decode_page(mappi)
    map += u'</map>\n'

    return div + map
示例#2
0
def execute(macro, args):
    request = macro.request

    # Handle GET arguments
    level = '4'
    level_text = '7'

    if not args:
        args = ''

    arglist = [x.strip() for x in args.split(',') if x]

    if not cairo_found:
        return "Cairo not found."

    key = cache_key(request, (macro.name, arglist))

    if not cache_exists(request, key):
        law = None
        if len(arglist) == 1:
            level = args[0]
        elif len(arglist):
            level = args[0]
            if arglist[1].isdigit():
                level_text = ','.join(arglist[1:])
            else:
                level_text = ''
                law = ','.join(arglist[1:])

        data = plot_tll(level, level_text, law)
        cache.put(request, key, data, content_type='image/png')

    f = macro.formatter

    divfmt = {"class": "ST"}

    result = f.div(1, **divfmt)
    result += f.image(src=cache.url(request, key), alt=LAW.format(level_text))
    result += f.div(0)
    return result
示例#3
0
def execute(macro, args):
    request = macro.request

    # Handle GET arguments
    level = '4'
    level_text = '7'

    if not args:
        args = ''

    arglist = [x.strip() for x in args.split(',') if x]

    if not have_cairo():
        return "Cairo not found."

    key = cache_key(request, (macro.name, arglist))

    if not cache_exists(request, key):
        law = None
        if len(arglist) == 1:
            level = args[0]
        elif len(arglist):
            level = args[0]
            if arglist[1].isdigit():
                level_text = ','.join(arglist[1:])
            else:
                level_text = ''
                law = ','.join(arglist[1:])

        data = plot_tll(level, level_text, law)
        cache.put(request, key, data, content_type='image/png')

    f = macro.formatter

    divfmt = {"class": "ST"}

    result = f.div(1, **divfmt)
    result += f.image(src=cache.url(request, key), alt=LAW.format(level_text))
    result += f.div(0)
    return result
示例#4
0
def execute(macro, args):
    request = macro.request

    if not cairo_found:
        return "Cairo not found."

    if not args:
        key = DEFAULT
    elif not hasattr(request.cfg, 'gwiki_markings'):
        return "No gwiki_markings in configuration."
    else:
        try:
            val = request.cfg['gwiki_markings'][args]
            key = list()
            for line in val:
                if not isinstance(line, unicode):
                    return ("Marking misconfiguration " +
                            "(not a tuple of unicode strings)")
                key.append((line, CAIRO_BOLD))
        except KeyError:
            return "Marking not in gwiki_markings."

    level_text = ' '.join(x[0] for x in key)
    ckey = cache_key(request, (macro.name, key))

    if not cache_exists(request, ckey):
        data = plot_box(key)
        cache.put(request, ckey, data, content_type='image/png')

    f = macro.formatter

    divfmt = {"class": "CM"}

    result = f.div(1, **divfmt)
    result += f.image(src=cache.url(request, ckey), alt=level_text)
    result += f.div(0)
    return result
示例#5
0
    def execute(self):
        request = self.request
        _ = request.getText

        pagename = request.page.page_name
        if not request.user.may.read(pagename):
            fault = _(u'Can not read page') + u'\n'
            if self.inline:
                request.write(request.formatter.text(fault))
                return
            request.content_type = 'text/plain'
            request.write(fault)
            return

        form = values_to_form(request.values)
        self.formargs(form)

        if self.help or not self.attachment:
            enter_page(request, pagename, 'View .gv attachment')

            self.sendForm()

            if self.help:
                # This is the URL addition to the nodes that have graph data
                self.urladd = url_parameters(form)
                self.urladd = self.urladd.replace('&help=Inline', '')
                request.write('&lt;&lt;ViewDot(' + self.urladd + ')&gt;&gt;')

            exit_page(request, pagename)
            return

        if not self.attachment[:10].lower() == 'attachment':
            fault = _(u'No attachment defined') + u'\n'
            if self.inline:
                request.write(request.formatter.text(fault))
                return
            request.content_type = 'text/plain'
            request.write(fault)
            return

        self.attachment = self.attachment[11:]

        pagename, filename = AttachFile.absoluteName(self.attachment,
                                                     self.pagename)
        if not request.user.may.read(pagename):
            fault = _(u'Can not read attachment page') + u'\n'
            if self.inline:
                request.write(request.formatter.text(fault))
                return
            request.content_type = 'text/plain'
            request.write(fault)
            return

        fname = wikiutil.taintfilename(filename)
        fpath = AttachFile.getFilename(request, pagename, fname)

        try:
            data = file(fpath, 'r').read()
        except IOError:
            fault = _(u'Can not read attachment') + u'\n'
            if self.inline:
                request.write(request.formatter.text(fault))
                return
            request.content_type = 'text/plain'
            request.write(fault)
            return

        if not have_gv():
            fault = _(u"ERROR: Graphviz Python extensions not installed. " +\
                      u"Not performing layout.")
            if self.inline:
                request.write(request.formatter.text(fault))
                return
            request.content_type = 'text/plain'
            request.write(fault)
            return

        self.cache_key = cache_key(self.request,
                                   [data, self.graphengine, self.format])
        key = "%s-%s" % (self.cache_key, self.format)

        if self.format in ['zgr', 'svg']:
            formatcontent = 'svg+xml'
        else:
            formatcontent = self.format

        if not cache_exists(request, key):
            graphviz = Graphviz(engine=self.graphengine, string=data)
            data = self.getLayoutInFormat(graphviz, self.format)

            cache.put(self.request, key, data, content_type=formatcontent)

        if self.format in ['zgr', 'svg']:
            # Display zgr graphs as applets
            if self.format == 'zgr':
                image_p = lambda url, text: \
                    '<applet code="net.claribole.zgrviewer.ZGRApplet.class"'+ \
                    ' archive="%s/gwikicommon/zgrviewer/zvtm.jar,' % \
                    (self.request.cfg.url_prefix_static) + \
                    '%s/gwikicommon/zgrviewer/zgrviewer.jar" ' % \
                    (self.request.cfg.url_prefix_static) + \
                    'width="%s" height="%s">' % (form_escape(self.width), form_escape(self.height))+\
                    '<param name="type" ' + \
                    'value="application/x-java-applet;version=1.4" />' + \
                    '<param name="scriptable" value="false" />' + \
                    '<param name="svgURL" value="%s" />' % (url) + \
                    '<param name="title" value="ZGRViewer - Applet" />'+ \
                    '<param name="appletBackgroundColor" value="#DDD" />' + \
                    '<param name="graphBackgroundColor" value="#DDD" />' + \
                    '<param name="highlightColor" value="red" />' + \
                    ' </applet><br>\n'
            else:
                image_p = lambda url, text: \
                    '<object data="%s" alt="%s" ' % (url, text) + \
                    'type="image/svg+xml">\n' + \
                    '<embed src="%s" alt="%s" ' % (url, text) + \
                    'type="image/svg+xml"/>\n</object>'
        else:
            image_p = lambda url, text: \
                '<img src="%s" alt="%s">\n' % (url, text)

        image_uri = cache.url(self.request, key)

        if not self.inline:
            if self.format == 'zgr':
                request.write('<html><body>')

        request.write(image_p(image_uri, _('visualisation')))

        if not self.inline and self.format == 'zgr':
            request.write('</html></body>')
        else:
            pass # No footer
示例#6
0
    def execute(self):
        request = self.request
        _ = request.getText

        pagename = request.page.page_name
        if not request.user.may.read(pagename):
            fault = _(u'Can not read page') + u'\n'
            if self.inline:
                request.write(request.formatter.text(fault))
                return
            request.content_type = 'text/plain'
            request.write(fault)
            return

        form = values_to_form(request.values)
        self.formargs(form)

        if self.help or not self.attachment:
            enter_page(request, pagename, 'View .gv attachment')

            self.sendForm()

            if self.help:
                # This is the URL addition to the nodes that have graph data
                self.urladd = url_parameters(form)
                self.urladd = self.urladd.replace('&help=Inline', '')
                request.write('&lt;&lt;ViewDot(' + self.urladd + ')&gt;&gt;')

            exit_page(request, pagename)
            return

        if not self.attachment[:10].lower() == 'attachment':
            fault = _(u'No attachment defined') + u'\n'
            if self.inline:
                request.write(request.formatter.text(fault))
                return
            request.content_type = 'text/plain'
            request.write(fault)
            return

        self.attachment = self.attachment[11:]

        pagename, filename = AttachFile.absoluteName(self.attachment,
                                                     self.pagename)
        if not request.user.may.read(pagename):
            fault = _(u'Can not read attachment page') + u'\n'
            if self.inline:
                request.write(request.formatter.text(fault))
                return
            request.content_type = 'text/plain'
            request.write(fault)
            return

        fname = wikiutil.taintfilename(filename)
        fpath = AttachFile.getFilename(request, pagename, fname)

        try:
            data = file(fpath, 'r').read()
        except IOError:
            fault = _(u'Can not read attachment') + u'\n'
            if self.inline:
                request.write(request.formatter.text(fault))
                return
            request.content_type = 'text/plain'
            request.write(fault)
            return

        if not gv_found:
            fault = _(u"ERROR: Graphviz Python extensions not installed. " +\
                      u"Not performing layout.")
            if self.inline:
                request.write(request.formatter.text(fault))
                return
            request.content_type = 'text/plain'
            request.write(fault)
            return

        self.cache_key = cache_key(self.request,
                                   [data, self.graphengine, self.format])
        key = "%s-%s" % (self.cache_key, self.format)

        if self.format in ['zgr', 'svg']:
            formatcontent = 'svg+xml'
        else:
            formatcontent = self.format

        if not cache_exists(request, key):
            graphviz = Graphviz(engine=self.graphengine, string=data)
            data = self.getLayoutInFormat(graphviz, self.format)

            cache.put(self.request, key, data, content_type=formatcontent)

        if self.format in ['zgr', 'svg']:
            # Display zgr graphs as applets
            if self.format == 'zgr':
                image_p = lambda url, text: \
                    '<applet code="net.claribole.zgrviewer.ZGRApplet.class"'+ \
                    ' archive="%s/gwikicommon/zgrviewer/zvtm.jar,' % \
                    (self.request.cfg.url_prefix_static) + \
                    '%s/gwikicommon/zgrviewer/zgrviewer.jar" ' % \
                    (self.request.cfg.url_prefix_static) + \
                    'width="%s" height="%s">' % (form_escape(self.width), form_escape(self.height))+\
                    '<param name="type" ' + \
                    'value="application/x-java-applet;version=1.4" />' + \
                    '<param name="scriptable" value="false" />' + \
                    '<param name="svgURL" value="%s" />' % (url) + \
                    '<param name="title" value="ZGRViewer - Applet" />'+ \
                    '<param name="appletBackgroundColor" value="#DDD" />' + \
                    '<param name="graphBackgroundColor" value="#DDD" />' + \
                    '<param name="highlightColor" value="red" />' + \
                    ' </applet><br>\n'
            else:
                image_p = lambda url, text: \
                    '<object data="%s" alt="%s" ' % (url, text) + \
                    'type="image/svg+xml">\n' + \
                    '<embed src="%s" alt="%s" ' % (url, text) + \
                    'type="image/svg+xml"/>\n</object>'
        else:
            image_p = lambda url, text: \
                '<img src="%s" alt="%s">\n' % (url, text)

        image_uri = cache.url(self.request, key)

        if not self.inline:
            if self.format == 'zgr':
                request.write('<html><body>')

        request.write(image_p(image_uri, _('visualisation')))

        if not self.inline and self.format == 'zgr':
            request.write('</html></body>')
        else:
            pass  # No footer