예제 #1
0
    def __init__(self, host, port):
        # Now import the girder modules.  If this fails, it's up to the
        # administrator to make sure Girder is installed and on the PYTHONPATH.
        import girder.events
        from girder import constants
        from girder.api import api_main
        from girder import constants
        from girder.utility import plugin_utilities, model_importer

        self.root_dir = constants.ROOT_DIR

        api_main.addApiToNode(self)

        cherrypy.engine.subscribe("start", girder.events.daemon.start)
        cherrypy.engine.subscribe("stop", girder.events.daemon.stop)

        plugins = model_importer.ModelImporter().model('setting').get(
            constants.SettingKey.PLUGINS_ENABLED, default=())
        plugin_utilities.loadPlugins(plugins, self, cherrypy.config)

        self.config = {
            "/": {
                "request.dispatch": cherrypy.dispatch.MethodDispatcher(),
                "tools.staticdir.root": self.root_dir
            },
            "/static": {
                "tools.staticdir.on": "True",
                "tools.staticdir.dir": "clients/web/static"
            }
        }
예제 #2
0
def setup(test=False):
    """
    Function to setup the cherrypy server. It configures it, but does
    not actually start it.

    :param test: Set to True when running in the tests.
    :type test: bool
    """
    cfgs = ('auth', 'db', 'server')
    cfgs = [os.path.join(constants.ROOT_DIR, 'girder', 'conf',
                         'local.%s.cfg' % c) for c in cfgs]
    for cfg in cfgs:
        cherrypy.config.update(cfg)

    appconf = {
        '/': {
            'request.dispatch': cherrypy.dispatch.MethodDispatcher(),
            'tools.staticdir.root': constants.ROOT_DIR,
            'request.show_tracebacks': test
        },
        '/static': {
            'tools.staticdir.on': 'True',
            'tools.staticdir.dir': 'clients/web/static'
        }
    }

    cherrypy.config.update(appconf)

    if test:
        # Force the mode to be 'testing'
        cherrypy.config.update({'server': {'mode': 'testing'}})

    # Don't import this until after the configs have been read; some module
    # initialization code requires the configuration to be set up.
    from girder.api import api_main

    root = Webroot()
    api_main.addApiToNode(root)

    if cherrypy.config['server']['mode'] is 'development':
        dev_endpoints.addDevEndpoints(root, appconf)  # pragma: no cover

    cherrypy.engine.subscribe('start', girder.events.daemon.start)
    cherrypy.engine.subscribe('stop', girder.events.daemon.stop)

    settings = model_importer.ModelImporter().model('setting')
    plugins = settings.get(constants.SettingKey.PLUGINS_ENABLED, default=())
    plugin_utilities.loadPlugins(plugins, root, appconf)

    application = cherrypy.tree.mount(root, '/', appconf)
    for cfg in cfgs:
        application.merge(cfg)

    if test:
        application.merge({'server': {'mode': 'testing'}})

    return application
예제 #3
0
파일: server.py 프로젝트: jbeezley/tangelo
    def __init__(self, vtkweb=None, stream=None):
        self.vtkweb = vtkweb
        self.stream = stream

        # A dict containing information about imported modules.
        self.modules = {}

        # Mount a streaming API if requested.
        #
        # TODO(choudhury): make the mounting directory configurable by the
        # user.
        if self.stream:
            cherrypy.tree.mount(stream, "/stream")

        # Mount a VTKWeb API if requested.
        #
        # TODO(choudhury): make the mounting directory configurable by the
        # user.
        if self.vtkweb is not None:
            cherrypy.tree.mount(self.vtkweb, "/vtkweb")

        # Mount Girder API if available.
        try:
            from girder.api import api_main

            cherrypy.config.update({
                "sessions": {"cookie_lifetime": 180},
                "server": {"mode": "development"},
                "database": {
                    "host": "localhost",
                    "port": 27017,
                    "user": "",
                    "password": "",
                    "database": "girder"
                }
            })

            class Dummy(object):
                pass

            cherrypy.tree.mount(api_main.addApiToNode(Dummy()), "/girder", {
                '/': {
                    'request.dispatch': cherrypy.dispatch.MethodDispatcher()
                }
            })
        except ImportError:
            # Ok, just don't mount it.
            pass
