def load(self, info): mail_utils.addTemplateDirectory(os.path.join(_HERE, 'mail_templates')) curatedFolder = CuratedFolder() info['apiRoot'].folder.route( 'GET', (':id', 'curation'), curatedFolder.getCuration) info['apiRoot'].folder.route( 'PUT', (':id', 'curation'), curatedFolder.setCuration)
def load(info): # set the title of the HTML pages info['serverRoot'].updateHtmlVars({'title': 'ISIC Archive'}) # add event listeners events.bind('rest.get.describe/:resource.after', 'onDescribeResource', onDescribeResource) events.bind('model.job.save', 'onJobSave', onJobSave) # add custom model searching resource.allowedSearchTypes.update({ 'image.isic_archive', 'featureset.isic_archive', 'study.isic_archive', }) # register licenses for template usage mail_utils.addTemplateDirectory(os.path.join(info['pluginRootDir'], 'server', 'license_templates'), prepend=True) registerPluginWebroot(Webroot(), info['name']) # add static file serving info['config']['/uda'] = { 'tools.staticdir.on': 'True', 'tools.staticdir.dir': os.path.join(info['pluginRootDir'], 'custom') } # add dynamic root routes # root endpoints -> where a user may go and expect a UI class Root(object): pass legacyWebroot = Root() legacyWebroot.gallery = staticFile( os.path.join(info['pluginRootDir'], 'custom', 'gallery.html')) legacyWebroot.segment = staticFile( os.path.join(info['pluginRootDir'], 'custom', 'phase1.html')) legacyWebroot.annotate = staticFile( os.path.join(info['pluginRootDir'], 'custom', 'phase2.html')) registerPluginWebroot(legacyWebroot, 'markup') # create all necessary users, groups, collections, etc provisionDatabase() # add api routes # remove docs for default Girder API, to simplify page clearRouteDocs() # TODO: nest these under a "/isic" path? info['apiRoot'].annotation = api.AnnotationResource() info['apiRoot'].dataset = api.DatasetResource() info['apiRoot'].featureset = api.FeaturesetResource() info['apiRoot'].image = api.ImageResource() info['apiRoot'].segmentation = api.SegmentationResource() info['apiRoot'].study = api.StudyResource() info['apiRoot'].task = api.TaskResource() api.attachUserApi(info['apiRoot'].user)
def load(info): # set the title of the HTML pages info['serverRoot'].updateHtmlVars({'title': 'ISIC Archive'}) # add event listeners events.bind('rest.get.describe/:resource.after', 'onDescribeResource', onDescribeResource) events.bind('model.job.save', 'onJobSave', onJobSave) # add custom model searching resource.allowedSearchTypes.update({ 'image.isic_archive', 'featureset.isic_archive', 'study.isic_archive', }) # register licenses for template usage mail_utils.addTemplateDirectory( os.path.join(info['pluginRootDir'], 'server', 'license_templates'), prepend=True) registerPluginWebroot(Webroot(), info['name']) # add static file serving info['config']['/uda'] = { 'tools.staticdir.on': 'True', 'tools.staticdir.dir': os.path.join(info['pluginRootDir'], 'custom') } # add dynamic root routes # root endpoints -> where a user may go and expect a UI class Root(object): pass legacyWebroot = Root() legacyWebroot.gallery = staticFile( os.path.join(info['pluginRootDir'], 'custom', 'gallery.html')) legacyWebroot.segment = staticFile( os.path.join(info['pluginRootDir'], 'custom', 'phase1.html')) legacyWebroot.annotate = staticFile( os.path.join(info['pluginRootDir'], 'custom', 'phase2.html')) registerPluginWebroot(legacyWebroot, 'markup') # create all necessary users, groups, collections, etc provisionDatabase() # add api routes # remove docs for default Girder API, to simplify page clearRouteDocs() # TODO: nest these under a "/isic" path? info['apiRoot'].annotation = api.AnnotationResource() info['apiRoot'].dataset = api.DatasetResource() info['apiRoot'].featureset = api.FeaturesetResource() info['apiRoot'].image = api.ImageResource() info['apiRoot'].segmentation = api.SegmentationResource() info['apiRoot'].study = api.StudyResource() info['apiRoot'].task = api.TaskResource() api.attachUserApi(info['apiRoot'].user)
def loadPlugin(name, root, appconf, apiRoot=None, curConfig=None): """ Loads a plugin into the application. This means allowing it to create endpoints within its own web API namespace, and to register its event listeners, and do anything else it might want to do. :param name: The name of the plugin (i.e. its directory name) :type name: str :param root: The root node of the web API. :param appconf: The cherrypy configuration for the server. :type appconf: dict """ if apiRoot is None: apiRoot = root.api.v1 pluginParentDir = getPluginParentDir(name, curConfig) pluginDir = os.path.join(pluginParentDir, name) isPluginDir = os.path.isdir(os.path.join(pluginDir, 'server')) isPluginFile = os.path.isfile(os.path.join(pluginDir, 'server.py')) if not os.path.exists(pluginDir): raise Exception('Plugin directory does not exist: {}'.format(pluginDir)) if not isPluginDir and not isPluginFile: # This plugin does not have any server-side python code. return root, appconf, apiRoot mailTemplatesDir = os.path.join(pluginDir, 'server', 'mail_templates') if os.path.isdir(mailTemplatesDir): # If the plugin has mail templates, add them to the lookup path mail_utils.addTemplateDirectory(mailTemplatesDir, prepend=True) moduleName = '.'.join((ROOT_PLUGINS_PACKAGE, name)) if moduleName not in sys.modules: fp = None try: fp, pathname, description = imp.find_module('server', [pluginDir]) module = imp.load_module(moduleName, fp, pathname, description) module.PLUGIN_ROOT_DIR = pluginDir girder.plugins.__dict__[name] = module if hasattr(module, 'load'): info = { 'name': name, 'config': appconf, 'serverRoot': root, 'apiRoot': apiRoot, 'pluginRootDir': os.path.abspath(pluginDir) } module.load(info) root, appconf, apiRoot = ( info['serverRoot'], info['config'], info['apiRoot']) finally: if fp: fp.close() return root, appconf, apiRoot
def loadPlugin(name, root, appconf, apiRoot=None, curConfig=None): """ Loads a plugin into the application. This means allowing it to create endpoints within its own web API namespace, and to register its event listeners, and do anything else it might want to do. :param name: The name of the plugin (i.e. its directory name) :type name: str :param root: The root node of the web API. :param appconf: The cherrypy configuration for the server. :type appconf: dict """ if apiRoot is None: apiRoot = root.api.v1 pluginDir = os.path.join(getPluginDir(curConfig), name) isPluginDir = os.path.isdir(os.path.join(pluginDir, 'server')) isPluginFile = os.path.isfile(os.path.join(pluginDir, 'server.py')) if not os.path.exists(pluginDir): raise Exception( 'Plugin directory does not exist: {}'.format(pluginDir)) if not isPluginDir and not isPluginFile: # This plugin does not have any server-side python code. return root, appconf, apiRoot mailTemplatesDir = os.path.join(pluginDir, 'server', 'mail_templates') if os.path.isdir(mailTemplatesDir): # If the plugin has mail templates, add them to the lookup path mail_utils.addTemplateDirectory(mailTemplatesDir, prepend=True) moduleName = '.'.join((ROOT_PLUGINS_PACKAGE, name)) if moduleName not in sys.modules: fp = None try: fp, pathname, description = imp.find_module('server', [pluginDir]) module = imp.load_module(moduleName, fp, pathname, description) module.PLUGIN_ROOT_DIR = pluginDir girder.plugins.__dict__[name] = module if hasattr(module, 'load'): info = { 'name': name, 'config': appconf, 'serverRoot': root, 'apiRoot': apiRoot, 'pluginRootDir': os.path.abspath(pluginDir) } module.load(info) root, appconf, apiRoot = (info['serverRoot'], info['config'], info['apiRoot']) finally: if fp: fp.close() return root, appconf, apiRoot
def loadPlugin(name, root, appconf, apiRoot=None, curConfig=None): """ Loads a plugin into the application. This means allowing it to create endpoints within its own web API namespace, and to register its event listeners, and do anything else it might want to do. :param name: The name of the plugin (i.e. its directory name) :type name: str :param root: The root node of the web API. :param appconf: The cherrypy configuration for the server. :type appconf: dict """ if apiRoot is None: apiRoot = root.api.v1 pluginDir = os.path.join(getPluginDir(curConfig), name) isPluginDir = os.path.isdir(os.path.join(pluginDir, "server")) isPluginFile = os.path.isfile(os.path.join(pluginDir, "server.py")) if not os.path.exists(pluginDir): raise Exception("Plugin directory does not exist: {}".format(pluginDir)) if not isPluginDir and not isPluginFile: # This plugin does not have any server-side python code. return root, appconf, apiRoot mailTemplatesDir = os.path.join(pluginDir, "server", "mail_templates") if os.path.isdir(mailTemplatesDir): # If the plugin has mail templates, add them to the lookup path mail_utils.addTemplateDirectory(mailTemplatesDir, prepend=True) moduleName = ".".join((ROOT_PLUGINS_PACKAGE, name)) if moduleName not in sys.modules: fp = None try: fp, pathname, description = imp.find_module("server", [pluginDir]) module = imp.load_module(moduleName, fp, pathname, description) setattr(module, "PLUGIN_ROOT_DIR", pluginDir) if hasattr(module, "load"): info = { "name": name, "config": appconf, "serverRoot": root, "apiRoot": apiRoot, "pluginRootDir": os.path.abspath(pluginDir), } module.load(info) root, appconf, apiRoot = (info["serverRoot"], info["config"], info["apiRoot"]) finally: if fp: fp.close() return root, appconf, apiRoot
def load(self, info): ModelImporter.registerModel('annotationItem', AnnotationItem, plugin='dive_server') ModelImporter.registerModel('revisionLogItem', RevisionLogItem, plugin='dive_server') info["apiRoot"].dive_annotation = AnnotationResource("dive_annotation") info["apiRoot"].dive_configuration = ConfigurationResource("dive_configuration") info["apiRoot"].dive_dataset = DatasetResource("dive_dataset") info["apiRoot"].dive_rpc = RpcResource("dive_rpc") # Setup route additions for exsting resources info["apiRoot"].user.route("PUT", (":id", "use_private_queue"), use_private_queue) User().exposeFields(AccessType.READ, constants.UserPrivateQueueEnabledMarker) # Expose Job dataset assocation Job().exposeFields(AccessType.READ, constants.JOBCONST_DATASET_ID) DIVE_MAIL_TEMPLATES = Path(os.path.realpath(__file__)).parent / 'mail_templates' mail_utils.addTemplateDirectory(str(DIVE_MAIL_TEMPLATES)) # Relocate Girder info["serverRoot"], info["serverRoot"].girder = ( ClientWebroot(), info["serverRoot"], ) info["serverRoot"].api = info["serverRoot"].girder.api events.bind( "filesystem_assetstore_imported", "process_fs_import", process_fs_import, ) events.bind( "s3_assetstore_imported", "process_s3_import", process_s3_import, ) events.bind( 'model.user.save.created', 'send_new_user_email', send_new_user_email, ) # Create dependency on worker plugin.getPlugin('worker').load(info) Setting().set( 'worker.api_url', os.environ.get('WORKER_API_URL', 'http://girder:8080/api/v1'), ) broker_url = os.environ.get('CELERY_BROKER_URL', None) if broker_url is None: raise RuntimeError('CELERY_BROKER_URL must be set') Setting().set('worker.broker', broker_url)
def load(self, info): name = 'authorized_upload' mail_utils.addTemplateDirectory(os.path.join(_HERE, 'mail_templates')) events.bind('rest.post.file.before', name, _authorizeInitUpload) events.bind('rest.post.file.after', name, _storeUploadId) events.bind('rest.post.file/chunk.before', name, _authorizeUploadStep) events.bind('rest.post.file/completion.before', name, _authorizeUploadStep) events.bind('rest.get.file/offset.before', name, _authorizeUploadStep) events.bind('model.file.finalizeUpload.after', name, _uploadComplete) info['apiRoot'].authorized_upload = AuthorizedUpload()
def load(self, info): name = 'authorized_upload' mail_utils.addTemplateDirectory(os.path.join(_HERE, 'mail_templates')) events.bind('rest.post.file.before', name, _authorizeInitUpload) events.bind('rest.post.file.after', name, _storeUploadId) events.bind('rest.post.file/chunk.before', name, _authorizeUploadStep) events.bind('rest.post.file/completion.before', name, _authorizeUploadStep) events.bind('rest.get.file/offset.before', name, _authorizeUploadStep) events.bind('model.file.finalizeUpload.after', name, _uploadComplete) info['apiRoot'].authorized_upload = AuthorizedUpload()
def load(self, info): getPlugin('gravatar').load(info) getPlugin('jobs').load(info) getPlugin('worker').load(info) getPlugin('thumbnails').load(info) mail_utils.addTemplateDirectory(os.path.join(_HERE, 'mail_templates')) ModelImporter.registerModel('challenge', Challenge, 'covalic') ModelImporter.registerModel('phase', Phase, 'covalic') ModelImporter.registerModel('submission', Submission, 'covalic') resource.allowedSearchTypes.add('challenge.covalic') info['apiRoot'].challenge = ChallengeResource() info['apiRoot'].challenge_phase = PhaseResource() info['apiRoot'].covalic_submission = SubmissionResource() webroot = WebrootBase(os.path.join(_HERE, 'webroot.mako')) webroot.updateHtmlVars({ 'pluginCss': [ plugin for plugin in loadedPlugins() if os.path.exists(os.path.join( STATIC_ROOT_DIR, 'built', 'plugins', plugin, 'plugin.min.css')) ], 'pluginJs': [ plugin for plugin in loadedPlugins() if os.path.exists(os.path.join( STATIC_ROOT_DIR, 'built', 'plugins', plugin, 'plugin.min.js')) ] }) registerPluginWebroot(webroot, 'covalic') events.bind('jobs.job.update', 'covalic', onJobUpdate) events.bind('model.setting.validate', 'covalic', validateSettings) events.bind('model.challenge_challenge.save.after', 'covalic', challengeSaved) events.bind('model.challenge_phase.save.after', 'covalic', onPhaseSave) events.bind('model.user.save.after', 'covalic', onUserSave)
def loadPlugin(name, root, appconf, apiRoot=None): """ Loads a plugin into the application. This means allowing it to create endpoints within its own web API namespace, and to register its event listeners, and do anything else it might want to do. :param name: The name of the plugin (i.e. its directory name) :type name: str :param root: The root node of the web API. :param appconf: The cherrypy configuration for the server. :type appconf: dict """ if apiRoot is None: apiRoot = root.api.v1 pluginDir = os.path.join(getPluginDir(), name) isPluginDir = os.path.isdir(os.path.join(pluginDir, 'server')) isPluginFile = os.path.isfile(os.path.join(pluginDir, 'server.py')) pluginLoadMethod = None if not os.path.exists(pluginDir): # Try to load the plugin as an entry_point for entry_point in iter_entry_points(group='girder.plugin', name=name): pluginLoadMethod = entry_point.load() module = importlib.import_module(entry_point.module_name) pluginDir = os.path.dirname(module.__file__) module.PLUGIN_ROOT_DIR = pluginDir girder.plugins.__dict__[name] = module isPluginDir = True if not os.path.exists(pluginDir): raise Exception('Plugin directory does not exist: %s' % pluginDir) if not isPluginDir and not isPluginFile: # This plugin does not have any server-side python code. return root, appconf, apiRoot mailTemplatesDir = os.path.join(pluginDir, 'server', 'mail_templates') if os.path.isdir(mailTemplatesDir): # If the plugin has mail templates, add them to the lookup path mail_utils.addTemplateDirectory(mailTemplatesDir, prepend=True) moduleName = '.'.join((ROOT_PLUGINS_PACKAGE, name)) fp = None try: # @todo this query is run for every plugin that's loaded routeTable = Setting().get(SettingKey.ROUTE_TABLE) info = { 'name': name, 'config': appconf, 'serverRoot': root, 'serverRootPath': routeTable[GIRDER_ROUTE_ID], 'apiRoot': apiRoot, 'staticRoot': routeTable[GIRDER_STATIC_ROUTE_ID], 'pluginRootDir': os.path.abspath(pluginDir) } if pluginLoadMethod is None: fp, pathname, description = imp.find_module('server', [pluginDir]) module = imp.load_module(moduleName, fp, pathname, description) module.PLUGIN_ROOT_DIR = pluginDir girder.plugins.__dict__[name] = module pluginLoadMethod = getattr(module, 'load', None) if pluginLoadMethod is not None: sys.modules[moduleName] = module pluginLoadMethod(info) root, appconf, apiRoot = (info['serverRoot'], info['config'], info['apiRoot']) finally: if fp: fp.close() return root, appconf, apiRoot
def loadPlugin(name, root, appconf, apiRoot=None): """ Loads a plugin into the application. This means allowing it to create endpoints within its own web API namespace, and to register its event listeners, and do anything else it might want to do. :param name: The name of the plugin (i.e. its directory name) :type name: str :param root: The root node of the web API. :param appconf: The cherrypy configuration for the server. :type appconf: dict """ if apiRoot is None: apiRoot = root.api.v1 pluginDir = os.path.join(getPluginDir(), name) isPluginDir = os.path.isdir(os.path.join(pluginDir, 'server')) isPluginFile = os.path.isfile(os.path.join(pluginDir, 'server.py')) pluginLoadMethod = None if not os.path.exists(pluginDir): # Try to load the plugin as an entry_point for entry_point in iter_entry_points(group='girder.plugin', name=name): pluginLoadMethod = entry_point.load() module = importlib.import_module(entry_point.module_name) pluginDir = os.path.dirname(module.__file__) module.PLUGIN_ROOT_DIR = pluginDir girder.plugins.__dict__[name] = module isPluginDir = True if not os.path.exists(pluginDir): raise Exception('Plugin directory does not exist: %s' % pluginDir) if not isPluginDir and not isPluginFile: # This plugin does not have any server-side python code. return root, appconf, apiRoot mailTemplatesDir = os.path.join(pluginDir, 'server', 'mail_templates') if os.path.isdir(mailTemplatesDir): # If the plugin has mail templates, add them to the lookup path mail_utils.addTemplateDirectory(mailTemplatesDir, prepend=True) moduleName = '.'.join((ROOT_PLUGINS_PACKAGE, name)) if moduleName not in sys.modules: fp = None try: # @todo this query is run for every plugin that's loaded setting = model_importer.ModelImporter().model('setting') routeTable = setting.get(SettingKey.ROUTE_TABLE) info = { 'name': name, 'config': appconf, 'serverRoot': root, 'serverRootPath': routeTable[GIRDER_ROUTE_ID], 'apiRoot': apiRoot, 'staticRoot': routeTable[GIRDER_STATIC_ROUTE_ID], 'pluginRootDir': os.path.abspath(pluginDir) } if pluginLoadMethod is None: fp, pathname, description = imp.find_module( 'server', [pluginDir]) module = imp.load_module(moduleName, fp, pathname, description) module.PLUGIN_ROOT_DIR = pluginDir girder.plugins.__dict__[name] = module pluginLoadMethod = getattr(module, 'load', None) if pluginLoadMethod is not None: sys.modules[moduleName] = module pluginLoadMethod(info) root, appconf, apiRoot = (info['serverRoot'], info['config'], info['apiRoot']) finally: if fp: fp.close() return root, appconf, apiRoot
def load(self, info): mail_utils.addTemplateDirectory( os.path.join(os.path.dirname(__file__), 'data', 'mail_templates'), prepend=True )
def load(self, info): getPlugin('worker').load(info) addTemplateDirectory(os.path.join(os.path.dirname(__file__)), 'mail_templates') dist = os.path.join(os.path.dirname(__file__), 'dist') webroot = staticFile(os.path.join(dist, 'index.html')) registerPluginWebroot(webroot, 'demo_site') info['config']['/stroke_ct_static'] = { 'tools.staticdir.on': True, 'tools.staticdir.dir': os.path.join(dist, 'stroke_ct_static') } info['config']['/itk'] = { 'tools.staticdir.on': True, 'tools.staticdir.dir': os.path.join(dist, 'itk') } info['apiRoot'].study = Study() info['apiRoot'].series = Series() info['apiRoot'].photomorph = Photomorph() info['apiRoot'].inpainting = Inpainting() Folder().ensureIndex(('isStudy', {'sparse': True})) Folder().ensureIndex(('isPhotomorph', {'sparse': True})) Folder().ensureIndex(('photomorphExampleFolder', {'sparse': True})) Folder().ensureIndex(('inpaintingExampleFolder', {'sparse': True})) Folder().exposeFields(level=AccessType.READ, fields={ 'isStudy', 'nSeries', 'studyDate', 'patientId', 'studyModality', 'photomorphJobId', 'isPhotomorph', 'photomorphInputFolderId', 'photomorphOutputItems', 'photomorphJobStatus', 'photomorphMaskRect' }) Item().exposeFields(level=AccessType.READ, fields={ 'isSeries', 'isPhotomorph', 'originalName', 'photomorphTakenDate' }) Job().exposeFields(level=AccessType.READ, fields={ 'photomorphId', 'inpaintingImageId', 'inpaintingMaskId', 'inpaintingImageResultId', 'inpaintingFolderId' }) events.bind('model.file.finalizeUpload.after', 'demo_site', _handleUpload) events.bind('model.item.remove', 'demo_site', _itemDeleted) events.bind('jobs.job.update', 'demo_site', _jobUpdated) # Guest user support events.bind('model.user.authenticate', 'demo_site', _authenticateGuestUser) try: User().createUser(login='******', password='******', firstName='Guest', lastName='User', email='*****@*****.**') except ValidationException: pass
def load(self, info): sentry_sdk.init() getPlugin('large_image').load(info) oauth = getPlugin('oauth') if oauth: oauth.load(info) isic_discourse_sso = getPlugin('isic_discourse_sso') if isic_discourse_sso: # If this plugin is enabled, ensure it loads first, so its API docs are cleared isic_discourse_sso.load(info) # set the title of the HTML pages info['serverRoot'].updateHtmlVars({'title': 'ISIC Archive'}) # register models ModelImporter.registerModel('annotation', Annotation, 'isic_archive') ModelImporter.registerModel('batch', Batch, 'isic_archive') ModelImporter.registerModel('dataset', Dataset, 'isic_archive') ModelImporter.registerModel('image', Image, 'isic_archive') ModelImporter.registerModel('segmentation', Segmentation, 'isic_archive') ModelImporter.registerModel('study', Study, 'isic_archive') ModelImporter.registerModel('user', User, 'isic_archive') # add event listeners events.bind('rest.get.describe/:resource.after', 'isic.onDescribeResource', onDescribeResource) events.bind('model.user.save.created', 'isic.onUserCreate', onUserCreate) # add custom model searching resource.allowedSearchTypes.update({ 'image.isic_archive', 'study.isic_archive', }) # register license and mail templates mail_utils.addTemplateDirectory(pkg_resources.resource_filename( 'isic_archive', 'license_templates'), prepend=True) mail_utils.addTemplateDirectory(pkg_resources.resource_filename( 'isic_archive', 'mail_templates'), prepend=True) # create all necessary users, groups, collections, etc provisionDatabase() # add api routes # remove docs for default Girder API, to simplify page clearRouteDocs() # Customize API docs template baseTemplateFilename = info['apiRoot'].templateFilename info['apiRoot'].updateHtmlVars( {'baseTemplateFilename': baseTemplateFilename}) templatePath = pkg_resources.resource_filename('isic_archive', 'isic_api_docs.mako') info['apiRoot'].setTemplatePath(templatePath) # TODO: nest these under a "/isic" path? info['apiRoot'].annotation = api.AnnotationResource() info['apiRoot'].dataset = api.DatasetResource() info['apiRoot'].image = api.ImageResource() info['apiRoot'].redirects = api.RedirectsResource() info['apiRoot'].segmentation = api.SegmentationResource() info['apiRoot'].study = api.StudyResource() info['apiRoot'].task = api.TaskResource() api.attachUserApi(info['apiRoot'].user)
def addMailTemplates(sender, **kwargs): """Perform the necessary steps from IsicArchive.load.""" mail_utils.addTemplateDirectory(pkg_resources.resource_filename( 'isic_archive', 'mail_templates'), prepend=True)