File: graph-info.py

package info (click to toggle)
botch 0.21-8
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,298,428 kB
  • sloc: xml: 11,924,948; ml: 4,497; python: 3,620; sh: 1,269; makefile: 319
file content (31 lines) | stat: -rwxr-xr-x 1,017 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env python3

from __future__ import print_function
import networkx as nx
import sys
sys.path.append('/usr/share/botch')
from util import read_graph

if __name__ == "__main__":
    import argparse
    parser = argparse.ArgumentParser(
        description=("Print type and number of vertices, edges and SCC of a " +
                     "graph in GraphML or dot format"))
    parser.add_argument(
        "g", type=read_graph, help="Input graph in GraphML or dot format")
    parser.add_argument(
        '-v', '--verbose', action='store_true', help='be verbose')
    args = parser.parse_args()

    if 'InstSet' in (a['kind'] for _, a in args.g.nodes(data=True)):
        graphtype = "buildgraph"
    else:
        graphtype = "srcgraph"

    nvert = args.g.number_of_nodes()
    nedge = args.g.number_of_edges()
    nscc = len([1 for scc
                in nx.components.strongly_connected_components(args.g)
                if len(scc) > 1])

    print("%s\t%d\t%d\t%d" % (graphtype, nvert, nedge, nscc))