예제 #4
0
파일: server.py 프로젝트: jeffbaumes/girder
def setup(test=False):
    """
    Function to setup the cherrypy server. It configures it, but does
    not actually start it.

    :param test: Set to True when running in the tests.
    :type test: bool
    """
    cfgs = ['auth', 'db', 'server']
    cfgs = [os.path.join(ROOT_DIR, 'girder', 'conf', 'local.%s.cfg' % c)
            for c in cfgs]
    [cherrypy.config.update(cfg) for cfg in cfgs]

    appconf = {
        '/': {
            'request.dispatch': cherrypy.dispatch.MethodDispatcher(),
            'tools.staticdir.root': ROOT_DIR,
            'request.show_tracebacks': test
            },
        '/static': {
            'tools.staticdir.on': 'True',
            'tools.staticdir.dir': 'clients/web/static',
            }
        }

    cherrypy.config.update(appconf)

    if test:
        # Force the mode to be 'testing'
        cherrypy.config.update({'server': {'mode': 'testing'}})

    # Don't import this until after the configs have been read; some module
    # initialization code requires the configuration to be set up.
    from girder.api import api_main

    root = Webroot()
    root = api_main.addApiToNode(root)

    application = cherrypy.tree.mount(root, '/', appconf)
    [application.merge(cfg) for cfg in cfgs]

    if test:
        application.merge({'server': {'mode': 'testing'}})
예제 #5
0
파일: server.py 프로젝트: adsorensen/girder
def configureServer(test=False, plugins=None, curConfig=None):
    """
    Function to setup the cherrypy server. It configures it, but does
    not actually start it.

    :param test: Set to True when running in the tests.
    :type test: bool
    :param plugins: If you wish to start the server with a custom set of
                    plugins, pass this as a list of plugins to load. Otherwise,
                    will use the PLUGINS_ENABLED setting value from the db.
    :param curConfig: The configuration dictionary to update.
    """
    if curConfig is None:
        curConfig = config.getConfig()

    appconf = {
        '/': {
            'request.dispatch': cherrypy.dispatch.MethodDispatcher(),
            'request.show_tracebacks': test,
            'request.methods_with_bodies': ('POST', 'PUT', 'PATCH'),
            'response.headers.server': 'Girder %s' % __version__,
            'error_page.default': _errorDefault
        }
    }
    # Add MIME types for serving Fontello files from staticdir;
    # these may be missing or incorrect in the OS
    mimetypes.add_type('application/vnd.ms-fontobject', '.eot')
    mimetypes.add_type('application/x-font-ttf', '.ttf')
    mimetypes.add_type('application/font-woff', '.woff')

    if test:
        appconf['/src'] = {
            'tools.staticdir.on': True,
            'tools.staticdir.root': constants.STATIC_ROOT_DIR,
            'tools.staticdir.dir': 'clients/web/src',
        }
        appconf['/test'] = {
            'tools.staticdir.on': True,
            'tools.staticdir.root': constants.STATIC_ROOT_DIR,
            'tools.staticdir.dir': 'clients/web/test',
        }
        appconf['/clients'] = {
            'tools.staticdir.on': True,
            'tools.staticdir.root': constants.STATIC_ROOT_DIR,
            'tools.staticdir.dir': 'clients'
        }
        appconf['/plugins'] = {
            'tools.staticdir.on': True,
            'tools.staticdir.root': constants.STATIC_ROOT_DIR,
            'tools.staticdir.dir': 'plugins',
        }

    curConfig.update(appconf)

    if test:
        # Force some config params in testing mode
        curConfig.update({'server': {
            'mode': 'testing',
            'api_root': 'api/v1',
            'static_root': 'static',
            'api_static_root': '../static',
            'cherrypy_server': True
        }})

    mode = curConfig['server']['mode'].lower()
    logprint.info('Running in mode: ' + mode)
    cherrypy.config['engine.autoreload.on'] = mode == 'development'

    # Don't import this until after the configs have been read; some module
    # initialization code requires the configuration to be set up.
    from girder.api import api_main

    root = webroot.Webroot()
    api_main.addApiToNode(root)

    cherrypy.engine.subscribe('start', girder.events.daemon.start)
    cherrypy.engine.subscribe('stop', girder.events.daemon.stop)

    if plugins is None:
        settings = model_importer.ModelImporter().model('setting')
        plugins = settings.get(constants.SettingKey.PLUGINS_ENABLED, default=())

    plugins = list(plugin_utilities.getToposortedPlugins(plugins, ignoreMissing=True))

    _configureStaticRoutes(root, plugins)

    girder.events.bind('model.setting.save.after', '_updateStaticRoutesIfModified',
                       functools.partial(_configureStaticRoutes, root, plugins))

    root, appconf, _ = plugin_utilities.loadPlugins(
        plugins, root, appconf, root.api.v1, buildDag=False)

    return root, appconf
