示例#1
0
 def __init__(self, trans, repository_id, changeset_revision, tools_metadata, tool_id):
     self.trans = trans
     self.tools_metadata = tools_metadata
     self.tool_id = tool_id
     self.tool = None
     self.errors = None
     self.tool_version = None
     if trans.webapp.name == 'tool_shed':
         # We're in the tool shed.
         with ValidationContext.from_app(trans.app) as validation_context:
             tv = tool_validator.ToolValidator(validation_context)
             for tool_dict in tools_metadata:
                 if self.tool_id in [tool_dict['id'], tool_dict['guid']]:
                     repository, self.tool, message = tv.load_tool_from_changeset_revision(repository_id,
                                                                                           changeset_revision,
                                                                                           tool_dict['tool_config'])
                     if message and self.tool is None:
                         self.errors = 'unavailable'
                     break
     else:
         # We're in Galaxy.
         self.tool = trans.app.toolbox.get_tool(self.tool_id, tool_version=self.tool_version)
         if self.tool is None:
             self.errors = 'unavailable'
     self.post_job_actions = {}
     self.workflow_outputs = []
     self.state = None
示例#2
0
 def __init__(self, trans, repository_id, changeset_revision, tools_metadata, tool_id):
     self.trans = trans
     self.tools_metadata = tools_metadata
     self.tool_id = tool_id
     self.tool = None
     self.errors = None
     self.tool_version = None
     if trans.webapp.name == 'tool_shed':
         # We're in the tool shed.
         with ValidationContext.from_app(trans.app) as validation_context:
             tv = tool_validator.ToolValidator(validation_context)
             for tool_dict in tools_metadata:
                 if self.tool_id in [tool_dict['id'], tool_dict['guid']]:
                     repository, self.tool, valid, message = tv.load_tool_from_changeset_revision(repository_id,
                                                                                                  changeset_revision,
                                                                                                  tool_dict['tool_config'])
                     if self.tool is None and message or not valid:
                         self.errors = 'unavailable'
                     break
     else:
         # We're in Galaxy.
         self.tool = trans.app.toolbox.get_tool(self.tool_id, tool_version=self.tool_version)
         if self.tool is None:
             self.errors = 'unavailable'
     self.post_job_actions = {}
     self.workflow_outputs = []
     self.state = None
def get_tool_validator():
    app = MockApp()
    with ValidationContext.from_app(app) as validation_context:
        yield ToolValidator(validation_context)
示例#4
0
    def json(self, trans, **kwd):
        """
        GET /api/tools/json

        Get the tool form JSON for a tool in a repository.

        :param guid:          the GUID of the tool
        :param guid:          str

        :param tsr_id:        the ID of the repository
        :param tsr_id:        str

        :param changeset:     the changeset at which to load the tool json
        :param changeset:     str
        """
        guid = kwd.get('guid', None)
        tsr_id = kwd.get('tsr_id', None)
        changeset = kwd.get('changeset', None)
        if None in [changeset, tsr_id, guid]:
            message = 'Changeset, repository ID, and tool GUID are all required parameters.'
            trans.response.status = 400
            return {'status': 'error', 'message': message}
        tsucm = ToolShedUtilityContainerManager(trans.app)
        repository = repository_util.get_repository_in_tool_shed(self.app, tsr_id)
        repository_clone_url = common_util.generate_clone_url_for_repository_in_tool_shed(repository.user, repository)
        repository_metadata = metadata_util.get_repository_metadata_by_changeset_revision(trans.app, tsr_id, changeset)
        toolshed_base_url = str(web.url_for('/', qualified=True)).rstrip('/')
        rb = relation_builder.RelationBuilder(trans.app, repository, repository_metadata, toolshed_base_url)
        repository_dependencies = rb.get_repository_dependencies_for_changeset_revision()
        containers_dict = tsucm.build_repository_containers(repository,
                                                            changeset,
                                                            repository_dependencies,
                                                            repository_metadata)
        found_tool = None
        for folder in containers_dict['valid_tools'].folders:
            if hasattr(folder, 'valid_tools'):
                for tool in folder.valid_tools:
                    tool.id = tool.tool_id
                    tool_guid = suc.generate_tool_guid(repository_clone_url, tool)
                    if tool_guid == guid:
                        found_tool = tool
                        break
        if found_tool is None:
            message = 'Unable to find tool with guid %s in repository %s.' % (guid, repository.name)
            trans.response.status = 404
            return {'status': 'error', 'message': message}

        with ValidationContext.from_app(trans.app) as validation_context:
            tv = tool_validator.ToolValidator(validation_context)
            repository, tool, message = tv.load_tool_from_changeset_revision(tsr_id,
                                                                             changeset,
                                                                             found_tool.tool_config)
        if message:
            status = 'error'
            return dict(message=message, status=status)
        tool_help = ''
        if tool.help:
            tool_help = tool.help.render(static_path=web.url_for('/static'), host_url=web.url_for('/', qualified=True))
            tool_help = util.unicodify(tool_help, 'utf-8')
        tool_dict = tool.to_dict(trans)
        tool_dict['inputs'] = {}
        tool.populate_model(trans, tool.inputs, {}, tool_dict['inputs'])
        tool_dict.update({
            'help'          : tool_help,
            'citations'     : bool(tool.citations),
            'biostar_url'   : trans.app.config.biostar_url,
            'requirements'  : [{'name' : r.name, 'version' : r.version} for r in tool.requirements],
            'state_inputs'  : params_to_strings(tool.inputs, {}, trans.app),
            'display'       : tool.display_interface,
            'action'        : web.url_for(tool.action),
            'method'        : tool.method,
            'enctype'       : tool.enctype
        })
        return json.dumps(tool_dict)
