1 new changeset in galaxy-central: http://bitbucket.org/galaxy/galaxy-central/changeset/1119959f40cc/ changeset: 1119959f40cc branches: user: greg date: 2011-06-07 17:06:50 summary: Add the ability to download repository files in tar.gz, tar.bz2 or zip format from the tool shed. affected #: 8 files (4.6 KB) --- a/lib/galaxy/webapps/community/controllers/repository.py Tue Jun 07 10:46:52 2011 -0400 +++ b/lib/galaxy/webapps/community/controllers/repository.py Tue Jun 07 11:06:50 2011 -0400 @@ -611,6 +611,23 @@ rra=rra, message=message, status=status ) + @web.expose + def download( self, trans, repository_id, file_type, **kwd ): + # Download an archive of the repository files compressed as zip, gz or bz2. + params = util.Params( kwd ) + repository = get_repository( trans, repository_id ) + # Allow hgweb to handle the download. This requires the tool shed + # server account's .hgrc file to include the following setting: + # [web] + # allow_archive = bz2, gz, zip + if file_type == 'zip': + file_type_str = 'tip.zip' + elif file_type == 'bz2': + file_type_str = 'tip.tar.bz2' + elif file_type == 'gz': + file_type_str = 'tip.tar.gz' + download_url = '/repos/%s/%s/archive/%s' % ( repository.user.username, repository.name, file_type_str ) + return trans.response.send_redirect( download_url ) @web.json def open_folder( self, trans, repository_id, key ): # TODO: The tool shed includes a repository source file browser, which currently depends upon --- a/lib/galaxy/webapps/community/controllers/upload.py Tue Jun 07 10:46:52 2011 -0400 +++ b/lib/galaxy/webapps/community/controllers/upload.py Tue Jun 07 11:06:50 2011 -0400 @@ -119,11 +119,12 @@ repo.dirstate.add( file_path ) files_to_commit.append( file_path ) else: - # We're uploading files to a repository with existing - # contents, so clone the repository to a temporary location. - tmp_dir, cloned_repo_dir = self.__handle_hg_clone( trans, repository, upload_point, uploaded_file, file_data, repo_dir, current_working_dir, istar, tar=tar ) + # Clone the repository to a temporary location. + tmp_dir, cloned_repo_dir = self.__hg_clone( trans, repository, repo_dir, current_working_dir ) + # Move the uploaded files to the upload_point within the cloned repository. + self.__move_to_upload_point( upload_point, uploaded_file, file_data, cloned_repo_dir, istar, tar ) # Commit and push the changes from the cloned repo to the master repo. - self.__handle_hg_push( trans, repository, file_data, commit_message, current_working_dir, cloned_repo_dir, repo_dir, tmp_dir ) + self.__hg_push( trans, repository, file_data, commit_message, current_working_dir, cloned_repo_dir, repo_dir, tmp_dir ) if ok: if files_to_commit: repo.dirstate.write() @@ -147,7 +148,7 @@ commit_message=commit_message, message=message, status=status ) - def __handle_hg_clone( self, trans, repository, upload_point, uploaded_file, file_data, repo_dir, current_working_dir, istar, tar=None ): + def __hg_clone( self, trans, repository, repo_dir, current_working_dir ): tmp_dir = tempfile.mkdtemp() tmp_archive_dir = os.path.join( tmp_dir, 'tmp_archive_dir' ) if not os.path.exists( tmp_archive_dir ): @@ -158,20 +159,8 @@ os.system( cmd ) os.chdir( current_working_dir ) cloned_repo_dir = os.path.join( tmp_archive_dir, 'repo_%d' % repository.id ) - if upload_point is not None: - full_path = os.path.abspath( os.path.join( cloned_repo_dir, upload_point, file_data.filename ) ) - else: - full_path = os.path.abspath( os.path.join( cloned_repo_dir, file_data.filename ) ) - if istar: - # Extract the uploaded tarball to the load_point within the cloned repository hierarchy - tar.extractall( path=full_path ) - tar.close() - uploaded_file.close() - else: - # Move the uploaded file to the load_point within the cloned repository hierarchy - shutil.move( uploaded_file.name, full_path ) return tmp_dir, cloned_repo_dir - def __handle_hg_push( self, trans, repository, file_data, commit_message, current_working_dir, cloned_repo_dir, repo_dir, tmp_dir ): + def __hg_push( self, trans, repository, file_data, commit_message, current_working_dir, cloned_repo_dir, repo_dir, tmp_dir ): # We want these change sets to be associated with the owner of the repository, so we'll # set the HGUSER environment variable accordingly. os.environ[ 'HGUSER' ] = trans.user.username @@ -198,6 +187,19 @@ action='browse_repository', message=message, id=trans.security.encode_id( repository.id ) ) ) + def __move_to_upload_point( self, upload_point, uploaded_file, file_data, cloned_repo_dir, istar, tar ): + if upload_point is not None: + full_path = os.path.abspath( os.path.join( cloned_repo_dir, upload_point, file_data.filename ) ) + else: + full_path = os.path.abspath( os.path.join( cloned_repo_dir, file_data.filename ) ) + if istar: + # Extract the uploaded tarball to the load_point within the cloned repository hierarchy + tar.extractall( path=full_path ) + tar.close() + uploaded_file.close() + else: + # Move the uploaded file to the load_point within the cloned repository hierarchy + shutil.move( uploaded_file.name, full_path ) def __check_archive( self, archive ): for member in archive.getmembers(): # Allow regular files and directories only --- a/templates/webapps/community/repository/browse_repository.mako Tue Jun 07 10:46:52 2011 -0400 +++ b/templates/webapps/community/repository/browse_repository.mako Tue Jun 07 11:06:50 2011 -0400 @@ -79,6 +79,9 @@ %if can_rate: <a class="action-button" href="${h.url_for( controller='repository', action='rate_repository', id=trans.app.security.encode_id( repository.id ) )}">Rate repository</a> %endif + <a class="action-button" href="${h.url_for( controller='repository', action='download', repository_id=trans.app.security.encode_id( repository.id ), file_type='gz' )}">Download as a .tar.gz file</a> + <a class="action-button" href="${h.url_for( controller='repository', action='download', repository_id=trans.app.security.encode_id( repository.id ), file_type='bz2' )}">Download as a .tar.bz2 file</a> + <a class="action-button" href="${h.url_for( controller='repository', action='download', repository_id=trans.app.security.encode_id( repository.id ), file_type='zip' )}">Download as a zip file</a></div> %endif </ul> --- a/templates/webapps/community/repository/manage_repository.mako Tue Jun 07 10:46:52 2011 -0400 +++ b/templates/webapps/community/repository/manage_repository.mako Tue Jun 07 11:06:50 2011 -0400 @@ -76,6 +76,9 @@ %if can_browse_contents: <a class="action-button" href="${h.url_for( controller='repository', action='browse_repository', id=trans.app.security.encode_id( repository.id ) )}">Browse repository</a> %endif + <a class="action-button" href="${h.url_for( controller='repository', action='download', repository_id=trans.app.security.encode_id( repository.id ), file_type='gz' )}">Download as a .tar.gz file</a> + <a class="action-button" href="${h.url_for( controller='repository', action='download', repository_id=trans.app.security.encode_id( repository.id ), file_type='bz2' )}">Download as a .tar.bz2 file</a> + <a class="action-button" href="${h.url_for( controller='repository', action='download', repository_id=trans.app.security.encode_id( repository.id ), file_type='zip' )}">Download as a zip file</a></div> %endif </ul> --- a/templates/webapps/community/repository/rate_repository.mako Tue Jun 07 10:46:52 2011 -0400 +++ b/templates/webapps/community/repository/rate_repository.mako Tue Jun 07 11:06:50 2011 -0400 @@ -81,6 +81,9 @@ %if can_browse_contents: <a class="action-button" href="${h.url_for( controller='repository', action='browse_repository', id=trans.app.security.encode_id( repository.id ) )}">Browse repository</a> %endif + <a class="action-button" href="${h.url_for( controller='repository', action='download', repository_id=trans.app.security.encode_id( repository.id ), file_type='gz' )}">Download as a .tar.gz file</a> + <a class="action-button" href="${h.url_for( controller='repository', action='download', repository_id=trans.app.security.encode_id( repository.id ), file_type='bz2' )}">Download as a .tar.bz2 file</a> + <a class="action-button" href="${h.url_for( controller='repository', action='download', repository_id=trans.app.security.encode_id( repository.id ), file_type='zip' )}">Download as a zip file</a></div> %endif </ul> --- a/templates/webapps/community/repository/view_changelog.mako Tue Jun 07 10:46:52 2011 -0400 +++ b/templates/webapps/community/repository/view_changelog.mako Tue Jun 07 11:06:50 2011 -0400 @@ -50,6 +50,9 @@ %if can_browse_contents: <a class="action-button" href="${h.url_for( controller='repository', action='browse_repository', id=trans.app.security.encode_id( repository.id ) )}">Browse repository</a> %endif + <a class="action-button" href="${h.url_for( controller='repository', action='download', repository_id=trans.app.security.encode_id( repository.id ), file_type='gz' )}">Download as a .tar.gz file</a> + <a class="action-button" href="${h.url_for( controller='repository', action='download', repository_id=trans.app.security.encode_id( repository.id ), file_type='bz2' )}">Download as a .tar.bz2 file</a> + <a class="action-button" href="${h.url_for( controller='repository', action='download', repository_id=trans.app.security.encode_id( repository.id ), file_type='zip' )}">Download as a zip file</a></div></ul> --- a/templates/webapps/community/repository/view_changeset.mako Tue Jun 07 10:46:52 2011 -0400 +++ b/templates/webapps/community/repository/view_changeset.mako Tue Jun 07 11:06:50 2011 -0400 @@ -54,6 +54,9 @@ %if can_browse_contents: <a class="action-button" href="${h.url_for( controller='repository', action='browse_repository', id=trans.app.security.encode_id( repository.id ) )}">Browse repository</a> %endif + <a class="action-button" href="${h.url_for( controller='repository', action='download', repository_id=trans.app.security.encode_id( repository.id ), file_type='gz' )}">Download as a .tar.gz file</a> + <a class="action-button" href="${h.url_for( controller='repository', action='download', repository_id=trans.app.security.encode_id( repository.id ), file_type='bz2' )}">Download as a .tar.bz2 file</a> + <a class="action-button" href="${h.url_for( controller='repository', action='download', repository_id=trans.app.security.encode_id( repository.id ), file_type='zip' )}">Download as a zip file</a></div></ul> --- a/templates/webapps/community/repository/view_repository.mako Tue Jun 07 10:46:52 2011 -0400 +++ b/templates/webapps/community/repository/view_repository.mako Tue Jun 07 11:06:50 2011 -0400 @@ -76,6 +76,9 @@ %if can_browse_contents: <a class="action-button" href="${h.url_for( controller='repository', action='browse_repository', id=trans.app.security.encode_id( repository.id ) )}">Browse repository</a> %endif + <a class="action-button" href="${h.url_for( controller='repository', action='download', repository_id=trans.app.security.encode_id( repository.id ), file_type='gz' )}">Download as a .tar.gz file</a> + <a class="action-button" href="${h.url_for( controller='repository', action='download', repository_id=trans.app.security.encode_id( repository.id ), file_type='bz2' )}">Download as a .tar.bz2 file</a> + <a class="action-button" href="${h.url_for( controller='repository', action='download', repository_id=trans.app.security.encode_id( repository.id ), file_type='zip' )}">Download as a zip file</a></div> %endif </ul> Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.