예제 #6
0
파일: server.py 프로젝트: cjh1/girder
def setup(test=False, plugins=None):
    """
    Function to setup the cherrypy server. It configures it, but does
    not actually start it.

    :param test: Set to True when running in the tests.
    :type test: bool
    :param plugins: If you wish to start the server with a custom set of
                    plugins, pass this as a list of plugins to load. Otherwise,
                    will use the PLUGINS_ENABLED setting value from the db.
    """
    cur_config = config.getConfig()

    appconf = {
        '/': {
            'request.dispatch': cherrypy.dispatch.MethodDispatcher(),
            'tools.staticdir.root': constants.ROOT_DIR,
            'request.show_tracebacks': test
        },
        '/static': {
            'tools.staticdir.on': 'True',
            'tools.staticdir.dir': 'clients/web/static'
        }
    }

    if test:
        appconf['/src'] = {
            'tools.staticdir.on': 'True',
            'tools.staticdir.dir': 'clients/web/src',
        }
        appconf['/test'] = {
            'tools.staticdir.on': 'True',
            'tools.staticdir.dir': 'clients/web/test',
        }
        appconf['/clients'] = {
            'tools.staticdir.on': 'True',
            'tools.staticdir.dir': 'clients'
        }

    cur_config.update(appconf)

    if test:
        # Force some config params in testing mode
        cur_config.update({'server': {
            'mode': 'testing',
            'api_root': '/api/v1',
            'static_root': '/static'
        }})

    # Don't import this until after the configs have been read; some module
    # initialization code requires the configuration to be set up.
    from girder.api import api_main

    root = webroot.Webroot()
    api_main.addApiToNode(root)

    if cur_config['server']['mode'] is 'development':
        dev_endpoints.addDevEndpoints(root, appconf)  # pragma: no cover

    cherrypy.engine.subscribe('start', girder.events.daemon.start)
    cherrypy.engine.subscribe('stop', girder.events.daemon.stop)

    if plugins is None:
        settings = model_importer.ModelImporter().model('setting')
        plugins = settings.get(constants.SettingKey.PLUGINS_ENABLED, default=())

    root.updateHtmlVars({
        'apiRoot': cur_config['server']['api_root'],
        'staticRoot': cur_config['server']['static_root'],
        'plugins': plugins
    })

    plugin_utilities.loadPlugins(plugins, root, appconf)

    application = cherrypy.tree.mount(root, '/', appconf)

    if test:
        application.merge({'server': {'mode': 'testing'}})

    return application
