Beispiel #1
0
def main(argv=None):
    """Start up a CherryPy server to serve the SRU, OAI-PMH applications."""
    global argparser, c3_session, c3_server
    global sru_app, oaipmh_app  # WSGI Apps
    if argv is None:
        args = argparser.parse_args()
    else:
        args = argparser.parse_args(argv)
    c3_session = Session()
    c3_server = SimpleServer(c3_session, args.serverconfig)
    # Init SRU App
    sru_configs = get_configsFromServer(c3_session, c3_server)
    sru_app = SRUWsgiHandler(c3_session, sru_configs)
    # Init OAI-PMH App
    dbs, oaipmh_configs = get_databasesAndConfigs(c3_session, c3_server)
    oaipmh_app = OAIPMHWsgiApplication(c3_session, oaipmh_configs, dbs)
    # Mount various Apps and static directories
    urlmap = URLMap()
    urlmap['/docs'] = make_pkg_resources(None, 'cheshire3', 'docs/build/html')
    urlmap['/api/sru'] = sru_app
    urlmap['/api/oaipmh/2.0'] = oaipmh_app
    url = "http://{0}:{1}/".format(args.hostname, args.port)
    if args.browser:
        webbrowser.open(url)
        print ("Hopefully a new browser window/tab should have opened "
               "displaying the application.")
    paste.httpserver.serve(urlmap,
                           host=args.hostname,
                           port=args.port,
                           )
Beispiel #2
0
def main(argv=None):
    """Start up a CherryPy server to serve the SRU, OAI-PMH applications."""
    global argparser, c3_session, c3_server
    global sru_app, oaipmh_app  # WSGI Apps
    if argv is None:
        args = argparser.parse_args()
    else:
        args = argparser.parse_args(argv)
    c3_session = Session()
    c3_server = SimpleServer(c3_session, args.serverconfig)
    # Init SRU App
    sru_configs = get_configsFromServer(c3_session, c3_server)
    sru_app = SRUWsgiHandler(c3_session, sru_configs)
    # Init OAI-PMH App
    dbs, oaipmh_configs = get_databasesAndConfigs(c3_session, c3_server)
    oaipmh_app = OAIPMHWsgiApplication(c3_session, oaipmh_configs, dbs)
    # Mount various Apps and static directories
    urlmap = URLMap()
    urlmap['/docs'] = make_pkg_resources(None, 'cheshire3', 'docs/build/html')
    urlmap['/api/sru'] = sru_app
    urlmap['/api/oaipmh/2.0'] = oaipmh_app
    url = "http://{0}:{1}/".format(args.hostname, args.port)
    if args.browser:
        webbrowser.open(url)
        print("Hopefully a new browser window/tab should have opened "
              "displaying the application.")
    paste.httpserver.serve(
        urlmap,
        host=args.hostname,
        port=args.port,
    )
def main(argv=None):
    """Start up a CherryPy server to serve the SRU application."""
    global argparser, c3_session, c3_server
    global sru_app, ead_search_app, ead_data_app  # WSGI Apps
    if argv is None:
        args = argparser.parse_args()
    else:
        args = argparser.parse_args(argv)
    c3_session = Session()
    c3_server = SimpleServer(c3_session, args.serverconfig)
    # Init SRU App
    sru_configs = get_configsFromServer(c3_session, c3_server)
    sru_app = SRUWsgiHandler(c3_session, sru_configs)
    # Init OAI-PMH App
    dbs, oaipmh_configs = get_databasesAndConfigs(c3_session, c3_server)
    oaipmh_app = OAIPMHWsgiApplication(c3_session, oaipmh_configs, dbs)
    # Prepare CherryPy Engine
    cherrypy.config.update({'server.socket_host': args.hostname,
                            'server.socket_port': args.port,
                            'tools.trailing_slash.on': True,
                            'tools.trailing_slash.missing': True,
                            'tools.trailing_slash.extra': True})
    cherrypy.tree.graft(sru_app, '/api/sru')
    cherrypy.tree.graft(oaipmh_app, '/api/OAI-PMH/2.0')
    cherrypy.tree.graft(ead_data_app, '/data')
    cherrypy.tree.graft(ead_search_app, '/search')
    cherrypy.tree.graft(admin_app, '/admin')
    cherrypy.tree.graft(edit_app, '/edit')
    cherrypy.tree.graft(console_app, '/contribute')
    root_conf = {
        'tools.staticdir.on': True,
        'tools.staticdir.dir': expanduser('~/mercurial/archiveshub/htdocs'),
        'tools.staticdir.index': 'index.html'
    }
    config = {
        '/': root_conf
    }
    cherrypy.tree.mount(None, '/', config=config)
    edit_config = {
        '/': {
            'tools.staticdir.on': True,
            'tools.staticdir.dir': resource_filename(
                Requirement.parse('archiveshub'),
                'www/hubedit/js'
            )
        }
    }
    cherrypy.tree.mount(None, '/edit/js', edit_config)
    # Write startup message to stdout
    sys.stdout.write(
        "Starting CherryPy HTTP server for ArchivesHub.\n"
        "If running in foreground Ctrl-C will stop the server.\n"
        "You will be able to access the applications from:\n"
        "http://{0}:{1}\n""".format(args.hostname, args.port)
    )
    sys.stdout.flush()
    # Register signal handler for shutdown

    def signal_handler(signal, frame):
        cherrypy.engine.stop()
        sys.exit(0)

    signal.signal(signal.SIGINT, signal_handler)
    # Daemonize the process?
    if args.daemonic:
        sys.stdout.write("Daemonizing...\n""")
        sys.stdout.flush()
        access_log = resource_filename(
            Requirement.parse('archiveshub'),
            'www/ead/logs/access.log'
        )
        error_log = resource_filename(
            Requirement.parse('archiveshub'),
            'www/ead/logs/error.log'
        )
        cherrypy.process.plugins.Daemonizer(
            cherrypy.engine,
            stdout=access_log,
            stderr=error_log
        ).subscribe()
    cherrypy.engine.start()
    cherrypy.engine.block()