How to use the girder.utility.model_importer.ModelImporter function in girder

To help you get started, we’ve selected a few girder examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Kitware / minerva / server / jobs / soda_import_worker.py View on Github external
def run(job):
    job_model = ModelImporter.model('job', 'jobs')
    job_model.updateJob(job, status=JobStatus.RUNNING)

    try:
        configFile = os.path.join(os.path.dirname(__file__), "bsve.json")
        if os.path.exists(configFile):
            bsveConfig = json.load(open(configFile))['bsve']
        else:
            bsveConfig = {}

        kwargs = job['kwargs']
        datasetId = str(kwargs['dataset']['_id'])

        # TODO better to create a job token rather than a user token?
        token = kwargs['token']

        params = kwargs['params']
github nasa-jpl-memex / image_space / imagespace_smqtk / server / smqtk_iqr.py View on Github external
def getSessions(self, params):
        sessionsFolder = getCreateSessionsFolder()
        return list(ModelImporter.model('folder').childItems(folder=sessionsFolder))
github Kitware / minerva / girder / api / rest.py View on Github external
def ensureTokenScopes(token, scope):
    """
    Call this to validate a token scope for endpoints that require tokens
    other than a user authentication token. Raises an AccessException if the
    required scopes are not allowed by the given token.

    :param token: The token object used in the request.
    :type token: dict
    :param scope: The required scope or set of scopes.
    :type scope: str or list of str
    """
    tokenModel = ModelImporter.model('token')
    if not tokenModel.hasScope(token, scope):
        setattr(cherrypy.request, 'girderUser', None)
        if isinstance(scope, six.string_types):
            scope = (scope,)
        raise AccessException(
            'Invalid token scope.\n'
            'Required: %s.\n'
            'Allowed: %s' % (
                ' '.join(scope), ' '.join(tokenModel.getAllowedScopes(token))))
github Kitware / tangelo / tangelo / tangelo / girder.py View on Github external
# 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"}}
github Kitware / cumulus / cumulus / taskflow / core / __init__.py View on Github external
def start(self, *args, **kwargs):
        user = getCurrentUser()
        # Load the cluster
        cluster_id = parse('cluster._id').find(kwargs)
        if cluster_id:
            cluster_id = cluster_id[0].value
            model = ModelImporter.model('cluster', 'cumulus')
            cluster = model.load(cluster_id, user=user, level=AccessType.ADMIN)
            cluster = model.filter(cluster, user, passphrase=False)
            kwargs['cluster'] = cluster

        profile_id = parse('cluster.profileId').find(kwargs)
        if profile_id:
            profile_id = profile_id[0].value
            model = ModelImporter.model('aws', 'cumulus')
            profile = model.load(profile_id, user=user, level=AccessType.ADMIN)
            kwargs['profile'] = profile

        super(ClusterProvisioningTaskFlow, self).start(
            setup_cluster.s(self, *args, **kwargs))
github Kitware / minerva / plugins / oauth / server / providers.py View on Github external
def _verifyOpenRegistration():
    """
    Raises a REST exception if registration policy on the server is not set to
    'open'. This should be called by the provider-specific code in the case when
    a user logs in with an email that is not already tied to an existing user.
    """
    policy = model_importer.ModelImporter().model('setting').get(
        SettingKey.REGISTRATION_POLICY, default='open')
    if policy != 'open':
        raise RestException(
            'Registration on this instance is closed. Contact an administrator '
            'to create an account for you.')
github Kitware / minerva / server / jobs / elastic_geospace_worker.py View on Github external
def run(job):
    job_model = ModelImporter.model('job', 'jobs')
    job_model.updateJob(job, status=JobStatus.RUNNING)

    try:
        kwargs = job['kwargs']
        # TODO better to create a job token rather than a user token?
        token = kwargs['token']
        datasetId = str(kwargs['dataset']['_id'])
        elasticSearchParams = kwargs['params']['elasticSearchParams']

        # connect to girder and upload the file
        # TODO will probably have to change this from local to romanesco
        # so that can work on worker machine
        # at least need host connection info
        girderPort = config.getConfig()['server.socket_port']
        client = girder_client.GirderClient(port=girderPort)
        client.token = token['_id']
github Kitware / cumulus / girder / sftp / sftp / rest.py View on Github external
def create_assetstore(self, params):
        """Create a new SFTP assetstore."""

        params = getBodyJson()
        self.requireParams(('name', 'host', 'user'), params)

        return ModelImporter.model('assetstore').save({
            'type': AssetstoreType.SFTP,
            'name': params.get('name'),
            'sftp': {
                'host': params.get('host'),
                'user': params.get('user'),
                'authKey': params.get('authKey')
            }
github girder / girder / girder / utility / plugin_utilities.py View on Github external
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
        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]
            )