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. export_repository_dependencies = util.asbool( export_repository_dependencies) # Get the repository information. repository = repository_util.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 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()
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(f'Malformed library content id ( {str(content_id)} ) specified, unable to decode.')
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( f'Cannot locate repository_metadata with id {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 hasattr(repository_metadata, key): # log information when setting attributes associated with the Tool Shed's install and test framework. if key in ['includes_tools', 'missing_test_components']: 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