예제 #7
0
파일: server.py 프로젝트: manthey/girder
def configureServer(test=False, plugins=None, curConfig=None):
    """
    Function to setup the cherrypy server. It configures it, but does
    not actually start it.

    :param test: Set to True when running in the tests.
    :type test: bool
    :param plugins: If you wish to start the server with a custom set of
                    plugins, pass this as a list of plugins to load. Otherwise,
                    will use the PLUGINS_ENABLED setting value from the db.
    :param curConfig: The configuration dictionary to update.
    """
    if curConfig is None:
        curConfig = config.getConfig()

    curStaticRoot = constants.STATIC_ROOT_DIR

    appconf = {
        "/": {
            "request.dispatch": cherrypy.dispatch.MethodDispatcher(),
            "tools.staticdir.root": curStaticRoot,
            "request.show_tracebacks": test,
            "request.methods_with_bodies": ("POST", "PUT", "PATCH"),
        },
        "/static": {"tools.staticdir.on": "True", "tools.staticdir.dir": "clients/web/static"},
    }

    if test:
        appconf["/src"] = {"tools.staticdir.on": "True", "tools.staticdir.dir": "clients/web/src"}
        appconf["/test"] = {"tools.staticdir.on": "True", "tools.staticdir.dir": "clients/web/test"}
        appconf["/clients"] = {"tools.staticdir.on": "True", "tools.staticdir.dir": "clients"}
        appconf["/plugins"] = {"tools.staticdir.on": "True", "tools.staticdir.dir": "plugins"}

    curConfig.update(appconf)

    if test:
        # Force some config params in testing mode
        curConfig.update(
            {
                "server": {
                    "mode": "testing",
                    "api_root": "api/v1",
                    "static_root": "static",
                    "api_static_root": "../static",
                }
            }
        )

    # Don't import this until after the configs have been read; some module
    # initialization code requires the configuration to be set up.
    from girder.api import api_main

    root = webroot.Webroot()
    api_main.addApiToNode(root)

    cherrypy.engine.subscribe("start", girder.events.daemon.start)
    cherrypy.engine.subscribe("stop", girder.events.daemon.stop)

    if plugins is None:
        settings = model_importer.ModelImporter().model("setting")
        plugins = settings.get(constants.SettingKey.PLUGINS_ENABLED, default=())

    root.updateHtmlVars(
        {
            "apiRoot": curConfig["server"]["api_root"],
            "staticRoot": curConfig["server"]["static_root"],
            "plugins": plugins,
        }
    )

    apiStaticRoot = curConfig["server"].get("api_static_root", "")
    if not apiStaticRoot:
        apiStaticRoot = curConfig["server"]["static_root"]
    root.api.v1.updateHtmlVars({"apiRoot": curConfig["server"]["api_root"], "staticRoot": apiStaticRoot})

    root, appconf, _ = plugin_utilities.loadPlugins(plugins, root, appconf, root.api.v1, curConfig=curConfig)

    return root, appconf
예제 #8
0
파일: server.py 프로젝트: jbeezley/girder
def configureServer(test=False, plugins=None, curConfig=None):
    """
    Function to setup the cherrypy server. It configures it, but does
    not actually start it.

    :param test: Set to True when running in the tests.
    :type test: bool
    :param plugins: If you wish to start the server with a custom set of
                    plugins, pass this as a list of plugins to load. Otherwise,
                    will use the PLUGINS_ENABLED setting value from the db.
    :param curConfig: The configuration dictionary to update.
    """
    if curConfig is None:
        curConfig = config.getConfig()

    curStaticRoot = constants.STATIC_ROOT_DIR

    appconf = {
        '/': {
            'request.dispatch': cherrypy.dispatch.MethodDispatcher(),
            'tools.staticdir.root': curStaticRoot,
            'request.show_tracebacks': test,
            'request.methods_with_bodies': ('POST', 'PUT', 'PATCH')
        },
        '/static': {
            'tools.staticdir.on': True,
            'tools.staticdir.dir': 'clients/web/static'
        }
    }

    if test:
        appconf['/src'] = {
            'tools.staticdir.on': True,
            'tools.staticdir.dir': 'clients/web/src',
        }
        appconf['/test'] = {
            'tools.staticdir.on': True,
            'tools.staticdir.dir': 'clients/web/test',
        }
        appconf['/clients'] = {
            'tools.staticdir.on': True,
            'tools.staticdir.dir': 'clients'
        }
        appconf['/plugins'] = {
            'tools.staticdir.on': True,
            'tools.staticdir.dir': 'plugins',
        }

    curConfig.update(appconf)

    if test:
        # Force some config params in testing mode
        curConfig.update({'server': {
            'mode': 'testing',
            'api_root': 'api/v1',
            'static_root': 'static',
            'api_static_root': '../static'
        }})

    mode = curConfig['server']['mode'].lower()
    print(constants.TerminalColor.info('Running in mode: ' + mode))
    cherrypy.config['engine.autoreload.on'] = mode == 'development'

    # Don't import this until after the configs have been read; some module
    # initialization code requires the configuration to be set up.
    from girder.api import api_main

    root = webroot.Webroot()
    api_main.addApiToNode(root)

    cherrypy.engine.subscribe('start', girder.events.daemon.start)
    cherrypy.engine.subscribe('stop', girder.events.daemon.stop)

    if plugins is None:
        settings = model_importer.ModelImporter().model('setting')
        plugins = settings.get(constants.SettingKey.PLUGINS_ENABLED,
                               default=())

    root.updateHtmlVars({
        'apiRoot': curConfig['server']['api_root'],
        'staticRoot': curConfig['server']['static_root'],
        'plugins': plugins
    })

    apiStaticRoot = curConfig['server'].get('api_static_root', '')
    if not apiStaticRoot:
        apiStaticRoot = curConfig['server']['static_root']
    root.api.v1.updateHtmlVars({
        'apiRoot': curConfig['server']['api_root'],
        'staticRoot': apiStaticRoot,
    })

    root, appconf, _ = plugin_utilities.loadPlugins(
        plugins, root, appconf, root.api.v1, curConfig=curConfig)

    return root, appconf
