mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
Add the ability to download repository files in tar.gz, tar.bz2 or zip format from the tool shed.
This commit is contained in:
@@ -611,6 +611,23 @@ class RepositoryController( BaseController, ItemRatings ):
|
||||
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
|
||||
|
||||
@@ -119,11 +119,12 @@ class UploadController( BaseController ):
|
||||
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 @@ class UploadController( BaseController ):
|
||||
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 @@ class UploadController( BaseController ):
|
||||
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 @@ class UploadController( BaseController ):
|
||||
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
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user