Ejemplo n.º 1
0
def get_handler_instances(handler_definitions, handler_type):
    if handler_definitions is None:
        return

    if handler_type not in handler_definitions:
        return

    for handler in handler_definitions[handler_type]:
        handler_class = import_object(handler['name'])
        handler_instance = handler_class(**handler.get("args", {}))

        yield handler_instance
Ejemplo n.º 2
0
def get_handler_instances( handler_definitions, handler_type ):
    if handler_definitions is None:
        return
    
    if handler_type not in handler_definitions:
        return
    
    for handler in handler_definitions[handler_type]:
        handler_class = import_object( handler['name'] )
        handler_instance = handler_class(**handler.get("args", {}))
        
        yield handler_instance
Ejemplo n.º 3
0
def main():
    
    # get command line input
    usage = """python routeserver.py graphdb_filename config_filename"""
    parser = OptionParser(usage=usage)
    parser.add_option("-p", "--port", dest="port", default="8080",
                      help="Port to serve HTTP, if serving as a standalone server")
    parser.add_option("-s", "--socket", dest="socket", default=None, 
                      help="Socket on which serve fastCGI. If both port and socket are specified, serves as an fastCGI backend.")
    
    (options, args) = parser.parse_args()
    
    if len(args) != 2:
        parser.print_help()
        exit(-1)
        
    graphdb_filename, config_filename = args
    
    # get narrative handler classes
    handler_definitions = yaml.load( open(config_filename).read() )

    server_class = RouteServer
    if 'server_class' in handler_definitions:
        server_class = import_object(handler_definitions['server_class'])
    
    edge_events = list(get_handler_instances( handler_definitions, 'edge_handlers' ) )
    vertex_events = list(get_handler_instances( handler_definitions, 'vertex_handlers' ) )
    vertex_reverse_geocoders = list(get_handler_instances( handler_definitions, 'vertex_reverse_geocoders' ) )
    
    # explain to the nice people which handlers were loaded
    print "edge event handlers:"
    for edge_event in edge_events:
        print "   %s"%edge_event
    print "vertex event handlers:"
    for vertex_event in vertex_events:
        print "   %s"%vertex_event
    print "vertex reverse geocoders:"
    for vertex_reverse_geocoder in vertex_reverse_geocoders:
        print "   %s"%vertex_reverse_geocoder
    
    # start up the routeserver
    gc = server_class(graphdb_filename, vertex_events, edge_events, vertex_reverse_geocoders, 
                      config=handler_definitions)
    
    # serve as either an HTTP server or an fastCGI backend
    if options.socket:
        print "Starting fastCGI backend serving at %s"%options.socket
        WSGIServer(gc.wsgi_app(), bindAddress = options.socket).run()
    else:
        gc.run_test_server(port=int(options.port))
Ejemplo n.º 4
0
def main():
    usage = """usage: python gdb_import_osm.py <graphdb_filename> <osmdb_filename>"""
    parser = OptionParser(usage=usage)
    parser.add_option("-n", "--namespace", dest="namespace", default="osm",
                      help="prefix all imported vertices with namespace string")
    parser.add_option("-s", "--slog",
                      action="append", dest="slog_strings", default=[],
                      help="specify slog for highway type, in highway_type:slog form. For example, 'motorway:10.5'")
    parser.add_option("-p", "--profiledb", dest="profiledb_filename", default=None,
                      help="specify profiledb to annotate streets with rise/fall data")
    parser.add_option("-c", "--slog_config",
                      dest="slog_config", default=None, metavar="CONFIG.yaml",
                      help="file containing slog parameters for highways, cycleways, etc")

    (options, args) = parser.parse_args()
    
    if len(args) != 2:
        parser.print_help()
        exit(-1)
        
    slogs = {}
    slog_config = {}
    if options.slog_config:
        slog_config = yaml.load( open(options.slog_config).read() )
        for highway_type, slog_penalty in slog_config.get('slogs',{}).items():
            slogs[highway_type] = float(slog_penalty)

    for slog_string in options.slog_strings:
        highway_type,slog_penalty = slog_string.split(":")
        slogs[highway_type] = float(slog_penalty)
    print "slog values: %s"%slogs

    slog_config['slogs'] = slogs
    if slog_config.get('slog_function'):
        slog_config['slog_function'] = import_object(slog_config['slog_function'])
        
    graphdb_filename = args[0]
    osmdb_filename = args[1]
    
    print "importing osmdb '%s' into graphdb '%s'"%(osmdb_filename, graphdb_filename)
    
    profiledb = ProfileDB( options.profiledb_filename ) if options.profiledb_filename else None
    osmdb = OSMDB( osmdb_filename )
    gdb = GraphDatabase( graphdb_filename, overwrite=False )
    
    gdb_import_osm(gdb, osmdb, options.namespace, slog_config, profiledb)
    
    print "done"