예제 #9
0
파일: server.py 프로젝트: manthey/girder
def configureServer(test=False, plugins=None, curConfig=None):
    """
    Function to setup the cherrypy server. It configures it, but does
    not actually start it.

    :param test: Set to True when running in the tests.
    :type test: bool
    :param plugins: If you wish to start the server with a custom set of
        plugins, pass this as a list of plugins to load. Otherwise,
        will use the PLUGINS_ENABLED setting value from the db.
    :param curConfig: The configuration dictionary to update.
    """
    if curConfig is None:
        curConfig = config.getConfig()

    appconf = {
        '/': {
            'request.dispatch': cherrypy.dispatch.MethodDispatcher(),
            'request.show_tracebacks': test,
            'request.methods_with_bodies': ('POST', 'PUT', 'PATCH'),
            'response.headers.server': 'Girder %s' % __version__,
            'error_page.default': _errorDefault
        }
    }
    # Add MIME types for serving Fontello files from staticdir;
    # these may be missing or incorrect in the OS
    mimetypes.add_type('application/vnd.ms-fontobject', '.eot')
    mimetypes.add_type('application/x-font-ttf', '.ttf')
    mimetypes.add_type('application/font-woff', '.woff')

    curConfig.update(appconf)

    if test:
        # Force some config params in testing mode
        curConfig.update({'server': {
            'mode': 'testing',
            'api_root': 'api/v1',
            'static_root': 'static',
            'api_static_root': '../static',
            'cherrypy_server': True
        }})

    mode = curConfig['server']['mode'].lower()
    logprint.info('Running in mode: ' + mode)
    cherrypy.config['engine.autoreload.on'] = mode == 'development'

    _setupCache()

    # Don't import this until after the configs have been read; some module
    # initialization code requires the configuration to be set up.
    from girder.api import api_main

    root = webroot.Webroot()
    api_main.addApiToNode(root)

    girder.events.setupDaemon()
    cherrypy.engine.subscribe('start', girder.events.daemon.start)
    cherrypy.engine.subscribe('stop', girder.events.daemon.stop)

    if plugins is None:
        plugins = getPlugins()

    routeTable = loadRouteTable()
    info = {
        'config': appconf,
        'serverRoot': root,
        'serverRootPath': routeTable[constants.GIRDER_ROUTE_ID],
        'apiRoot': root.api.v1,
        'staticRoot': routeTable[constants.GIRDER_STATIC_ROUTE_ID]
    }

    plugin._loadPlugins(plugins, info)
    root, appconf = info['serverRoot'], info['config']

    return root, appconf
