def install_web(opts=None): """ Build and install Girder's web client, or perform a watch on the web client or a specified plugin. For documentation of all the options, see the argparse configuration for the "web" subcommand in the main() function. """ if opts is None: runWebBuild() elif opts.watch: _runWatchCmd('npm', 'run', 'watch') elif opts.watch_plugin: staticPlugins = plugin_utilities.getToposortedPlugins( [opts.watch_plugin], ignoreMissing=True, keys=('dependencies', 'staticWebDependencies')) staticPlugins = [p for p in staticPlugins if p != opts.watch_plugin] _runWatchCmd('npm', 'run', 'watch', '--', '--plugins=%s' % opts.watch_plugin, '--configure-plugins=%s' % ','.join(staticPlugins), 'webpack:%s_%s' % (opts.plugin_prefix, opts.watch_plugin)) else: runWebBuild(dev=opts.development, npm=opts.npm, allPlugins=opts.all_plugins, plugins=opts.plugins, noPlugins=opts.no_plugins)
def _getPluginBuildArgs(buildAll, plugins): if buildAll: return ['--all-plugins'] elif not plugins: # build only the enabled plugins settings = model_importer.ModelImporter().model('setting') plugins = settings.get(constants.SettingKey.PLUGINS_ENABLED, default=()) plugins = list(plugin_utilities.getToposortedPlugins(plugins, ignoreMissing=True)) # include static-only dependencies that are not in the runtime load set staticPlugins = plugin_utilities.getToposortedPlugins( plugins, ignoreMissing=True, keys=('dependencies', 'staticWebDependencies')) staticPlugins = [p for p in staticPlugins if p not in plugins] return [ '--plugins=%s' % ','.join(plugins), '--configure-plugins=%s' % ','.join(staticPlugins) ]
def _getPluginBuildArgs(buildAll, plugins): if buildAll: sortedPlugins = plugin_utilities.getToposortedPlugins() return ['--plugins=%s' % ','.join(sortedPlugins)] elif plugins is None: # build only the enabled plugins plugins = Setting().get(constants.SettingKey.PLUGINS_ENABLED, default=()) plugins = list(plugin_utilities.getToposortedPlugins(plugins, ignoreMissing=True)) # include static-only dependencies that are not in the runtime load set staticPlugins = plugin_utilities.getToposortedPlugins( plugins, ignoreMissing=True, keys=('dependencies', 'staticWebDependencies')) staticPlugins = [p for p in staticPlugins if p not in plugins] return [ '--plugins=%s' % ','.join(plugins), '--configure-plugins=%s' % ','.join(staticPlugins) ]
def validateCorePluginsEnabled(doc): """ Ensures that the set of plugins passed in is a list of valid plugin names. Removes any invalid plugin names, removes duplicates, and adds all transitive dependencies to the enabled list. """ if not isinstance(doc['value'], list): raise ValidationException('Plugins enabled setting must be a list.', 'value') # Add all transitive dependencies and store in toposorted order doc['value'] = list(plugin_utilities.getToposortedPlugins(doc['value']))
def _getPluginBuildArgs(buildAll, plugins): if buildAll: return ['--all-plugins'] elif not plugins: # build only the enabled plugins settings = model_importer.ModelImporter().model('setting') plugins = settings.get(constants.SettingKey.PLUGINS_ENABLED, default=()) plugins = ','.join( plugin_utilities.getToposortedPlugins(plugins, ignoreMissing=True)) return ['--plugins=%s' % plugins]
def validateCorePluginsEnabled(self, doc): """ Ensures that the set of plugins passed in is a list of valid plugin names. Removes any invalid plugin names, removes duplicates, and adds all transitive dependencies to the enabled list. """ if not isinstance(doc['value'], list): raise ValidationException( 'Plugins enabled setting must be a list.', 'value') # Add all transitive dependencies and store in toposorted order doc['value'] = list(plugin_utilities.getToposortedPlugins(doc['value']))
def install_web(opts=None): """ Build and install Girder's web client, or perform a watch on the web client or a specified plugin. For documentation of all the options, see the argparse configuration for the "web" subcommand in the main() function. """ if opts is None: runWebBuild() elif opts.watch: _runWatchCmd('npm', 'run', 'watch') elif opts.watch_plugin: staticPlugins = plugin_utilities.getToposortedPlugins( [opts.watch_plugin], ignoreMissing=True, keys=('dependencies', 'staticWebDependencies')) staticPlugins = [p for p in staticPlugins if p != opts.watch_plugin] _runWatchCmd( 'npm', 'run', 'watch', '--', '--plugins=%s' % opts.watch_plugin, '--configure-plugins=%s' % ','.join(staticPlugins), 'webpack:%s_%s' % (opts.plugin_prefix, opts.watch_plugin)) else: runWebBuild( dev=opts.development, npm=opts.npm, allPlugins=opts.all_plugins, plugins=opts.plugins, noPlugins=opts.no_plugins)
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
def getPlugins(): plugins = Setting().get(constants.SettingKey.PLUGINS_ENABLED, default=()) return plugin_utilities.getToposortedPlugins(plugins, ignoreMissing=True)
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'), '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' } }) 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 }) # Make the staticRoot relative to the api_root, if possible. The api_root # could be relative or absolute, but it needs to be in an absolute form for # relpath to behave as expected. We always expect the api_root to # contain at least two components, but the reference from static needs to # be from only the first component. apiRootBase = os.path.split( os.path.join('/', curConfig['server']['api_root']))[0] root.api.v1.updateHtmlVars({ 'apiRoot': curConfig['server']['api_root'], 'staticRoot': os.path.relpath(routeTable[constants.GIRDER_STATIC_ROUTE_ID], apiRootBase) }) root, appconf, _ = plugin_utilities.loadPlugins(plugins, root, appconf, root.api.v1, buildDag=False) return root, appconf
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
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=()) 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
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