def get_slices(): with open(slice_file) as f: sast = parse(f.read()) slices = dict() for gast in sast.children: sg = Graph.build('dot', gast) slices[gast.children[1].label] = sg return slices
def test_dot_tools(process): runner = fair_bpm.FlexibleJobRunner() job = process.createJob(111) runner.execute_job(job) tree = parse(job.to_dot()) assert len(str(tree)) > 10 g = SimpleGraph.build(tree.kid('Graph')) assert len(g.nodes) == 4 assert len(g.edges) == 3 assert g.nodes['id44']['state'] == 'COMPLETE'
def test_run_job(process): ps = process runner = fair_bpm.FlexibleJobRunner() print("ps=" + str(ps)) job = ps.createJob(111) runner.execute_job(job) tree = parse(job.to_dot()) g = SimpleGraph.build(tree.kid('Graph')) for node in g.nodes: # print("Node -> "+str(node)) assert g.nodes[node]['state'] == 'COMPLETE'
def get_subgraphs(slices): with open(pattern_file) as f: past = parse(f.read()) subgraphs = list() for i in xrange(0, len(past.children), 2): gast = past.children[i] comment = past.children[i+1].children[0].label sg = Graph.build('dot', gast) labels = set(label for label in sg.nodes.itervalues()) if ((label is None or label in labels) and any(l.startswith('3:call') and 'Iterator' not in l for l in labels) ): subgraphs.append((sg, [slices[e] for e in parse_examples(comment)])) return subgraphs
def parse(cls, dot): tree = parse(dot) id = tree.kid('Graph').children[1].label g = SimpleGraph.build(tree.kid('Graph')) ps = Process(id) for node in g.nodes: #print("About to parse node "+str(node)) ps.activities.append(Activity.parse_from_dot(node, g.nodes[node])) for edge in g.edges: parent = ps.find_activity_by_id(edge[0]) child = ps.find_activity_by_id(edge[1]) if edge[2]: child.add_parent([parent.id, edge[2]]) else: child.add_parent(parent.id) return ps
from dot_tools import parse from dot_tools.dot_graph import SimpleGraph import pickle import sys import warnings warnings.filterwarnings("ignore") filename = sys.argv[1] with open(filename,"r") as fin: dotStr = fin.read() tree = parse(dotStr) g = SimpleGraph.build(tree.kid('Graph')) #print g.nodes.keys() #print g.edges try: name = filename.split('/')[-1].split('.')[0] except: name = "pickle_file" with open(name+".pickle","wb") as fin: pickle.dump(g.nodes.keys(),fin) pickle.dump(g.edges,fin)
def parse_to_simple_graph(cls, dot): tree = parse(dot) g = SimpleGraph.build(tree.kid('Graph')) return g
# coding: utf-8 # In[6]: from dot_tools import parse with open("8.dot", "r") as myfile: data = myfile.read() # In[9]: data = data.replace("Digraph", "digraph") # In[10]: tree = parse(data) # In[11]: from dot_tools.dot_graph import SimpleGraph # In[12]: g = SimpleGraph.build(tree.kid('Graph')) # In[13]: constant = ' "id":"1", "fontcolor":"blue","shape":"plaintext","label":"Cluster ID: 1344\\nSpecific Mutation Type: Response time change\\nCost: 206331909\\nOverall Mutation Type: Originating_Cluster and_Response_Time_Change\\nCandidate originating clusters: \\n\\nAvg. response times: 42170 us ; 70959 us\\nStandard Deviations: 7580 us ; 13811 us\\nKS-Test2 P-value: 0.000\\nCluster likelihood: 0.0340 ; 0.0291\\nPercent makeup: 54 / 46\\nrequests: 7167 ; 6082" ' # In[20]: import json
def DOTParser(pdgfile): with open(pdgfile, "r") as fin: dotStr = fin.read() tree = parse(dotStr) graph = SimpleGraph.build(tree.kid('Graph')) return graph
# pip install ply betterast from dot_tools import parse tree = parse('digraph { x [label=<<b>I am an html label</b>>] x -> y }') print tree print tree.dotty()