예제 #10
0
파일: server.py 프로젝트: tymiao1220/girder
def configureServer(mode=None, plugins=None, curConfig=None):
    """
    Function to setup the cherrypy server. It configures it, but does
    not actually start it.

    :param mode: The server mode to start in.
    :type mode: string
    :param plugins: If you wish to start the server with a custom set of
        plugins, pass this as a list of plugins to load. Otherwise,
        all installed plugins will be loaded.
    :param curConfig: The configuration dictionary to update.
    """
    if curConfig is None:
        curConfig = config.getConfig()

    appconf = {
        '/': {
            'request.dispatch': cherrypy.dispatch.MethodDispatcher(),
            'request.show_tracebacks': mode == ServerMode.TESTING,
            'request.methods_with_bodies': ('POST', 'PUT', 'PATCH'),
            'response.headers.server': 'Girder %s' % __version__,
            'error_page.default': _errorDefault
        }
    }
    # Add MIME types for serving Fontello files from staticdir;
    # these may be missing or incorrect in the OS
    mimetypes.add_type('application/vnd.ms-fontobject', '.eot')
    mimetypes.add_type('application/x-font-ttf', '.ttf')
    mimetypes.add_type('application/font-woff', '.woff')

    curConfig.update(appconf)
    if mode:
        curConfig['server']['mode'] = mode

    logprint.info('Running in mode: ' + curConfig['server']['mode'])
    cherrypy.config['engine.autoreload.on'] = mode == ServerMode.DEVELOPMENT

    _setupCache()

    # Don't import this until after the configs have been read; some module
    # initialization code requires the configuration to be set up.
    from girder.api import api_main

    root = webroot.Webroot()
    api_main.addApiToNode(root)

    girder.events.setupDaemon()
    cherrypy.engine.subscribe('start', girder.events.daemon.start)
    cherrypy.engine.subscribe('stop', girder.events.daemon.stop)

    routeTable = loadRouteTable()
    info = {
        'config': appconf,
        'serverRoot': root,
        'serverRootPath': routeTable[constants.GIRDER_ROUTE_ID],
        'apiRoot': root.api.v1,
    }

    plugin._loadPlugins(info, plugins)
    root, appconf = info['serverRoot'], info['config']

    return root, appconf
