Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(8)  |  Call(8)  |  Derive(0)  |  Import(0)

        def dump_graph(input_graph, filename):
    LOG.debug("Dumping to graphml %s" % filename)
    try:
        del input_graph.graph['node_default']
    except KeyError:
        pass
    try:
        del input_graph.graph['edge_default']
    except KeyError:
        pass

# map x_pos and y_pos into graph
    try:
        nx.write_graphml(input_graph, "%s.graphml" % filename)
    except nx.exception.NetworkXError:
        # NetworkX can't save dicts to graphml: use string representation
        graph = input_graph.copy()
        for key, item in graph.graph.items():
            graph.graph[key] = str(item)

            for n in graph:
                if 'label' not in graph.node[n]:
                    graph.node[n]['label'] = n.fqdn
                for key, item in graph.node[n].items():
                    graph.node[n][key] = str(item)

        for s,t in graph.edges():
            for key, item in graph[s][t].items():
                graph[s][t][key] = str(item)

        nx.write_graphml(graph, "%s.graphml" % filename)

    mat_fh = open(filename + "_mat.txt", "w")
    try:
        import numpy
        sparse_matrix = nx.to_numpy_matrix(input_graph)
        # Write out manually (numpy.tofile() writes as all on one line)
        for line in sparse_matrix.tolist():
            # Convert list to a string format numbers as integers not floats
            line = [ str(int(x)) for x in line]
            mat_fh.write( " ".join(line) )
            mat_fh.write("\n")
        mat_fh.close()
    except ImportError:
        LOG.debug("Sparse matrix support requires Numpy")


    nodelist_fh = open(filename + "_nodelist.txt", "w")
    line = [ str(n) for n in input_graph]
    nodelist_fh.write( ", ".join(line) + "\n")
    nodelist_fh.close()

    try:
        poplist_fh = open(filename + "_poplist.txt", "w")
        line = [ str(n.pop) for n in input_graph]
        poplist_fh.write( ", ".join(line) + "\n")
        poplist_fh.close()
    except AttributeError:
        pass
        


src/a/n/ank_le-HEAD/AutoNetkit/internet.py   ank_le(Download)
        try:
            g_dns = nx.Graph(self.network.g_dns)
            ank.dump_graph(g_dns, os.path.join(config.log_dir, "dns"))
            ank.dump_graph(self.network.g_dns_auth, os.path.join(config.log_dir, "dns_auth"))
            ank.dump_identifiers(self.network, os.path.join(config.log_dir, "identifiers.txt"))
            ank.dump_graph(self.network.graph, os.path.join(config.log_dir, "physical"))
            physical_single_edge = nx.Graph(self.network.graph)
            ank.dump_graph(physical_single_edge, os.path.join(config.log_dir, "physical_single_edge"))
            ibgp_graph = ank.get_ibgp_graph(self.network)
            ebgp_graph = ank.get_ebgp_graph(self.network)
            ank.dump_graph(ibgp_graph, os.path.join(config.log_dir, "ibgp"))
            ank.dump_graph(ebgp_graph, os.path.join(config.log_dir, "ebgp"))
            g_dns = nx.Graph(self.network.g_dns)