def run(self):

        node = graphviz()
        dotted = self.arguments[0].split()[0]

        # Get the workflow for ``dotted``.
        try:
            workflow = Workflow(dotted)
        except WorkflowException as err:
            return [node.document.reporter.warning(
                err.args[0], line=self.lineno)]

        node['code'] = workflow.generate_dot(self.name)
        node['options'] = {}
        if 'graphviz_dot' in self.options:
            node['options']['graphviz_dot'] = self.options['graphviz_dot']
        if 'alt' in self.options:
            node['alt'] = self.options['alt']
        if 'inline' in self.options:
            node['inline'] = True

        caption = self.options.get('caption')
        if caption:
            node = figure_wrapper(self, node, caption)

        return [node]
Example #2
0
 def make_field(self, directive):
     # treat content like docfields.Field
     value = directive.options.get(self.name)
     if value:
         name = nodes.field_name('', self.label)
         para = nodes.paragraph(rawsource=value)
         bases = value.split(',')
         # graph attributes
         code = ['rankdir=LR;']
         code += ['size="8.0, 12.0";']
         t = directive.arguments[0]
         # node attributes
         node_attrs = ', '.join([
             'shape="box"', 'fontsize="10"', 'height="0.25"',
             'fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans"',
             'style="setlinewidth(0.5) filled"', 'fillcolor="khaki3:khaki1"'
         ])
         code += ['%s [%s, label="%s"];' % (t, node_attrs, t)]
         code += [
             '%s [%s, label="%s"];' % (b, node_attrs, b) for b in bases
         ]
         code += ['%s -> %s;' % (t, b) for b in bases]
         node = graphviz.graphviz()
         node['code'] = 'digraph I {\n%s\n}\n' % '\n'.join(code)
         node['options'] = {}
         body = nodes.field_body('', node)
         return nodes.field('', name, body)
    def process_doctree(self, doctree, docname):
        for graph_node in doctree.traverse(traceable_graph):
            # Determine graph's starting traceables.
            start_tags = graph_node["traceable-tags"]
            start_traceables = self.get_start_traceables(start_tags,
                                                         graph_node)
            if not start_traceables:
                self.env.warn_node("Traceables: no valid tags for graph,"
                                   " so skipping graph", node)
                continue

            # Determine relationships to include in graph.
            input = graph_node.get("traceable-relationships")
            relationship_length_pairs = self.parse_relationships(input)

            # Construct input for graph.
            graph_input = self.construct_graph_input(start_traceables,
                                                     relationship_length_pairs)

            # Generate diagram input and create output node.
            graphviz_node = graphviz.graphviz()
            graphviz_node["code"] = self.generate_dot(graph_input)
            graphviz_node["options"] = []
            graphviz_node["inline"] = False
#            caption = "Relationship diagram for {0}".format(traceable.tag)
#            figure_node = graphviz.figure_wrapper(self, graphviz_node,
#                                                  caption)
            graph_node.replace_self(graphviz_node)
