Exemplo n.º 1
0
def on_doctree_resolved(self, doctree, docname):
    if self.builder.format in ('html', 'slides'):
        return

    try:
        image_format = get_image_format_for(self.builder)
    except Exception as exc:
        if self.builder.config.rackdiag_debug:
            traceback.print_exc()

        self.builder.warn('rackdiag error: %s' % exc)
        for node in doctree.traverse(rackdiag_node):
            node.parent.remove(node)

        return

    for node in doctree.traverse(rackdiag_node):
        try:
            with Application():
                relfn = node.get_relpath(image_format, self.builder)
                image = node.to_drawer(image_format, self.builder)
                if not os.path.isfile(image.filename):
                    image.draw()
                    image.save()

                image = nodes.image(uri=relfn,
                                    candidates={'*': relfn},
                                    **node['options'])
                node.parent.replace(node, image)
        except Exception as exc:
            if self.builder.config.rackdiag_debug:
                traceback.print_exc()

            self.builder.warn('dot code %r: %s' % (node['code'], str(exc)))
            node.parent.remove(node)
Exemplo n.º 2
0
 def decorator(*args):
     with Application():
         return fn(*args)