예제 #11
0
def configureServer(test=False, plugins=None, curConfig=None):
    """
    Function to setup the cherrypy server. It configures it, but does
    not actually start it.

    :param test: Set to True when running in the tests.
    :type test: bool
    :param plugins: If you wish to start the server with a custom set of
                    plugins, pass this as a list of plugins to load. Otherwise,
                    will use the PLUGINS_ENABLED setting value from the db.
    :param curConfig: The configuration dictionary to update.
    """
    if curConfig is None:
        curConfig = config.getConfig()

    curStaticRoot = constants.STATIC_ROOT_DIR

    appconf = {
        "/": {
            "request.dispatch": cherrypy.dispatch.MethodDispatcher(),
            "tools.staticdir.root": curStaticRoot,
            "request.show_tracebacks": test,
            "request.methods_with_bodies": ("POST", "PUT", "PATCH"),
        },
        "/static": {"tools.staticdir.on": True, "tools.staticdir.dir": "clients/web/static"},
    }
    # Add MIME types for serving Fontello files from staticdir;
    # these may be missing or incorrect in the OS
    mimetypes.add_type("application/vnd.ms-fontobject", ".eot")
    mimetypes.add_type("application/x-font-ttf", ".ttf")
    mimetypes.add_type("application/font-woff", ".woff")

    if test:
        appconf["/src"] = {"tools.staticdir.on": True, "tools.staticdir.dir": "clients/web/src"}
        appconf["/test"] = {"tools.staticdir.on": True, "tools.staticdir.dir": "clients/web/test"}
        appconf["/clients"] = {"tools.staticdir.on": True, "tools.staticdir.dir": "clients"}
        appconf["/plugins"] = {"tools.staticdir.on": True, "tools.staticdir.dir": "plugins"}

    curConfig.update(appconf)

    if test:
        # Force some config params in testing mode
        curConfig.update(
            {
                "server": {
                    "mode": "testing",
                    "api_root": "api/v1",
                    "static_root": "static",
                    "api_static_root": "../static",
                }
            }
        )

    mode = curConfig["server"]["mode"].lower()
    print(constants.TerminalColor.info("Running in mode: " + mode))
    cherrypy.config["engine.autoreload.on"] = mode == "development"

    # Don't import this until after the configs have been read; some module
    # initialization code requires the configuration to be set up.
    from girder.api import api_main

    root = webroot.Webroot()
    api_main.addApiToNode(root)

    cherrypy.engine.subscribe("start", girder.events.daemon.start)
    cherrypy.engine.subscribe("stop", girder.events.daemon.stop)

    if plugins is None:
        settings = model_importer.ModelImporter().model("setting")
        plugins = settings.get(constants.SettingKey.PLUGINS_ENABLED, default=())

    plugins = list(plugin_utilities.getToposortedPlugins(plugins, curConfig, ignoreMissing=True))
    root.updateHtmlVars(
        {
            "apiRoot": curConfig["server"]["api_root"],
            "staticRoot": curConfig["server"]["static_root"],
            "plugins": plugins,
        }
    )

    apiStaticRoot = curConfig["server"].get("api_static_root", "")
    if not apiStaticRoot:
        apiStaticRoot = curConfig["server"]["static_root"]
    root.api.v1.updateHtmlVars({"apiRoot": curConfig["server"]["api_root"], "staticRoot": apiStaticRoot})

    root, appconf, _ = plugin_utilities.loadPlugins(
        plugins, root, appconf, root.api.v1, curConfig=curConfig, buildDag=False
    )

    return root, appconf
예제 #12
0
def configureServer(test=False, plugins=None, curConfig=None):
    """
    Function to setup the cherrypy server. It configures it, but does
    not actually start it.

    :param test: Set to True when running in the tests.
    :type test: bool
    :param plugins: If you wish to start the server with a custom set of
        plugins, pass this as a list of plugins to load. Otherwise,
        will use the PLUGINS_ENABLED setting value from the db.
    :param curConfig: The configuration dictionary to update.
    """
    if curConfig is None:
        curConfig = config.getConfig()

    appconf = {
        '/': {
            'request.dispatch': cherrypy.dispatch.MethodDispatcher(),
            'request.show_tracebacks': test,
            'request.methods_with_bodies': ('POST', 'PUT', 'PATCH'),
            'response.headers.server': 'Girder %s' % __version__,
            'error_page.default': _errorDefault
        }
    }
    # Add MIME types for serving Fontello files from staticdir;
    # these may be missing or incorrect in the OS
    mimetypes.add_type('application/vnd.ms-fontobject', '.eot')
    mimetypes.add_type('application/x-font-ttf', '.ttf')
    mimetypes.add_type('application/font-woff', '.woff')

    curConfig.update(appconf)

    if test:
        # Force some config params in testing mode
        curConfig.update({
            'server': {
                'mode': 'testing',
                'api_root': 'api/v1',
                'static_root': 'static',
                'api_static_root': '../static',
                'cherrypy_server': True
            }
        })

    mode = curConfig['server']['mode'].lower()
    logprint.info('Running in mode: ' + mode)
    cherrypy.config['engine.autoreload.on'] = mode == 'development'

    _setupCache()

    # Don't import this until after the configs have been read; some module
    # initialization code requires the configuration to be set up.
    from girder.api import api_main

    root = webroot.Webroot()
    api_main.addApiToNode(root)

    girder.events.setupDaemon()
    cherrypy.engine.subscribe('start', girder.events.daemon.start)
    cherrypy.engine.subscribe('stop', girder.events.daemon.stop)

    if plugins is None:
        plugins = getPlugins()

    routeTable = loadRouteTable()
    info = {
        'config': appconf,
        'serverRoot': root,
        'serverRootPath': routeTable[constants.GIRDER_ROUTE_ID],
        'apiRoot': root.api.v1,
        'staticRoot': routeTable[constants.GIRDER_STATIC_ROUTE_ID]
    }

    plugin._loadPlugins(plugins, info)
    root, appconf = info['serverRoot'], info['config']

    return root, appconf