Ejemplo n.º 5
0
def main():

    # get command line input
    usage = """python routeserver.py graphdb_filename config_filename"""
    parser = OptionParser(usage=usage)
    parser.add_option(
        "-p",
        "--port",
        dest="port",
        default="8080",
        help="Port to serve HTTP, if serving as a standalone server")
    parser.add_option(
        "-s",
        "--socket",
        dest="socket",
        default=None,
        help=
        "Socket on which serve fastCGI. If both port and socket are specified, serves as an fastCGI backend."
    )

    (options, args) = parser.parse_args()

    if len(args) != 2:
        parser.print_help()
        exit(-1)

    graphdb_filename, config_filename = args

    # get narrative handler classes
    handler_definitions = yaml.load(open(config_filename).read())

    server_class = RouteServer
    if 'server_class' in handler_definitions:
        server_class = import_object(handler_definitions['server_class'])

    edge_events = list(
        get_handler_instances(handler_definitions, 'edge_handlers'))
    vertex_events = list(
        get_handler_instances(handler_definitions, 'vertex_handlers'))
    vertex_reverse_geocoders = list(
        get_handler_instances(handler_definitions, 'vertex_reverse_geocoders'))

    # explain to the nice people which handlers were loaded
    print "edge event handlers:"
    for edge_event in edge_events:
        print "   %s" % edge_event
    print "vertex event handlers:"
    for vertex_event in vertex_events:
        print "   %s" % vertex_event
    print "vertex reverse geocoders:"
    for vertex_reverse_geocoder in vertex_reverse_geocoders:
        print "   %s" % vertex_reverse_geocoder

    # start up the routeserver
    gc = server_class(graphdb_filename,
                      vertex_events,
                      edge_events,
                      vertex_reverse_geocoders,
                      config=handler_definitions)

    # serve as either an HTTP server or an fastCGI backend
    if options.socket:
        print "Starting fastCGI backend serving at %s" % options.socket
        WSGIServer(gc.wsgi_app(), bindAddress=options.socket).run()
    else:
        gc.run_test_server(port=int(options.port))
Ejemplo n.º 6
0
def main():
    usage = """usage: python gdb_import_osm.py <graphdb_filename> <osmdb_filename>"""
    parser = OptionParser(usage=usage)
    parser.add_option(
        "-n",
        "--namespace",
        dest="namespace",
        default="osm",
        help="prefix all imported vertices with namespace string")
    parser.add_option(
        "-s",
        "--slog",
        action="append",
        dest="slog_strings",
        default=[],
        help=
        "specify slog for highway type, in highway_type:slog form. For example, 'motorway:10.5'"
    )
    parser.add_option(
        "-p",
        "--profiledb",
        dest="profiledb_filename",
        default=None,
        help="specify profiledb to annotate streets with rise/fall data")
    parser.add_option(
        "-c",
        "--slog_config",
        dest="slog_config",
        default=None,
        metavar="CONFIG.yaml",
        help="file containing slog parameters for highways, cycleways, etc")

    (options, args) = parser.parse_args()

    if len(args) != 2:
        parser.print_help()
        exit(-1)

    slogs = {}
    slog_config = {}
    if options.slog_config:
        slog_config = yaml.load(open(options.slog_config).read())
        for highway_type, slog_penalty in slog_config.get('slogs', {}).items():
            slogs[highway_type] = float(slog_penalty)

    for slog_string in options.slog_strings:
        highway_type, slog_penalty = slog_string.split(":")
        slogs[highway_type] = float(slog_penalty)
    print "slog values: %s" % slogs

    slog_config['slogs'] = slogs
    if slog_config.get('slog_function'):
        slog_config['slog_function'] = import_object(
            slog_config['slog_function'])

    graphdb_filename = args[0]
    osmdb_filename = args[1]

    print "importing osmdb '%s' into graphdb '%s'" % (osmdb_filename,
                                                      graphdb_filename)

    profiledb = ProfileDB(
        options.profiledb_filename) if options.profiledb_filename else None
    osmdb = OSMDB(osmdb_filename)
    gdb = GraphDatabase(graphdb_filename, overwrite=False)

    gdb_import_osm(gdb, osmdb, options.namespace, slog_config, profiledb)

    print "done"