Example #4
0
    def process_doctree(self, doctree, docname):
        for graph_node in doctree.traverse(traceable_graph):
            # Determine graph's starting traceables.
            start_tags = graph_node["traceables-tags"]
            start_traceables = self.get_start_traceables(start_tags,
                                                         graph_node)
            if not start_traceables:
                message = ("Traceables: no valid tags for graph,"
                           " so skipping graph")
                self.env.warn_node(message, graph_node)
                msg = nodes.system_message(message=message,
                                           level=2, type="ERROR",
                                           source=graph_node["source"],
                                           line=graph_node["line"])
                graph_node.replace_self(msg)
                continue

            # Determine relationships to include in graph.
            input = graph_node.get("traceables-relationships")
            relationship_length_pairs = self.parse_relationships(input)

            # Construct input for graph.
            graph_input = self.construct_graph_input(start_traceables,
                                                     relationship_length_pairs)

            # Generate diagram input and create output node.
            graphviz_node = graphviz.graphviz()
            graphviz_node["code"] = self.generate_dot(graph_input)
            graphviz_node["options"] = {}
            caption = graph_node.get("traceables-caption", "Traceables graph")
            graphviz_node["alt"] = caption
            graph_node.replace_self(graphviz_node)
    def process_doctree(self, doctree, docname):
        for graph_node in doctree.traverse(traceable_graph):
            # Determine graph's starting traceables.
            start_tags = graph_node["traceables-tags"]
            start_traceables = self.get_start_traceables(
                start_tags, graph_node)
            if not start_traceables:
                message = ("Traceables: no valid tags for graph,"
                           " so skipping graph")
                self.node_warning(self.env, message, graph_node)
                msg = nodes.system_message(message=message,
                                           level=2,
                                           type="ERROR",
                                           source=graph_node["source"],
                                           line=graph_node["line"])
                graph_node.replace_self(msg)
                continue

            # Determine relationships to include in graph.
            input = graph_node.get("traceables-relationships")
            relationship_length_pairs = self.parse_relationships(input)

            # Construct input for graph.
            graph_input = self.construct_graph_input(
                start_traceables, relationship_length_pairs)

            # Generate diagram input and create output node.
            graphviz_node = graphviz.graphviz()
            graphviz_node["code"] = self.generate_dot(graph_input)
            graphviz_node["options"] = {}
            caption = graph_node.get("traceables-caption", "Traceables graph")
            graphviz_node["alt"] = caption
            graph_node.replace_self(graphviz_node)
Example #6
0
    def run(self):
        name = self.arguments[0]
        command = directives.choice(self.arguments[1], allowed_commands)

        if command == 'init':
            # Create a temporary file to hold the database
            db_fh = tempfile.NamedTemporaryFile(delete=False)
            ehive_db_urls[name] = 'sqlite:///' + db_fh.name
            command_array = [
                'init_pipeline.pl', self.arguments[2], '-pipeline_url',
                ehive_db_urls[name]
            ]
            for tweak in self.options.get('tweaks', '').split():
                command_array.extend(['-tweak', tweak])
        else:
            db = ehive_db_urls[name]
            if command == 'run_job':
                command_array = [
                    'runWorker.pl', '-url', db, '-job_id', self.arguments[2]
                ]

            elif command == 'sync':
                command_array = ['beekeeper.pl', '-url', db, '-sync']
                if self.options.has_key('analyses_pattern'):
                    command_array.extend([
                        '-analyses_pattern', self.options['analyses_pattern']
                    ])

            elif command == 'analysis_diagram':
                default_config_file = os.environ[
                    "EHIVE_ROOT_DIR"] + os.path.sep + "hive_config.json"
                command_array = [
                    'generate_graph.pl', '-url', db, '-output', '/dev/stdout',
                    '-format', 'dot', '-config_file', default_config_file
                ]

            elif command == 'job_diagram':
                default_config_file = os.environ[
                    "EHIVE_ROOT_DIR"] + os.path.sep + "hive_config.json"
                command_array = [
                    'visualize_jobs.pl', '-url', db, '-output', '/dev/stdout',
                    '-format', 'dot', '-config_file', default_config_file
                ]
                command_array.extend(
                    self.options.get('vj_options', '').split())

        command_array[0] = os.path.join(os.environ["EHIVE_ROOT_DIR"],
                                        'scripts', command_array[0])
        dotcontent = subprocess.check_output(command_array, stderr=sys.stderr)

        if command.endswith('diagram'):
            # We reuse the graphviz node (from the graphviz extension) as it deals better with image formats vs builders
            graphviz_node = graphviz()
            graphviz_node['code'] = dotcontent
            graphviz_node['options'] = {}

            return [graphviz_node]
        else:
            return []
Example #7
0
 def run(self):
     dotcode = self.dotcode()
     if not dotcode.strip():
         return [self.state_machine.reporter.warning(
             'Ignoring "graphviz" directive without content.',
             line=self.lineno)]
     node = graphviz()
     node['code'] = dotcode
     node['options'] = []
     return [node]