예제 #13
0
def configureServer(test=False, plugins=None, curConfig=None):
    """
    Function to setup the cherrypy server. It configures it, but does
    not actually start it.

    :param test: Set to True when running in the tests.
    :type test: bool
    :param plugins: If you wish to start the server with a custom set of
                    plugins, pass this as a list of plugins to load. Otherwise,
                    will use the PLUGINS_ENABLED setting value from the db.
    :param curConfig: The configuration dictionary to update.
    """
    if curConfig is None:
        curConfig = config.getConfig()

    routeTable = loadRouteTable()

    appconf = {
        '/': {
            'request.dispatch': cherrypy.dispatch.MethodDispatcher(),
            'request.show_tracebacks': test,
            'request.methods_with_bodies': ('POST', 'PUT', 'PATCH')
        }
    }
    # Add MIME types for serving Fontello files from staticdir;
    # these may be missing or incorrect in the OS
    mimetypes.add_type('application/vnd.ms-fontobject', '.eot')
    mimetypes.add_type('application/x-font-ttf', '.ttf')
    mimetypes.add_type('application/font-woff', '.woff')

    if test:
        appconf['/src'] = {
            'tools.staticdir.on': True,
            'tools.staticdir.root': constants.STATIC_ROOT_DIR,
            'tools.staticdir.dir': 'clients/web/src',
        }
        appconf['/test'] = {
            'tools.staticdir.on': True,
            'tools.staticdir.root': constants.STATIC_ROOT_DIR,
            'tools.staticdir.dir': 'clients/web/test',
        }
        appconf['/clients'] = {
            'tools.staticdir.on': True,
            'tools.staticdir.root': constants.STATIC_ROOT_DIR,
            'tools.staticdir.dir': 'clients'
        }
        appconf['/plugins'] = {
            'tools.staticdir.on': True,
            'tools.staticdir.root': constants.STATIC_ROOT_DIR,
            'tools.staticdir.dir': 'plugins',
        }

    curConfig.update(appconf)

    if test:
        # Force some config params in testing mode
        curConfig.update({
            'server': {
                'mode': 'testing',
                'api_root': 'api/v1',
                'static_root': 'static',
                'api_static_root': '../static'
            }
        })

    mode = curConfig['server']['mode'].lower()
    logprint.info('Running in mode: ' + mode)
    cherrypy.config['engine.autoreload.on'] = mode == 'development'

    # Don't import this until after the configs have been read; some module
    # initialization code requires the configuration to be set up.
    from girder.api import api_main

    root = webroot.Webroot()
    api_main.addApiToNode(root)

    cherrypy.engine.subscribe('start', girder.events.daemon.start)
    cherrypy.engine.subscribe('stop', girder.events.daemon.stop)

    if plugins is None:
        settings = model_importer.ModelImporter().model('setting')
        plugins = settings.get(constants.SettingKey.PLUGINS_ENABLED,
                               default=())

    plugins = list(
        plugin_utilities.getToposortedPlugins(plugins, ignoreMissing=True))
    root.updateHtmlVars({
        'apiRoot':
        curConfig['server']['api_root'],
        'staticRoot':
        os.path.relpath(routeTable[constants.GIRDER_STATIC_ROUTE_ID],
                        routeTable[constants.GIRDER_ROUTE_ID]),
        'plugins':
        plugins
    })

    root.api.v1.updateHtmlVars({
        'apiRoot':
        curConfig['server']['api_root'],
        'staticRoot':
        routeTable[constants.GIRDER_STATIC_ROUTE_ID],
    })

    root, appconf, _ = plugin_utilities.loadPlugins(plugins,
                                                    root,
                                                    appconf,
                                                    root.api.v1,
                                                    buildDag=False)

    return root, appconf