コード例 #1
0
    def import_capsule( self, trans, payload, **kwd ):
        """
        POST /api/repositories/new/import_capsule
        Import a repository capsule into the Tool Shed.

        :param key: the user's API key

        The following parameters are included in the payload.
        :param tool_shed_url (required): the base URL of the Tool Shed into which the capsule should be imported.
        :param capsule_file_name (required): the name of the capsule file.
        """
        # Get the information about the capsule to be imported from the payload.
        tool_shed_url = payload.get( 'tool_shed_url', '' )
        if not tool_shed_url:
            raise HTTPBadRequest( detail="Missing required parameter 'tool_shed_url'." )
        capsule_file_name = payload.get( 'capsule_file_name', '' )
        if not capsule_file_name:
            raise HTTPBadRequest( detail="Missing required parameter 'capsule_file_name'." )
        capsule_file_path = os.path.abspath( capsule_file_name )
        capsule_dict = dict( error_message='',
                             encoded_file_path=None,
                             status='ok',
                             tar_archive=None,
                             uploaded_file=None,
                             capsule_file_name=None )
        if os.path.getsize( os.path.abspath( capsule_file_name ) ) == 0:
            log.debug( 'Your capsule file %s is empty.' % str( capsule_file_name ) )
            return {}
        try:
            # Open for reading with transparent compression.
            tar_archive = tarfile.open( capsule_file_path, 'r:*' )
        except tarfile.ReadError, e:
            log.debug( 'Error opening capsule file %s: %s' % ( str( capsule_file_name ), str( e ) ) )
            return {}
コード例 #2
0
    def export(self, trans, payload, **kwd):
        """
        POST /api/repository_revisions/export
        Creates and saves a gzip compressed tar archive of a repository and optionally all of its repository dependencies.

        The following parameters are included in the payload.
        :param tool_shed_url (required): the base URL of the Tool Shed from which the Repository is to be exported
        :param name (required): the name of the Repository
        :param owner (required): the owner of the Repository
        :param changeset_revision (required): the changeset_revision of the RepositoryMetadata object associated with the Repository
        :param export_repository_dependencies (optional): whether to export repository dependencies - defaults to False
        :param download_dir (optional): the local directory to which to download the archive - defaults to /tmp
        """
        tool_shed_url = payload.get('tool_shed_url', '')
        if not tool_shed_url:
            raise HTTPBadRequest(
                detail="Missing required parameter 'tool_shed_url'.")
        tool_shed_url = tool_shed_url.rstrip('/')
        name = payload.get('name', '')
        if not name:
            raise HTTPBadRequest(detail="Missing required parameter 'name'.")
        owner = payload.get('owner', '')
        if not owner:
            raise HTTPBadRequest(detail="Missing required parameter 'owner'.")
        changeset_revision = payload.get('changeset_revision', '')
        if not changeset_revision:
            raise HTTPBadRequest(
                detail="Missing required parameter 'changeset_revision'.")
        export_repository_dependencies = payload.get(
            'export_repository_dependencies', False)
        # We'll currently support only gzip-compressed tar archives.
        file_type = 'gz'
        export_repository_dependencies = util.asbool(
            export_repository_dependencies)
        # Get the repository information.
        repository = suc.get_repository_by_name_and_owner(
            trans.app, name, owner)
        if repository is None:
            error_message = 'Cannot locate repository with name %s and owner %s,' % (
                str(name), str(owner))
            log.debug(error_message)
            return None, error_message
        repository_id = trans.security.encode_id(repository.id)
        erm = capsule_manager.ExportRepositoryManager(
            app=trans.app,
            user=trans.user,
            tool_shed_url=tool_shed_url,
            repository=repository,
            changeset_revision=changeset_revision,
            export_repository_dependencies=export_repository_dependencies,
            using_api=True)
        return erm.export_repository()
コード例 #3
0
 def __decode_library_content_id( self, content_id ):
     if len( content_id ) % 16 == 0:
         return 'LibraryDataset', content_id
     elif content_id.startswith( 'F' ):
         return 'LibraryFolder', content_id[ 1: ]
     else:
         raise HTTPBadRequest( 'Malformed library content id ( %s ) specified, unable to decode.' % str( content_id ) )
