def build_reference_graph(): """ Builds a reference graph which shall be the same than the graph of ../test_files. A PyGraphml graph is returned. """ g = pgml.Graph() f1 = g.add_node("1") f2 = g.add_node("2") f3 = g.add_node("3") f4 = g.add_node("4") f5 = g.add_node("5") f6 = g.add_node("6") f1['key1'] = 'motorcycle_test.rb' f2['key1'] = 'lib/motorcycle.rb' f3['key1'] = 'motorcycle_2.rb' f4['key1'] = 'motorcycle_3.rb' f5['key1'] = 'motorcycle_4.rb' f6['key1'] = 'lib/sidecar.rb' g.add_edge(f1, f2) g.add_edge(f1, f3) g.add_edge(f1, f4) g.add_edge(f1, f5) g.add_edge(f4, f6) return g
def main(args): maven_modules = find_maven_modules(args.maven_module_paths) graph = pygraphml.Graph() nodes_store = NodesStore(graph) DependencyGraphBuilder(graph, nodes_store).build_graph(maven_modules) if (args.include_parent_edges): ParentEdgeBuilder(graph, nodes_store).build_graph(maven_modules) write_graph(args.graph_output_path, graph)
def build_reference_graph( self ): """ Builds a reference graph which shall be the same than the graph of ../test_files. A PyGraphml graph is returned. """ g = pgml.Graph() f_1_c = g.add_node( "1" ) f_2_c = g.add_node( "2" ) f_3_c = g.add_node( "3" ) existing_h = g.add_node("4") iostream = g.add_node("5") lib_f_1_h = g.add_node("6") lib_f_2_h = g.add_node("7") lib_f_3_h = g.add_node("8") lib2_f_4_h = g.add_node("9") lib2_f_1_h = g.add_node("10") e_1_x = g.add_node("11") e_2_y = g.add_node("12") f_1_c ['key1'] = 'src/f_1.c' f_2_c ['key1'] = 'src/f_2.c' f_3_c ['key1'] = 'src/f_3.c' existing_h ['key1'] = '../non/existing.h' iostream ['key1'] = 'iostream' lib_f_1_h ['key1'] = 'inc/lib/f_1.h' lib_f_2_h ['key1'] = 'inc/lib/f_2.h' lib_f_3_h ['key1'] = 'inc/lib/f_3.h' lib2_f_4_h ['key1'] = 'inc/lib2/f_4.h' lib2_f_1_h ['key1'] = 'inc/lib2/f_1.h' e_1_x ['key1'] = 'inc/lib/e_1.x' e_2_y ['key1'] = 'inc/lib/e_2.y' g.add_edge( f_3_c, existing_h ) g.add_edge( f_3_c, iostream ) g.add_edge( f_2_c, lib2_f_1_h ) g.add_edge( f_1_c, iostream ) g.add_edge( f_1_c, lib_f_2_h ) g.add_edge( f_1_c, lib_f_1_h ) g.add_edge( lib_f_2_h, lib_f_1_h ) g.add_edge( lib_f_1_h, lib_f_3_h ) g.add_edge( lib_f_1_h, lib2_f_4_h ) g.add_edge( lib_f_3_h, lib_f_1_h ) return g
def build_reference_graph(self): """ Builds a reference graph which shall be the same than the graph of ../test_files. A PyGraphml graph is returned. """ """ List of files by doing: find -iname '*.py' -or -iname '*.pyw' -or -iname '*.py3' Use as basis for constructing the graph ./py/pack3/__init__.py ./py/pack3/file1.py ./py/file3.pyw ./py/pack2/__init__.py ./py/pack2/file3.py ./py/pack2/file2.py ./py/pack2/file1.py ./py/file2.py3 ./py/file1.py ./py/pack1/__init__.py ./py/pack1/file3.py ./py/pack1/file2.py ./py/pack1/file1.py ./py/pack1/subpack1/__init__.py ./py/pack1/subpack1/file3.py ./py/pack1/subpack1/file2.py ./py/pack1/subpack1/file1.py """ g = pgml.Graph() f1 = g.add_node("1") f2 = g.add_node("2") f3 = g.add_node("3") p1_f1 = g.add_node("4") p1_f2 = g.add_node("5") p1_f3 = g.add_node("6") p1_init = g.add_node("7") p1_s1_f1 = g.add_node("8") p1_s1_f2 = g.add_node("9") p1_s1_f3 = g.add_node("10") p1_s1_init = g.add_node("11") p2_f1 = g.add_node("12") p2_f2 = g.add_node("13") p2_f3 = g.add_node("14") p2_init = g.add_node("15") p3_f1 = g.add_node("16") p3_init = g.add_node("17") bogusfile = g.add_node("18") filecmp = g.add_node("19") os = g.add_node("20") pickle = g.add_node("21") sys = g.add_node("22") f1['key1'] = 'file1.py' f2['key1'] = 'file2.py3' f3['key1'] = 'file3.pyw' p1_f1['key1'] = 'pack1/file1.py' p1_f2['key1'] = 'pack1/file2.py' p1_f3['key1'] = 'pack1/file3.py' p1_init['key1'] = 'pack1/__init__.py' p1_s1_f1['key1'] = 'pack1/subpack1/file1.py' p1_s1_f2['key1'] = 'pack1/subpack1/file2.py' p1_s1_f3['key1'] = 'pack1/subpack1/file3.py' p1_s1_init['key1'] = 'pack1/subpack1/__init__.py' p2_f1['key1'] = 'pack2/file1.py' p2_f2['key1'] = 'pack2/file2.py' p2_f3['key1'] = 'pack2/file3.py' p2_init['key1'] = 'pack2/__init__.py' p3_f1['key1'] = 'pack3/file1.py' p3_init['key1'] = 'pack3/__init__.py' bogusfile['key1'] = 'bogusfilename' filecmp['key1'] = 'filecmp' os['key1'] = 'os' pickle['key1'] = 'pickle' sys['key1'] = 'sys' # Root g.add_edge(f1, p1_s1_f1) g.add_edge(f1, p1_init) g.add_edge(f1, p2_init) g.add_edge(f2, sys) g.add_edge(f2, p1_s1_init) # *-import g.add_edge(f2, p1_f1) g.add_edge(f2, os) g.add_edge(f2, p2_init) g.add_edge(f3, p2_init) # *-import g.add_edge(f3, bogusfile) # Pack 1 g.add_edge(p1_f1, p1_s1_f1) g.add_edge(p1_f1, p2_f1) g.add_edge(p1_f2, f1) g.add_edge(p1_f2, f3) g.add_edge(p1_f2, p1_s1_f1) g.add_edge(p1_f3, sys) g.add_edge(p1_init, pickle) # Pack 1, Subpack 1 g.add_edge(p1_s1_f1, f3) g.add_edge(p1_s1_f2, sys) g.add_edge(p1_s1_f2, f1) g.add_edge(p1_s1_f3, filecmp) # Pack 2 (__init__ has __all__ import) g.add_edge(p2_f2, filecmp) g.add_edge(p2_f3, p1_f2) g.add_edge(p2_init, p2_f1) g.add_edge(p2_init, p2_f2) g.add_edge(p2_init, p2_f3) # Pack 3 (__init__ has __all__ import) g.add_edge(p3_init, p3_f1) return g
import pymongo import pygraphml # MongoDB db = pymongo.MongoClient('127.0.0.1', 27017).superblogger g = pygraphml.Graph() nodes = dict() for user in db.users.find({ 'counts.followed_by': { '$gte': 1000000 }, 'follows': { '$exists': True } }): nodes[user['id']] = g.add_node(user['username']) nodes[user['id']]['follows'] = user['counts']['follows'] nodes[user['id']]['followed_by'] = user['counts']['followed_by'] for user in db.users.find({ 'counts.followed_by': { '$gte': 1000000 }, 'follows': { '$exists': True } }): for followed_user_id in user['follows']: if followed_user_id in nodes: