예제 #1
0
def expressions_to_html(expressions):
    rows = ""
    for expression in expressions:
        dot_string = expression_to_dot(expression)
        target, query = expression_to_sparql(expression)

        dot_path = "/tmp/quepy_graph.dot"
        cmdline = "dot -Tpng %s" % dot_path

        with open(dot_path, "w") as filehandler:
            filehandler.write(dot_string)

        try:
            call = subprocess.Popen(cmdline.split(), stdout=subprocess.PIPE)
            output, _ = call.communicate()
        except OSError:
            msg = "Error running '{}': the program 'dot' was not found."
            print msg.format(cmdline)
            sys.exit(1)

        image_base64 = base64.b64encode(output)

        query = "\n".join([x for x in query.split("\n")
                           if not x.startswith("PREFIX")])
        query = escape(query)
        code = expression.source_code.split("\n")
        name = code[0].replace("def", "").replace("_", " ").strip(" :()")
        code = "\n".join(code[1:-2])
        rows += QUERY_TEMPLATE.format(name=name.capitalize(),
                                      code=code,
                                      sparql=query,
                                      image_base64=image_base64)

    html = HTML_TEMPLATE.format(rows=rows)
    with open("expression_inform.html", "w") as filehandler:
        filehandler.write(html)
예제 #2
0
 def test_dot_takes_unicode(self):
     e = gen_fixedtype(u"·̣─@łæßð~¶½")
     e += gen_datarel(u"tµŧurułej€", u"←ðßðæßđæßæđßŋŋæ @~~·ŋŋ·¶·ŋ“¶¬@@")
     s = expression_to_dot(e)
     self._standard_check(s, e)
예제 #3
0
 def test_dot_takes_unicode(self):
     e = gen_fixedtype(u"·̣─@łæßð~¶½")
     e += gen_datarel(u"tµŧurułej€", u"←ðßðæßđæßæđßŋŋæ @~~·ŋŋ·¶·ŋ“¶¬@@")
     s = expression_to_dot(e)
     self._standard_check(s, e)