コード例 #4
0
    def add_repository_registry_entry(self, trans, payload, **kwd):
        """
        POST /api/repositories/add_repository_registry_entry
        Adds appropriate entries to the repository registry for the repository defined by the received name and owner.

        :param key: the user's API key
        
        The following parameters are included in the payload.
        :param tool_shed_url (required): the base URL of the Tool Shed containing the Repository
        :param name (required): the name of the Repository
        :param owner (required): the owner of the Repository
        """
        response_dict = {}
        if not trans.user_is_admin():
            response_dict['status'] = 'error'
            response_dict[
                'message'] = "You are not authorized to add entries to this Tool Shed's repository registry."
            return response_dict
        tool_shed_url = payload.get('tool_shed_url', '')
        if not tool_shed_url:
            raise HTTPBadRequest(
                detail="Missing required parameter 'tool_shed_url'.")
        tool_shed_url = tool_shed_url.rstrip('/')
        name = payload.get('name', '')
        if not name:
            raise HTTPBadRequest(detail="Missing required parameter 'name'.")
        owner = payload.get('owner', '')
        if not owner:
            raise HTTPBadRequest(detail="Missing required parameter 'owner'.")
        repository = suc.get_repository_by_name_and_owner(
            trans.app, name, owner)
        if repository is None:
            error_message = 'Cannot locate repository with name %s and owner %s,' % (
                str(name), str(owner))
            log.debug(error_message)
            response_dict['status'] = 'error'
            response_dict['message'] = error_message
            return response_dict
        # Update the repository registry.
        trans.app.repository_registry.add_entry(repository)
        response_dict['status'] = 'ok'
        response_dict[ 'message' ] = 'Entries for repository %s owned by %s have been added to the Tool Shed repository registry.' \
            % ( name, owner )
        return response_dict
コード例 #5
0
    def update(self, trans, payload, **kwd):
        """
        PUT /api/repository_revisions/{encoded_repository_metadata_id}/{payload}
        Updates the value of specified columns of the repository_metadata table based on the key / value pairs in payload.

        :param id: the encoded id of the `RepositoryMetadata` object
        """
        repository_metadata_id = kwd.get('id', None)
        if repository_metadata_id is None:
            raise HTTPBadRequest(detail="Missing required parameter 'id'.")
        repository_metadata = metadata_util.get_repository_metadata_by_id(
            trans.app, repository_metadata_id)
        if repository_metadata is None:
            decoded_repository_metadata_id = trans.security.decode_id(
                repository_metadata_id)
            log.debug('Cannot locate repository_metadata with id %s' %
                      str(decoded_repository_metadata_id))
            return {}
        else:
            decoded_repository_metadata_id = repository_metadata.id
        flush_needed = False
        for key, new_value in payload.items():
            if key == 'time_last_tested':
                repository_metadata.time_last_tested = datetime.datetime.utcnow(
                )
                flush_needed = True
            elif hasattr(repository_metadata, key):
                # log information when setting attributes associated with the Tool Shed's install and test framework.
                if key in [
                        'do_not_test', 'includes_tools',
                        'missing_test_components', 'test_install_error',
                        'tools_functionally_correct'
                ]:
                    log.debug(
                        'Setting repository_metadata column %s to value %s for changeset_revision %s via the Tool Shed API.'
                        % (str(key), str(new_value),
                           str(repository_metadata.changeset_revision)))
                setattr(repository_metadata, key, new_value)
                flush_needed = True
        if flush_needed:
            log.debug(
                'Updating repository_metadata record with id %s and changeset_revision %s.'
                % (str(decoded_repository_metadata_id),
                   str(repository_metadata.changeset_revision)))
            trans.sa_session.add(repository_metadata)
            trans.sa_session.flush()
            trans.sa_session.refresh(repository_metadata)
        repository_metadata_dict = repository_metadata.to_dict(
            view='element', value_mapper=self.__get_value_mapper(trans))
        repository_metadata_dict['url'] = web.url_for(
            controller='repository_revisions',
            action='show',
            id=repository_metadata_id)
        return repository_metadata_dict