diff --git a/lib/galaxy/webapps/community/controllers/repository.py b/lib/galaxy/webapps/community/controllers/repository.py
index 4a2ec172dc0..00eb6e57760 100644
--- a/lib/galaxy/webapps/community/controllers/repository.py
+++ b/lib/galaxy/webapps/community/controllers/repository.py
@@ -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
diff --git a/lib/galaxy/webapps/community/controllers/upload.py b/lib/galaxy/webapps/community/controllers/upload.py
index 717cf79e526..8b598213699 100644
--- a/lib/galaxy/webapps/community/controllers/upload.py
+++ b/lib/galaxy/webapps/community/controllers/upload.py
@@ -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
diff --git a/templates/webapps/community/repository/browse_repository.mako b/templates/webapps/community/repository/browse_repository.mako
index caece1c69ff..072853c66f8 100644
--- a/templates/webapps/community/repository/browse_repository.mako
+++ b/templates/webapps/community/repository/browse_repository.mako
@@ -79,6 +79,9 @@
%if can_rate:
Rate repository
%endif
+ Download as a .tar.gz file
+ Download as a .tar.bz2 file
+ Download as a zip file
%endif
diff --git a/templates/webapps/community/repository/manage_repository.mako b/templates/webapps/community/repository/manage_repository.mako
index e3850167a6b..7bdd2d40e7b 100644
--- a/templates/webapps/community/repository/manage_repository.mako
+++ b/templates/webapps/community/repository/manage_repository.mako
@@ -76,6 +76,9 @@
%if can_browse_contents:
Browse repository
%endif
+ Download as a .tar.gz file
+ Download as a .tar.bz2 file
+ Download as a zip file
%endif
diff --git a/templates/webapps/community/repository/rate_repository.mako b/templates/webapps/community/repository/rate_repository.mako
index 9e886e024e6..e67173281d2 100644
--- a/templates/webapps/community/repository/rate_repository.mako
+++ b/templates/webapps/community/repository/rate_repository.mako
@@ -81,6 +81,9 @@
%if can_browse_contents:
Browse repository
%endif
+ Download as a .tar.gz file
+ Download as a .tar.bz2 file
+ Download as a zip file
%endif
diff --git a/templates/webapps/community/repository/view_changelog.mako b/templates/webapps/community/repository/view_changelog.mako
index 547d1dac4bb..543c2db8eae 100644
--- a/templates/webapps/community/repository/view_changelog.mako
+++ b/templates/webapps/community/repository/view_changelog.mako
@@ -50,6 +50,9 @@
%if can_browse_contents:
Browse repository
%endif
+ Download as a .tar.gz file
+ Download as a .tar.bz2 file
+ Download as a zip file
diff --git a/templates/webapps/community/repository/view_changeset.mako b/templates/webapps/community/repository/view_changeset.mako
index 75e883f2043..8233e74248b 100644
--- a/templates/webapps/community/repository/view_changeset.mako
+++ b/templates/webapps/community/repository/view_changeset.mako
@@ -54,6 +54,9 @@
%if can_browse_contents:
Browse repository
%endif
+ Download as a .tar.gz file
+ Download as a .tar.bz2 file
+ Download as a zip file
diff --git a/templates/webapps/community/repository/view_repository.mako b/templates/webapps/community/repository/view_repository.mako
index d5b246f0bee..5c0e55d0268 100644
--- a/templates/webapps/community/repository/view_repository.mako
+++ b/templates/webapps/community/repository/view_repository.mako
@@ -76,6 +76,9 @@
%if can_browse_contents:
Browse repository
%endif
+ Download as a .tar.gz file
+ Download as a .tar.bz2 file
+ Download as a zip file
%endif