Example #8
0
File: conf.py Project: pombreda/yay
    def run(self):
        p = parser.Parser()
        graph = Root(p.parse('\n'.join(self.content) + '\n'))

        node = graphviz()
        node['code'] = '\n'.join(graph.as_digraph())
        node['options'] = []
        if 'alt' in self.options:
            node['alt'] = self.options['alt']
        if 'caption' in self.options:
            node['caption'] = self.options['caption']
        node['inline'] = 'inline' in self.options
        return [node]
Example #9
0
    def run(self):

        # The PipeConfig sample is shown in a literal block
        content = '\n'.join(self.content)
        code_block_node = nodes.literal_block(text=content)

        # We reuse the graphviz node (from the graphviz extension) as it deals better with image formats vs builders
        graphviz_node = graphviz()
        graphviz_node['code'] = generate_dot_diagram(content)
        graphviz_node['options'] = {}

        table = [[[code_block_node], [graphviz_node]]]
        table_node = self.build_table_from_list(table, [50,50], 0, 0)
        return [table_node]
Example #10
0
    def run(self):

        # The PipeConfig sample is shown in a literal block
        content = '\n'.join(self.content)
        code_block_node = nodes.literal_block(text=content)

        # We reuse the graphviz node (from the graphviz extension) as it deals better with image formats vs builders
        graphviz_node = graphviz()
        graphviz_node['code'] = generate_dot_diagram(content)
        graphviz_node['options'] = {}

        table = [[[code_block_node], [graphviz_node]]]
        table_node = self.build_table_from_list(table, 'auto', [50,50], 0, 0)
        return [table_node]
Example #11
0
    def run(self):
        name = self.arguments[0]
        command = directives.choice(self.arguments[1], allowed_commands)

        if command == 'init':
            # Create a temporary file to hold the database
            db_fh = tempfile.NamedTemporaryFile(delete = False)
            ehive_db_urls[name] = 'sqlite:///' + db_fh.name
            command_array = ['init_pipeline.pl', self.arguments[2], '-pipeline_url', ehive_db_urls[name]]
            for tweak in self.options.get('tweaks', '').split():
                command_array.extend(['-tweak', tweak])
        else:
            db = ehive_db_urls[name]
            if command == 'run_job':
                command_array = ['runWorker.pl', '-url', db, '-job_id', self.arguments[2]]

            elif command == 'sync':
                command_array = ['beekeeper.pl', '-url', db, '-sync']
                if self.options.has_key('analyses_pattern'):
                    command_array.extend(['-analyses_pattern', self.options['analyses_pattern']])

            elif command == 'analysis_diagram':
                default_config_file = os.environ["EHIVE_ROOT_DIR"] + os.path.sep + "hive_config.json"
                command_array = ['generate_graph.pl', '-url', db, '-output', '/dev/stdout', '-format', 'dot', '-config_file', default_config_file]

            elif command == 'job_diagram':
                default_config_file = os.environ["EHIVE_ROOT_DIR"] + os.path.sep + "hive_config.json"
                command_array = ['visualize_jobs.pl', '-url', db, '-output', '/dev/stdout', '-format', 'dot', '-config_file', default_config_file]
                command_array.extend(self.options.get('vj_options', '').split())

        command_array[0] = os.path.join(os.environ["EHIVE_ROOT_DIR"], 'scripts', command_array[0])
        dotcontent = subprocess.check_output(command_array, stderr=sys.stderr)

        if command.endswith('diagram'):
            # We reuse the graphviz node (from the graphviz extension) as it deals better with image formats vs builders
            graphviz_node = graphviz()
            graphviz_node['code'] = dotcontent
            graphviz_node['options'] = {}

            return [graphviz_node]
        else:
            return []
