def expand_macro(self, formatter, name, content): formatter.req.perm.assert_permission('TICKET_VIEW') self._seen_tickets = [] options, kw = parse_args(content) if len(options) == 0: options = [''] # Generate graph header # result = "digraph G%s { rankdir = \"LR\"\n node [ style=filled ]\n" \ # % (options[0]) result = 'digraph G { rankdir = \"LR\"\n node [ style=filled ]\n' graphviz = Graphviz(self.env) if len(options) > 1 and options[1] is not '': self._maxdepth = int(options[1]) if len(options) == 0 or (len(options) > 0 and options[0] == ''): result += self._depgraph_all(formatter.req) else: result += self._depgraph(formatter.req, options[0], 0) # Add footer result += "\n}" # Draw graph and return result to browser return graphviz.expand_macro(formatter, "graphviz", result)
def generate_image(): repo = request.args.get('repository') filepath = request.args.get('filepath') dot_file = "" png_file = "" try: # Pull the file from GitHub dot_file = GitHub.download_file(repo, filepath) # Generate Graphviz image from dot file png_file = Graphviz.generate_png(dot_file) except GitHubFileDownloadException: app.logger.error(f'Error downloading {filepath} from {repo}') return send_file('static/404.png', mimetype='image/png') except GraphvizRenderException: app.logger.error(f'Error rendering {filepath} from {repo}') return send_file('static/404.png', mimetype='image/png') # Remove the png file after the file is sent @after_this_request def remove_file(response): os.remove(dot_file) os.remove(png_file) return response return send_file(png_file, mimetype='image/png')
def __init__(self, name=None): if name: self._name = name self.load() self._painter = Graphviz() return
def create_graphviz(self, file_name, attr_label_vertex=None, source=None, attr_label_edge=None): dot = Graphviz() # Review attribute directed of graph if DIRECTED in self.attr: if self.attr[DIRECTED]: dot = Digraph() else: dot = Graphviz() if attr_label_vertex is None: # Map graph to graphviz structure for n in list(self.vertices.keys()): dot.node(str(n), str(n)) else: # Map graph to graphviz structure and add vertex attribute for n in list(self.vertices.keys()): label = "Node: " + str(n) source_label = "Node source: " + str( source) if source is not None else "" label = label + "\n" + source_label label = label + "\n" + attr_label_vertex + " (" + str( self.vertices[n].attributes[attr_label_vertex]) + ")" dot.node(str(n), label) if attr_label_edge is None: for e in self.get_edges(): (s, t) = e dot.edge(str(s), str(t)) else: for e in self.get_edges(): (s, t) = e label_edge = self.edges[(s, t)].attr["WEIGHT"] dot.edge(str(s), str(t), label=str(label_edge)) file = open("./images/gv/" + file_name + ".gv", "w") file.write(dot.source) file.close() return dot
def get_node_details(name): name = name.lower() graph = Graphviz() node = graph.find_node_by_name(name) nodeGraph = pydot.Dot() nodeGraph.add_node(node) for e in graph.find_edges(name): dest_node = graph.find_node_by_name(e.get_destination()) nodeGraph.add_node(dest_node) nodeGraph.add_edge(pydot.Edge(node.get_name(), e.get_destination())) nodeGraph.write(path=f"{name}.svg", format="svg") with open(f"{name}.svg", "r") as imageFile: f = imageFile.read().replace('\n', '') os.remove(f"{name}.svg") return render_template('service.html', title=name, desc="desc", img=Markup(f))
def generate(): code.configure(state='normal') code.delete('1.0', END) code.insert(1.0, Graphviz.generateText(NpmParser.getPackage(package_name.get())))
import sys from parser import NpmParser from graphviz import Graphviz args = sys.argv if len(args) != 2: print('Error! Wrong number of arguments') exit() print(Graphviz.generateText(NpmParser.getPackage(args[1])))
def parse_request(): json = request.get_json() name = json["serviceName"] event_type = json["eventType"] metadata = json["serviceMetadata"] service_type = json["serviceType"] dependencies = json["dependencies"] graph = Graphviz() node_names = graph.node_names_list() if event_type == "DESTROY": app.logger.info('DESTROY event') if name in node_names: graph.del_edges_by_name(name) graph.del_node(name) graph.write("gv") file = graph.write("svg") return send_file(file, mimetype=SVG_MIME_TYPE) if name not in node_names: node_app = create_record_node(name, service_type, metadata) graph.add_node(node_app) else: node = graph.find_node_by_name(name) node_app = update_record_node(node, service_type, metadata) record_enabled = True edges = [] for e in graph.find_edges(name): edges.append(e.get_destination()) deps = [] for dep in dependencies: for svc in dependencies[dep]: app.logger.info('svc: %s', svc) deps.append(svc) if svc not in edges: dep_type = dependency_type(dep) node_svc = create_record_node( svc, dep_type, "" if dep_type == "db" or dep_type == "3rd party" else "N/D") graph.add_node(node_svc) graph.add_edge(node_app, node_svc) for e in graph.find_edges(name): if e.get_destination() not in deps: graph.del_edge(name, e.get_destination()) graph.write("gv") file = graph.write("svg") return send_file(file, mimetype=SVG_MIME_TYPE)
def index(): graph = Graphviz() file = graph.write("svg") return send_file(file, mimetype=SVG_MIME_TYPE)