def shouldBeRegistered(cls): # Check if Graphviz's fdp binary is available. if pygraphviz is not None: try: pygraphviz.AGraph()._which('fdp') return True except: return False if pydot is not None: return (pydot.find_graphviz() or {}).get('fdp', '') != ''
def OnSelectLayout(self, event): if hasattr(event, 'IsDropDownClicked') and event.IsDropDownClicked(): curr_layout = self.graph.GetViewOption('Layout', 0) tb = event.GetEventObject() tb.SetToolSticky(event.GetId(), True) # create the popup menu cntxMenu = wx.Menu() it = cntxMenu.AppendItem( wx.MenuItem( cntxMenu, wx.ID_FILE2, _("&Random layout"), wx.EmptyString, wx.ITEM_CHECK ) ) if curr_layout == 0: it.Check(True) it = cntxMenu.AppendItem( wx.MenuItem( cntxMenu, wx.ID_FILE3, _("&Circular layout"), wx.EmptyString, wx.ITEM_CHECK ) ) if curr_layout == 1: it.Check(True) it = cntxMenu.AppendItem( wx.MenuItem( cntxMenu, wx.ID_FILE4, _("&Shell layout"), wx.EmptyString, wx.ITEM_CHECK ) ) if curr_layout == 2: it.Check(True) it = cntxMenu.AppendItem( wx.MenuItem( cntxMenu, wx.ID_FILE5, _("S&pring layout"), wx.EmptyString, wx.ITEM_CHECK ) ) if curr_layout == 3: it.Check(True) it = cntxMenu.AppendItem( wx.MenuItem( cntxMenu, wx.ID_FILE6, _("Sp&ectral layout"), wx.EmptyString, wx.ITEM_CHECK ) ) if curr_layout == 4: it.Check(True) it = cntxMenu.AppendItem( wx.MenuItem( cntxMenu, wx.ID_FILE7, _("&Align to grid"), wx.EmptyString, wx.ITEM_CHECK ) ) if curr_layout == 5: it.Check(True) # check for the graphviz layouts gvl = pydot.find_graphviz() if gvl is not None: menuid = wx.ID_HIGHEST + 1 for lt in gvl: it = cntxMenu.AppendItem( wx.MenuItem( cntxMenu, menuid, _("Graphviz - %s" % lt), wx.EmptyString, wx.ITEM_CHECK ) ) if curr_layout == lt: it.Check(True) self.grapvizMap[menuid] = lt menuid += 1 # line up our menu with the button # if graphviz found rect = tb.GetToolRect(event.GetId()) pt = tb.ClientToScreen(rect.GetBottomLeft()) pt = self.ScreenToClient(pt) self.PopupMenu(cntxMenu, pt) # make sure the button is "un-stuck" tb.SetToolSticky(event.GetId(), False) else: self.graph.Refresh()
def __init__(self, parent): ''' Constructor ''' ogl.ShapeCanvas.__init__(self, parent) self.SetBackgroundColour(wx.LIGHT_GREY) self.diagram = ogl.Diagram() self.SetDiagram(self.diagram) self.diagram.SetCanvas(self) self.shapes = dict() self.edges = [] self.save_gdi = [] self.graph = None self.middle = None self.showPortHull = None self.newedgeshape = None # look for the graphviz executables # (we cache that per graphviz window... could # probably be done somewhere else...) self.dot = pydot.find_graphviz()
def create(self, prog=None, format='ps'): """Creates and returns a Postscript representation of the graph.""" if prog is None: prog = self.prog if isinstance(prog, (list, tuple)): prog, args = prog[0], prog[1:] else: args = [] if self.progs is None: self.progs = pydot.find_graphviz() if self.progs is None: raise pydot.InvocationException( 'GraphViz\'s executables not found') if not prog in self.progs: raise pydot.InvocationException( 'GraphViz\'s executable "{0}" not found'.format(prog)) if (not os.path.exists(self.progs[prog]) or not os.path.isfile(self.progs[prog])): raise pydot.InvocationException( 'GraphViz\'s executable "{0}" is not a file ' 'or doesn\'t exist'.format(self.progs[prog])) tmp_fd, tmp_name = tempfile.mkstemp() os.close(tmp_fd) self.write(tmp_name) tmp_dir = os.path.dirname(tmp_name) # For each of the image files... for img in self.shape_files: # Get its data f = file(img, 'rb') f_data = f.read() f.close() # Copy it under a file with the same name in the temp dir f = file(os.path.join(tmp_dir, os.path.basename(img)), 'wb') f.write(f_data) f.close() cmdline = [self.progs[prog], '-T' + format, tmp_name] + args self.p = subprocess.Popen( cmdline, cwd=tmp_dir, stderr=subprocess.PIPE, stdout=subprocess.PIPE ) stderr = self.p.stderr stdout = self.p.stdout stdout_output = list() while True: data = stdout.read() if not data: break stdout_output.append(data) stdout.close() stdout_output = ''.join(stdout_output) if not stderr.closed: stderr_output = list() while True: data = stderr.read() if not data: break stderr_output.append(data) stderr.close() if stderr_output: stderr_output = ''.join(stderr_output) status = self.p.wait() if status != 0: raise pydot.InvocationException( 'Program terminated with status: {0}. ' 'stderr follows: {1}'.format(status, stderr_output)) elif stderr_output: print stderr_output # For each of the image files... for img in self.shape_files: # Remove it os.unlink(os.path.join(tmp_dir, os.path.basename(img))) os.unlink(tmp_name) return stdout_output
import subprocess import sys import pydot import unittest PY3 = not sys.version_info < (3, 0, 0) if PY3: NULL_SEP = b'' xrange = range else: NULL_SEP = '' bytes = str DOT_BINARY_PATH = pydot.find_graphviz()['dot'] TEST_DIR = './' REGRESSION_TESTS_DIR = os.path.join(TEST_DIR, 'graphs') MY_REGRESSION_TESTS_DIR = os.path.join(TEST_DIR, 'my_tests') class TestGraphAPI(unittest.TestCase): def setUp(self): self._reset_graphs() def _reset_graphs(self): self.graph_directed = pydot.Graph('testgraph', graph_type='digraph') def test_keep_graph_type(self):
import pydot import graphviz print(pydot.find_graphviz())
import sys import pydot import unittest PY3 = not sys.version_info < (3, 0, 0) if PY3: NULL_SEP = b'' xrange = range else: NULL_SEP = '' bytes = str DOT_BINARY_PATH = pydot.find_graphviz()['dot'] TEST_DIR = './' REGRESSION_TESTS_DIR = os.path.join(TEST_DIR, 'graphs') MY_REGRESSION_TESTS_DIR = os.path.join(TEST_DIR, 'my_tests') class TestGraphAPI(unittest.TestCase): def setUp(self): self._reset_graphs() def _reset_graphs(self): self.graph_directed = pydot.Graph('testgraph', graph_type='digraph')
def Dot2Layout(dotcode, layerView, mode='dot'): G = None try: if platform.platform().lower().find('windows') != -1: pdex = pydot.find_graphviz() cmd = pdex['dot'] if pdex.has_key(mode): cmd = pdex[mode] p = subprocess.Popen( [cmd, '-Txdot'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False, creationflags=0x08000000, universal_newlines=True ) else: p = subprocess.Popen( ['dot', '-Txdot'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False, universal_newlines=True ) xdotcode, error = p.communicate(dotcode) if p.returncode == 0: G = pydot.graph_from_dot_data(xdotcode) else: raise Exception, error except Exception as cond: wx.GetApp().log('[PyDot][err] Processing error: %s' % cond) if G is None: return bb = G.get_bb() if bb is None or bb == '': return try: xo,yo,xm,ym = (float(e) for e in bb.replace('"','').split(',')) layerView.SetViewSize(xm - xo, ym - yo) for nd in G.get_nodes(): attrs = nd.get_attributes() if attrs.get('_draw_') and not attrs.get('bb'): nm = nd.get_name().replace('"', '') w = float(attrs.get('width', '"1"').replace('"', '')) * 72 h = float(attrs.get('height', '"1"').replace('"', '')) * 72 pos = attrs.get('pos', '"100,100"').replace('"', '') px,py = (float(e) for e in pos.split(',')) x = px - xo y = ym - py # if shape shp = layerView.storage.graph_data.get(uuid.UUID(nm), None) if shp: shp.xpos = x shp.ypos = y shp.width = w shp.height = h # if node # for nodes except Exception as cond: wx.GetApp().log('[PyDot][err] Parsing error: %s' % cond) finally: layerView.Refresh() return G
def __check_graphviz(): import pydot if pydot.find_graphviz() is None: return False return True
from keras.models import Model from keras import backend as K from keras.callbacks import EarlyStopping from keras.utils.visualize_util import plot from keras.wrappers.scikit_learn import KerasClassifier, KerasRegressor from hyperopt import Trials, STATUS_OK, tpe from hyperas import optim from hyperas.distributions import choice, uniform, conditional from hyperopt import fmin, tpe, hp from tempfile import TemporaryFile #importing graphics and numpy import numpy import pydot print pydot.find_graphviz() #importing Custom Libraries #manual functions import ArrayFunctions import MathFunctions import DataFunctions import NNFunctions import PlotFunctions import InterpolateFunctions import TimeScaleFunctions import NNFun_PSB import build_lstm_v1 #define hyperopt search space import hyperopt.pyll.stochastic
def diskusage(db, userName, withIndexes=False, percent=True): """Extracts the physical storage of the current user as a picture based on Oracle statistics The generation of the picture is powered by Graphviz (http://www.graphviz.org) through the PyDot API (http://www.dkbza.org/pydot.html) """ # Tries to import pydot module try: from pydot import find_graphviz, Dot, Subgraph, Cluster, Edge, Node except ImportError: message = _("Function not available because pydot module is not installed.\n\t") message += _("Go to http://dkbza.org/pydot.html to get it.") raise PysqlException(message) # Reads conf conf = PysqlConf.getConfig() unit = conf.get("unit") # Unit used to format data format = conf.get("graph_format") # Output format of the picture fontname = conf.get("graph_fontname") # Font used for table names fontsize = conf.get("graph_fontsize") # Font size for table names fontcolor = conf.get("graph_fontcolor") # Color of table and column names tablecolor = conf.get("graph_tablecolor") # Color of tables indexcolor = conf.get("graph_indexcolor") # Color of indexes bordercolor = conf.get("graph_bordercolor") # Color of borders # Gets picture generator prog = getProg(find_graphviz(), conf.get("graph_program"), "fdp") # First step: objects library building # Tablespaces if userName == db.getUsername().upper(): tablespaces = db.executeAll(diskusageSql["Tablespaces"]) else: tablespaces = db.executeAll(diskusageSql["TablespacesFromOwner"], [userName]) tbsBytes = 0 tbsList = [] for tablespace in tablespaces: tablespaceName = unicode(tablespace[0]) # Tables from current tablespace if userName == db.getUsername().upper(): tables = db.executeAll(diskusageSql["TablesFromTbs"], [tablespaceName]) else: tables = db.executeAll(diskusageSql["TablesFromOwnerAndTbs"], [userName, tablespaceName]) tabList = [] print CYAN + _("Extracting %3d tables from tablespace %s") % (len(tables), tablespaceName) + RESET for table in tables: tableName = table[0] if table[1] is None: print RED + _("""Warning: table "%s" removed because no statistics have been found""") \ % (tablespaceName + "/" + tableName) + RESET continue if table[1] == 0: print RED + _("""Warning: table "%s" removed because it is empty""") \ % (tablespaceName + "/" + tableName) + RESET continue numRows = int(table[1]) avgRowLen = float(table[2]) bytes = int(table[3]) tbsBytes += bytes tabList += [[tableName, bytes, numRows, avgRowLen]] if withIndexes: # Indexes from current tablespace if userName == db.getUsername().upper(): indexes = db.executeAll(diskusageSql["IndexesFromTbs"], [tablespaceName]) else: indexes = db.executeAll(diskusageSql["IndexesFromOwnerAndTbs"], [userName, tablespaceName]) idxList = [] print CYAN + _("Extracting %3d indexes from tablespace %s") % (len(indexes), tablespaceName) + RESET for index in indexes: indexName = index[0] if index[1] is None: print RED + _("""Warning: index "%s" removed because no statistics have been found""") \ % (tablespaceName + "/" + indexName) + RESET continue if index[1] == 0: print RED + _("""Warning: index "%s" removed because it is empty""") \ % (tablespaceName + "/" + indexName) + RESET continue numRows = int(index[1]) distinctKeys = int(index[2]) bytes = int(index[3]) tabName = str(index[4]) tbsBytes += bytes idxList += [[indexName, bytes, numRows, distinctKeys, tabName]] else: print CYAN + _("Not extracting indexes from tablespace %s (ignored)") % (tablespaceName) + RESET idxList = [] tbsList += [[tablespaceName, tbsBytes, tabList, idxList]] # Second step: objects drawing graph = Dot(label=userName, overlap="false", splines="true") for tbs in tbsList: tbsName = tbs[0] tbsBytes = tbs[1] tabList = tbs[2] idxList = tbs[3] subGraph = Subgraph("cluster_" + tbsName, bgcolor="palegreen", \ fontname=fontname, fontsize=str(fontsize - 1), \ label="%s\\n(%d %s)" % (tbsName, convert(tbsBytes, unit), unit.upper())) graph.add_subgraph(subGraph) print CYAN + _("Displaying %3d tables for tablespace %s") % (len(tabList), tbsName) + RESET for tab in tabList: name = tab[0] bytes = tab[1] numRows = tab[2] # unused avgRowLen = tab[3] # unused # Mathematics at work width = 0.2 height = 0.2 if percent: height += 10 * round(float(bytes) / tbsBytes, 4) label = "%s\\n(%.2f %s)" % (name, round(100 * float(bytes) / tbsBytes, 2), "%") else: height += round(sqrt(bytes) / 8192, 3) width += round(sqrt(bytes) / 8192, 3) label = "%s\\n(%3d %s)" % (name, convert(bytes, unit), unit.upper()) subGraph.add_node(Node(name, label=label, shape="box", style="filled", \ color="none", fillcolor=tablecolor, \ fontname=fontname, fontcolor=fontcolor, fixedsize="false", \ fontsize=str(fontsize - 2 - floor((len(label) - 7) / 15)), \ nodesep="0.01", height=str(height), width=str(max(width, 1)))) print CYAN + _("Displaying %3d indexes for tablespace %s") % (len(idxList), tbsName) + RESET for idx in idxList: name = idx[0] bytes = idx[1] numRows = idx[2] # unused distinctKeys = idx[3] # unused tabName = idx[4] # unused # Mathematics at work again) width = 0.2 height = 0.2 if percent: height += 10 * round(float(bytes) / tbsBytes, 4) label = "%s\\n(%.2f %s)" % (name, round(100 * float(bytes) / tbsBytes, 2), "%") else: height += round(sqrt(bytes) / 8192, 3) width += round(sqrt(bytes) / 8192, 3) label = "%s\\n(%3d %s)" % (name, convert(bytes, unit), unit.upper()) subGraph.add_node(Node(name, label=label, shape="box", style="filled", \ color="none", fillcolor=indexcolor, \ fontname=fontname, fontcolor=fontcolor, fixedsize="false", \ fontsize=str(fontsize - 2 - floor((len(label) - 7) / 15)), \ nodesep="0.01", height=str(height), width=str(max(width, 1)))) #Moving index near by its table (unused because it widens the graph) #subGraph.add_edge(Edge(src=name, dst=tabName, constraint="false", style="invis")) filename = "du_" + userName + "." + format generateImage(graph, filename, prog, format) viewImage(filename)
#encoding:UTF-8 __author__ = 'auroua' import theano_test.tensor as T from theano_test import function import theano_test import pydot print pydot.find_graphviz() x = T.dmatrix('x') y = x*2 print type(y.owner) print y.owner.op.name print len(y.owner.inputs) print type(y.owner.inputs[1].owner) #apply nodes are those that define which computations the graph does # When compiling a Theano function, what you give to the theano.function is actually a graph # (starting from the output variables you can traverse the graph up to the input variables). # While this graph structure shows how to compute the output from the input, # it also offers the possibility to improve the way this computation is carried out. a = T.vector('a') b = a+a**10 fab = function([a],b) print fab([0,1,2]) theano_test.printing.pydotprint(b, outfile="/home/auroua/symbolic_graph_unopt.png", var_with_name_simple=True) theano_test.printing.pydotprint(fab, outfile="/home/auroua/symbolic_graph_opt.png", var_with_name_simple=True)
def find_neato(): cmds = pydot.find_graphviz() if cmds is not None: if cmds.has_key("neato"): return cmds["neato"]
def pkgTree(db, packageName): """Creates the call tree of internal package functions and procedures""" # Tries to import pydot module try: from pydot import find_graphviz, Dot, Edge, Node except ImportError: message = _("Function not available because pydot module is not installed.\n\t") message += _("Go to http://dkbza.org/pydot.html to get it.") raise PysqlException(message) # Reads conf conf = PysqlConf.getConfig() format = conf.get("graph_format") # Output format of the picture fontname = conf.get("graph_fontname") # Font used for functions names fontsize = conf.get("graph_fontsize") # Font size for functions names fontcolor = conf.get("graph_fontcolor") # Color of functions names # Gets picture generator prog = getProg(find_graphviz(), conf.get("graph_program"), "fdp") package = OraObject(objectName=packageName) package.guessInfos(db) graph = Dot(overlap="false", splines="true") # Lists of function or procedure verbs = [] # Tries to resolve synonym and describe the target #TODO: factorise this code!! if package.getType() == "SYNONYM": package = package.getTarget(db) if package.getType() == "SYNONYM": raise PysqlException(_("Too much synonym recursion")) if package.getType() not in ("PACKAGE", "PACKAGE BODY"): raise PysqlException(_("This is not a package or package not found")) # Gets package body content package.setType(u"PACKAGE BODY") print CYAN + _("Extracting package source...") + RESET content = package.getSQLAsList(db) # Removes comments print CYAN + _("Parsing source and building graph...") + RESET newContent = [] comment = False for line in content: line, comment = removeComment(line, comment) newContent.append(line) content = newContent # Gets procedures and functions for line in content: result = re.match("\s*(FUNCTION|PROCEDURE)\s+(.+?)[\s|\(]+", line, re.I) if result: verbs.append(re.escape(result.group(2))) graph.add_node(Node(result.group(2).upper(), shape="box", label=result.group(2).upper(), \ fontsize=str(fontsize), fontname=fontname, fontcolor=fontcolor)) if not verbs: raise PysqlException(_("This package does not have any readable function or procedure")) verbs = "|".join(verbs) # Gets call of functions/procedure inside each other currentVerb = "" for line in content: # Doesn't pay attention to end lines if re.match("\s*END.*;", line, re.I): continue # Marks the function/procedure we are parsing result = re.match("\s*(FUNCTION|PROCEDURE)\s+(.+?)[\s|\(]+", line, re.I) if result: currentVerb = result.group(2) continue # else we get a circular reference below ;-) result = re.match(".*\s(%s).*" % verbs, line, re.I) if result: if graph.get_edge(currentVerb.upper(), result.group(1).upper()) is None: graph.add_edge(Edge(src=currentVerb.upper(), dst=result.group(1).upper())) filename = package.getName() + "_dep." + format generateImage(graph, filename, prog, format) viewImage(filename)
def datamodel(db, userName, tableFilter=None, withColumns=True): """Extracts the datamodel of the current user as a picture The generation of the picture is powered by Graphviz (http://www.graphviz.org) through the PyDot API (http://www.dkbza.org/pydot.html) @param db: pysql db connection @param userName: schema to be extracted @param tableFilter: filter pattern (in pysql extended syntax to extract only some tables (None means all) @param withColumns: Indicate whether columns are included or not in datamodel picture """ # Tries to import pydot module try: from pydot import find_graphviz, Dot, Edge, Node except ImportError: message = _("Function not available because pydot module is not installed.\n\t") message += _("Go to http://dkbza.org/pydot.html to get it.") raise PysqlException(message) # Reads conf conf = PysqlConf.getConfig() format = conf.get("graph_format") # Output format of the picture fontname = conf.get("graph_fontname") # Font used for table names fontsize = conf.get("graph_fontsize") # Font size for table names fontcolor = conf.get("graph_fontcolor") # Color of table and column names tablecolor = conf.get("graph_tablecolor") # Color of tables bordercolor = conf.get("graph_bordercolor") # Color of tables borders linkcolor = conf.get("graph_linkcolor") # Color of links between tables linklabel = conf.get("graph_linklabel") # Display constraints name or not # Gets picture generator prog = getProg(find_graphviz(), conf.get("graph_program"), "fdp") graph = Dot(splines="compound") # Tables, columns and constraints (temporary and external tables are excluded. So are TOAD tables) if tableFilter: whereClause = generateWhere("table_name", tableFilter) else: whereClause = "1=1" tables = db.executeAll(datamodelSql["tablesFromOwner"] % (userName, whereClause)) nbTables = len(tables) if nbTables == 0: raise PysqlException(_("No table found. Your filter clause is too restrictive or the schema is empty")) tableList = ", ".join(["'%s'" % table[0] for table in tables]) # Table list formated to be used in SQL query print CYAN + _("Extracting %d tables... ") % nbTables + RESET, current = 0 for table in tables: tableName = table[0] content = """<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">""" content += """\n<TR><TD PORT="%s">""" % tableName content += """<FONT FACE="%s" POINT-SIZE="%f" COLOR="%s">""" % (fontname, fontsize, fontcolor) content += tableName content += "</FONT></TD></TR>" if withColumns: columns = db.executeAll(datamodelSql["columnsFromOwnerAndTable"], [userName, tableName]) for column in columns: columnName = column[0] columnType = column[1] content += """\n<TR><TD ALIGN="LEFT" PORT="%s_%s">""" % (tableName, columnName) content += """<FONT FACE="%s" POINT-SIZE="%f" COLOR="%s">""" % \ (fontname, fontsize - 2, fontcolor) if column[2] is None: # Normal field content += " " else: # Primary key field content += "PK%d" % int(column[2]) content += " %s (%s)" % (columnName, columnType) content += "</FONT></TD></TR>" content += "\n</TABLE>>" graph.add_node(Node(tableName, shape="none", label=content, style="filled", \ fillcolor=tablecolor, color=bordercolor)) current += 1 sys.stdout.write("\b\b\b\b\b%4.1f%%" % round(100 * float(current) / nbTables, 1)) sys.stdout.flush() print # Links between tables (foreign key -> primary key) # Only extract links from considered tables links = db.executeAll(datamodelSql["constraintsFromOwner"] % (userName, tableList, tableList)) nbLinks = len(links) print (CYAN + _("Extracting %d links... ") % nbLinks + RESET), current = 0 for link in links: if linklabel == "yes": graph.add_edge(Edge(src=link[1], dst=link[2], color=linkcolor)) else: graph.add_edge(Edge(src=link[1], dst=link[2], label=link[0], color=linkcolor, \ fontcolor=linkcolor, fontname=fontname, fontsize=str(fontsize - 3))) current += 1 sys.stdout.write("\b\b\b\b\b%4.1f%%" % round(100 * float(current) / nbLinks, 1)) print filename = db.getDSN() + "_" + userName + "." + format generateImage(graph, filename, prog, format) viewImage(filename)
def Dot2Layout(dotcode, layerView, mode="dot"): G = None try: if platform.platform().lower().find("windows") != -1: pdex = pydot.find_graphviz() cmd = pdex["dot"] if pdex.has_key(mode): cmd = pdex[mode] p = subprocess.Popen( [cmd, "-Txdot"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False, creationflags=0x08000000, universal_newlines=True, ) else: p = subprocess.Popen( ["dot", "-Txdot"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False, universal_newlines=True, ) xdotcode, error = p.communicate(dotcode) if p.returncode == 0: G = pydot.graph_from_dot_data(xdotcode) else: raise Exception, error except Exception as cond: wx.GetApp().log("[PyDot][err] Processing error: %s" % cond) if G is None: return bb = G.get_bb() if bb is None or bb == "": return try: xo, yo, xm, ym = (float(e) for e in bb.replace('"', "").split(",")) layerView.SetViewSize(xm - xo, ym - yo) for nd in G.get_nodes(): attrs = nd.get_attributes() if attrs.get("_draw_") and not attrs.get("bb"): nm = nd.get_name().replace('"', "") w = float(attrs.get("width", '"1"').replace('"', "")) * 72 h = float(attrs.get("height", '"1"').replace('"', "")) * 72 pos = attrs.get("pos", '"100,100"').replace('"', "") px, py = (float(e) for e in pos.split(",")) x = px - xo y = ym - py # if shape shp = layerView.storage.graph_data.get(uuid.UUID(nm), None) if shp: shp.xpos = x shp.ypos = y shp.width = w shp.height = h # if node # for nodes except Exception as cond: wx.GetApp().log("[PyDot][err] Parsing error: %s" % cond) finally: layerView.Refresh() return G
They all allow different way to print a graph or the result of an Op in a graph(Print Op) """ from copy import copy import logging import os import sys # Not available on all platforms hashlib = None import numpy np = numpy try: import pydot as pd if pd.find_graphviz(): pydot_imported = True else: pydot_imported = False except ImportError: pydot_imported = False import theano from theano import gof from theano import config from theano.compat.six import StringIO from theano.gof import Op, Apply from theano.gof.python25 import any from theano.compile import Function, debugmode from theano.compile.profilemode import ProfileMode
#"transformations.graph" max_num_chars_in_description=70 #only fields of length < max(description_length,max_num_chars_in_description) will be shown in full on the graph do_html=True #Whether html output should be made. Requires availability of pydot # graphviz_location={'dot':'C:\\Program Files\\Graphviz2.26.3\\bin\\dot.exe'} graphviz_location=None #Only necessary if pydot can't find graphviz by itself. Set to None otherwise ############################### #Check if pydot is available try: import pydot use_pydot=True #If pydot can't find the Graphviz executables, explicitly give the location below if not pydot.find_graphviz() and not graphviz_location: print "Graphviz not found, only outputting .graph file" use_pydot=False except: print "pydot not available, use graphviz directly to convert the graph to an image" use_pydot=False if not use_pydot: do_html=False import sys,os #Set input transformation file if len(sys.argv)>1: transformation_file=sys.argv[1] else: transformation_file=default_transformation_file #Read transformation file into list of dicts 'transformations' transformations=[]
def dependencies(db, objectName, direction, maxDepth, maxNodes): """Displays object dependencies as a picture The generation of the picture is powered by Graphviz (http://www.graphviz.org) through the PyDot API (http://www.dkbza.org/pydot.html) @param db: pysql db connection @param objectName: name of the oracle object on which dependancies are computed @param direction: direction of the dependancy graph. Can be "onto", "from" or "both" @param maxDepth: Override default maxDepth value. If None, use default value @param maxNodes: Override default maxNodes value. If None, use default value """ # Tries to import pydot module try: from pydot import find_graphviz, Dot, Edge, Node except ImportError: message = _("Function not available because pydot module is not installed.\n\t") message += _("Go to http://dkbza.org/pydot.html to get it.") raise PysqlException(message) # Reads conf conf = PysqlConf.getConfig() format = conf.get("graph_format") # Output format of the picture fontname = conf.get("graph_fontname") # Font used for object names fontsize = conf.get("graph_fontsize") # Font size for object names # Gets picture generator prog = getProg(find_graphviz(), conf.get("graph_program"), "dot") graph = Dot(overlap="false", splines="true", rankdir="TB") if direction == "onto" or direction == "from": dirList = [direction] elif direction == "both": dirList = ["onto", "from"] else: dirList = [] for currentDir in dirList: depth = 0 objectList = [OraObject(objectName=objectName)] objectList[0].guessInfos(db) objectOwner = objectList[0].getOwner() objectName = objectList[0].getName() objectType = objectList[0].getType() label = objectOwner + "." + objectName + "\\n(" + objectType + ")" graph.add_node(Node(objectName, label=label, fontname=fontname, fontsize=str(fontsize), shape="diamond")) nodeList = [objectName] edgeList = [] nextObjectList = [] while objectList != [] and depth <= maxDepth and len(nodeList) <= maxNodes: depth += 1 for currentObject in objectList: currentObjectOwner = currentObject.getOwner() currentObjectName = currentObject.getName() if currentDir == "onto": # Objects referencing the the current object result = db.executeAll(dependenciesSql["refOnFromOwnerAndName"], \ [currentObjectOwner, currentObjectName]) elif currentDir == "from": # Objects referenced by the the current object result = db.executeAll(dependenciesSql["refByFromOwnerAndName"], \ [currentObjectOwner, currentObjectName]) refObjectList = [OraObject(objectOwner=i[0], objectName=i[1]) for i in result] for currentRefObject in refObjectList: currentRefObject.guessInfos(db) currentRefObjectOwner = currentRefObject.getOwner() currentRefObjectName = currentRefObject.getName() currentRefObjectType = currentRefObject.getType() if not currentRefObjectName in nodeList: nodeList.append(currentRefObjectName) # Object shape if currentRefObjectType in ("TABLE", "VIEW", "SEQUENCE"): shape = "box" elif currentRefObjectType in ("PACKAGE", "FUNCTION", "PROCEDURE", "TRIGGER"): shape = "ellipse" else: shape = "none" # Object label if currentRefObjectOwner == db.getUsername().upper(): label = currentRefObjectName else: label = currentRefObjectOwner + "." + currentRefObjectName label += "\\n(" + currentRefObjectType + ")" # Adding object to graph graph.add_node(Node(currentRefObjectName, label=label, fontname=fontname, \ fontsize=str(fontsize), shape=shape)) if not [currentObjectName, currentRefObjectName] in edgeList: if currentDir == "onto": edgeList.append([currentObjectName, currentRefObjectName]) graph.add_edge(Edge(dst=currentObjectName, src=currentRefObjectName, \ color="red")) elif currentDir == "from": edgeList.append([currentObjectName, currentRefObjectName]) graph.add_edge(Edge(src=currentObjectName, dst=currentRefObjectName, \ color="darkgreen")) nextObjectList += refObjectList objectList = nextObjectList nextObjectList = [] if len(nodeList) > maxNodes: print RED + _("Warning: reach max node, references lookup stopped on direction %s") % currentDir + RESET if depth > maxDepth: print RED + _("Warning: reach max recursion limit, references lookup stopped on direction %s") % currentDir + RESET filename = "dep_" + objectOwner + "." + objectName + "." + format generateImage(graph, filename, prog, format) viewImage(filename)
def find_neato(): cmds = pydot.find_graphviz() if cmds is not None: if cmds.has_key('neato'): return cmds['neato']
They all allow different way to print a graph or the result of an Op in a graph(Print Op) """ from copy import copy import logging import os import sys import warnings import hashlib import numpy as np try: import pydot as pd if pd.find_graphviz(): pydot_imported = True else: pydot_imported = False except ImportError: pydot_imported = False import theano from theano import gof from theano import config from theano.compat.six import StringIO from theano.gof import Op, Apply from theano.compile import Function, debugmode from theano.compile.profilemode import ProfileMode _logger = logging.getLogger("theano.printing")
#!/usr/bin/python # vim: ts=3 sw=3 ai import pydot if pydot.find_graphviz(): # pass print "You have graphviz.. continuing" else: print "You don't have graphviz installed" exit(1) roothints = open('root.hints') print roothints for rootserver in roothints: print rootserver.split()[0] + " -> " + rootserver.split()[4]