sourcefilename = 'edmonton-roads-digraph.txt' argv = sys.argv[1:] if len(argv) == 0: #for no args, nothing to do, use default file pass elif len(argv) == 1: #for one arg, that arg is the file sourcefilename = argv[0].strip(' ') else: #otherwise, there was a bad usage, bail out print("Invalid usage.\nExpected: server.py [graphdatafile]") exit(-1) (graph, metadata) = (None, None) #try: (graph, metadata) = read_graph(open(sourcefilename)) #except: # print("Could not open source graph file `%s` for reading" % sourcefilename) # exit(-1) def dist_between(node_a_id, node_b_id): """ Calculate the distance between two vertex IDs """ #get the nodes node_a = metadata[node_a_id] node_b = metadata[node_b_id] #calculate the distance and eturn it
""" python3 readgraph.py [ digraph-file ] Takes a csv (comma separated values) text file containing the vertices and edges of a street digraph and converts it into a digraph instance. If the optional argument digraph-file is supplied, reads that, otherwise takes input from stdin """ import sys from readgraph import read_graph # throw away executable name before processing command line arguments argv = sys.argv[1:] # if filename is supplied, use that, otherwise use stdin if argv: digraph_file_name = argv.pop(0) digraph_file = open(digraph_file_name, 'r') else: digraph_file = sys.stdin (graph, md) = read_graph(digraph_file) if True: print("Done\n:", md)