示例#5
0
文件: tools.py 项目: msauria/galaxy
    def json(self, trans, **kwd):
        """
        GET /api/tools/json

        Get the tool form JSON for a tool in a repository.

        :param guid:          the GUID of the tool
        :param guid:          str

        :param tsr_id:        the ID of the repository
        :param tsr_id:        str

        :param changeset:     the changeset at which to load the tool json
        :param changeset:     str
        """
        guid = kwd.get('guid', None)
        tsr_id = kwd.get('tsr_id', None)
        changeset = kwd.get('changeset', None)
        if None in [changeset, tsr_id, guid]:
            message = 'Changeset, repository ID, and tool GUID are all required parameters.'
            trans.response.status = 400
            return {'status': 'error', 'message': message}
        tsucm = ToolShedUtilityContainerManager(trans.app)
        repository = repository_util.get_repository_in_tool_shed(
            self.app, tsr_id)
        repository_clone_url = common_util.generate_clone_url_for_repository_in_tool_shed(
            repository.user, repository)
        repository_metadata = metadata_util.get_repository_metadata_by_changeset_revision(
            trans.app, tsr_id, changeset)
        toolshed_base_url = str(web.url_for('/', qualified=True)).rstrip('/')
        rb = relation_builder.RelationBuilder(trans.app, repository,
                                              repository_metadata,
                                              toolshed_base_url)
        repository_dependencies = rb.get_repository_dependencies_for_changeset_revision(
        )
        containers_dict = tsucm.build_repository_containers(
            repository, changeset, repository_dependencies,
            repository_metadata)
        found_tool = None
        for folder in containers_dict['valid_tools'].folders:
            if hasattr(folder, 'valid_tools'):
                for tool in folder.valid_tools:
                    tool.id = tool.tool_id
                    tool_guid = suc.generate_tool_guid(repository_clone_url,
                                                       tool)
                    if tool_guid == guid:
                        found_tool = tool
                        break
        if found_tool is None:
            message = f'Unable to find tool with guid {guid} in repository {repository.name}.'
            trans.response.status = 404
            return {'status': 'error', 'message': message}

        with ValidationContext.from_app(trans.app) as validation_context:
            tv = tool_validator.ToolValidator(validation_context)
            repository, tool, valid, message = tv.load_tool_from_changeset_revision(
                tsr_id, changeset, found_tool.tool_config)
        if message or not valid:
            status = 'error'
            return dict(message=message, status=status)
        tool_help = ''
        if tool.help:
            tool_help = tool.help.render(static_path=web.url_for('/static'),
                                         host_url=web.url_for('/',
                                                              qualified=True))
            tool_help = util.unicodify(tool_help, 'utf-8')
        tool_dict = tool.to_dict(trans)
        tool_dict['inputs'] = {}
        tool.populate_model(trans, tool.inputs, {}, tool_dict['inputs'])
        tool_dict.update({
            'help':
            tool_help,
            'citations':
            bool(tool.citations),
            'requirements': [{
                'name': r.name,
                'version': r.version
            } for r in tool.requirements],
            'state_inputs':
            params_to_strings(tool.inputs, {}, trans.app),
            'display':
            tool.display_interface,
            'action':
            web.url_for(tool.action),
            'method':
            tool.method,
            'enctype':
            tool.enctype
        })
        return json.dumps(tool_dict)
def get_tool_validator():
    app = MockApp()
    with ValidationContext.from_app(app) as validation_context:
        yield ToolValidator(validation_context)