Example #12
0
    def run(self):
        module = self.arguments[0]

        # Generate dot:
        save_dir = os.getcwd()
        tmp_dir = tempfile.mkdtemp()
        os.chdir(tmp_dir)
        basename = 'foo'
        cmd = ['pyreverse', '-p', basename]
        classes = self.options.get('classes', [])
        for c in classes:
            raise NotImplementedError('classes option')
            cmd.extend(['-c', c])
        cmd.append(module)
        subprocess.check_call(cmd)
        with open('classes_{}.dot'.format(basename)) as f:
            dotcode = f.read()
        os.chdir(save_dir)

        # create graphviz node:
        node = graphviz()
        node['code'] = dotcode
        node['options'] = {}
        return [node]
Example #13
0
 def run(self):
     package_diagram_node = graphviz()
     package_diagram_node[
         'code'] = 'digraph {A->FAKE->DOT->DIAGRAM}'  # TODO replace hardcoded dot code
     package_diagram_node['options'] = {}
     return [package_diagram_node]
Example #14
0
    def run(self):
        func_name = self.content[0]
        base_name = func_name.split(".")[0]
        if len(func_name.split(".")) == 1:
            func_name = None
        base_path = __import__(base_name).__path__[0]

        direction = "vertical"
        if "direction" in self.options:
            direction = self.options["direction"]
        dotcode = create_callgraph(
            filenames=f"{base_path}/**/*.py",
            function=func_name,
            namespace=base_name,
            format="dot",
            grouped="no-groups" not in self.options,
            draw_uses="no-uses" not in self.options,
            draw_defines="no-defines" not in self.options,
            nested_groups="nested-groups" in self.options,
            colored="no-colors" not in self.options,
            annotated="annotated" in self.options,
            rankdir={
                "horizontal": "LR",
                "vertical": "TB"
            }[direction],
        )
        node = graphviz()

        # insert link targets into groups: first insert link, then reformat link
        if "toctree" in self.options:
            path = self.options["toctree"].strip("/")
            # create raw link
            dotcode = re.sub(
                r'([\w\d]+)(\s.+), (style="filled")',
                r'\1\2, href="../' + path + r'/\1.html", target="_blank", \3',
                dotcode,
            )

            def create_link(dot_name):
                raw_link = re.sub(r"__(\w)", r".\1", dot_name)
                # determine if name this is a class by checking if its first letter is capital
                # (heuristic but should work almost always)
                splits = raw_link.rsplit(".", 2)
                if len(splits) > 1 and splits[-2][0].capitalize(
                ) == splits[-2][0]:
                    # is class
                    link = ".".join(splits[:-1]) + ".html#" + raw_link + '"'
                else:
                    link = raw_link + '.html"'
                return link

            dotcode = re.sub(
                r'(href="../' + path + r'/)(\w+)(\.html")',
                lambda m: m.groups()[0] + create_link(m.groups()[1]),
                dotcode,
            )

        node["code"] = dotcode
        node["options"] = {"docname": self.env.docname}
        if "graphviz_dot" in self.options:
            node["options"]["graphviz_dot"] = self.options["graphviz_dot"]
        if "layout" in self.options:
            node["options"]["graphviz_dot"] = self.options["layout"]
        if "alt" in self.options:
            node["alt"] = self.options["alt"]
        if "align" in self.options:
            node["align"] = self.options["align"]

        if "class" in self.options:
            classes = self.options["class"]
        else:
            classes = []
        if "zoomable" in self.options:
            if len(classes) == 0:
                classes = ["zoomable-callgraph"]
            else:
                classes.append("zoomable-callgraph")
        if len(classes) > 0:
            node["classes"] = classes

        if "caption" not in self.options:
            self.add_name(node)
            return [node]
        else:
            figure = figure_wrapper(self, node, self.options["caption"])
            self.add_name(figure)
            return [figure]
Example #15
0
 def run(self):
     package_diagram_node = graphviz()
     package_diagram_node['code'] = 'digraph {A->FAKE->DOT->DIAGRAM}'  # TODO replace hardcoded dot code
     package_diagram_node['options'] = {}
     return [package_diagram_node]