def main():
"""
Draws the topology of the SCION network in a gen folder.
example: python scion_topology_graph -g "gen", -e, -n:
will place a pdf file of the scion topology with edge and node labels
into output/scion_topo.gv
-g: path to the gen folder ex: SCION/gen
-e: set this flag if edge labels should be drawn
-n: set this flag if node labels should be drawn
-o: path to the output file ex: output/scion_topo.gv
"""
parser = argparse.ArgumentParser()
parser.add_argument('-g', '--gen_folder_path', default="gen",
help='path to the gen folder')
parser.add_argument('-e', '--edge_labels', action='store_true', default=False,
help='set this flag if you want edge labels')
parser.add_argument('-n', '--node_labels', action='store_true', default=False,
help='set this flag if you want node labels')
parser.add_argument('-o', '--output_path', default="output/scion_topo.gv",
help='path to the output topology file')
args = parser.parse_args()
topo = parse_gen_folder(args.gen_folder_path)
dot = draw_SCION_topology(topo, args.node_labels, args.edge_labels)
s = Source(dot, filename=dot.filename, format="pdf")
s.render(directory=args.output_path)
python类Source()的实例源码
def disassemble_sample_get_svg(sample_id, address):
"""
Gets SVG file data, with functions names.
"""
graph = disassemble_sample(sample_id, address)
filename = Sample.query.get(sample_id).storage_file
data = Source(graph, format='svg')
out_file = filename + "_disass_"
if address is not None:
out_file += hex(address)
out_file = data.render(out_file)
beautify_svg(out_file)
svg_data = open(out_file, 'rb').read()
elements = re.findall("func_<!-- -->[0-9a-f]{3,}h", svg_data)
for e in elements:
et = e[13:-1]
for i in Sample.query.get(sample_id).functions:
if i.address == et:
svg_data = svg_data.replace(e, i.name)
elements = re.findall("loc_[0-9a-f]{3,}h", svg_data)
for e in elements:
et = e[4:-1]
for i in Sample.query.get(sample_id).functions:
if i.address == et:
svg_data = svg_data.replace(e, i.name)
return svg_data
def plotPipelineStructure(self):
'''
Plot pipeline structure
@return iPython display object
'''
#Graph setup
g1 = gv.Digraph(format='svg')
g1.graph_attr['rankdir'] = 'LR'
g1.node_attr['shape'] = 'rounded'
g1.node_attr['fontname'] = 'Arial'
g1.node_attr['fontsize'] = '9'
g1.node_attr['style'] = 'filled'
g1.node_attr['margin'] = '0.1'
g1.node_attr['height'] = '0.1'
g1.node_attr['fillcolor'] = '#fff7da'
#g1.node_attr['shape'] = 'plaintext' #use this to remove boxes around nodes
nodelist= self.getMetadataNestedGraph()
print (nodelist)
src = Source(nodelist)
print (dir(src))
src.format='svg'
src.render('img/plotPipelineStructure')
# for s in nodelist:
# g1.node(s)
# g1.edges(zip(nodelist, nodelist[1:]))
# g1.render('img/plotPipelineStructure')
# print(nodelist)
# print(g1.source)
# return display(SVG('img/plotPipelineStructure.svg'))
return display(SVG('img/plotPipelineStructure.svg'))
#++++++++++ NEW Victor +++++++++++