Allow downloading index files via tool data API.

This provides direct access to the files to admins - probably still wise to provide some mechanism to download a copressed archive of these files.
This commit is contained in:
John Chilton
2014-12-15 00:20:35 -05:00
parent 4262ff7673
commit 8536ca4315
3 changed files with 20 additions and 0 deletions
@@ -1,6 +1,9 @@
import os
from galaxy import exceptions
from galaxy import web
from galaxy.web import _future_expose_api as expose_api
from galaxy.web import _future_expose_api_raw as expose_api_raw
from galaxy.web.base.controller import BaseAPIController
@@ -74,6 +77,16 @@ class ToolData( BaseAPIController ):
"""
return self._data_table_field( id, value ).to_dict()
@web.require_admin
@expose_api_raw
def download_field_file( self, trans, id, value, path, **kwds ):
field_value = self._data_table_field( id, value )
base_dir = field_value.get_base_dir()
full_path = os.path.join( base_dir, path )
if full_path not in field_value.get_files():
raise exceptions.ObjectNotFound("No such path in data table field.")
return open(full_path, "r")
def _data_table_field( self, id, value ):
out = self._data_table(id).get_field(value)
if out is None:
+1
View File
@@ -171,6 +171,7 @@ def populate_api_routes( webapp, app ):
webapp.mapper.resource( 'dataset', 'datasets', path_prefix='/api' )
webapp.mapper.resource( 'tool_data', 'tool_data', path_prefix='/api' )
webapp.mapper.connect( '/api/tool_data/{id:.+?}/fields/{value:.+?}/files/{path:.+?}', action='download_field_file', controller="tool_data" )
webapp.mapper.connect( '/api/tool_data/{id:.+?}/fields/{value:.+?}', action='show_field', controller="tool_data" )
webapp.mapper.resource( 'dataset_collection', 'dataset_collections', path_prefix='/api/')
webapp.mapper.resource( 'sample', 'samples', path_prefix='/api' )
+6
View File
@@ -36,3 +36,9 @@ class ToolDataApiTestCase( api.ApiTestCase ):
self._assert_has_keys( field, "files", "name", "fields", "fingerprint", "base_dir" )
files = field[ "files" ]
assert len( files ) == 2
def test_download_field_file(self):
show_field_response = self._get( "tool_data/testalpha/fields/data1/files/entry.txt", admin=True )
self._assert_status_code_is( show_field_response, 200 )
content = show_field_response.content
assert content == "This is data 1.", content