Apply patch from Brad Chapman that fixes an issue when downloading a zip archive of library datasets. Also include some miscellansous imporvements and code cleanup related to changes made in change set 4964:82107691d26e.

This commit is contained in:
Greg Von Kuster
2011-02-01 11:21:41 -05:00
parent 5c431752bb
commit e8e6753c47
10 changed files with 84 additions and 88 deletions
+17 -1
View File
@@ -1,7 +1,7 @@
"""
A simple wrapper for writing tarballs as a stream.
"""
import os
import logging, tarfile
log = logging.getLogger( __name__ )
@@ -26,3 +26,19 @@ class StreamBall( object ):
tf.add( file, arcname=rel )
tf.close()
return []
class ZipBall(object):
def __init__(self, tmpf, tmpd):
self._tmpf = tmpf
self._tmpd = tmpd
def stream(self, environ, start_response):
response_write = start_response( self.wsgi_status, self.wsgi_headeritems )
tmpfh = open( self._tmpf )
response_write(tmpfh.read())
tmpfh.close()
try:
os.unlink( self._tmpf )
os.rmdir( self._tmpd )
except OSError:
log.exception( "Unable to remove temporary library download archive and directory" )
return []
+1 -1
View File
@@ -35,7 +35,7 @@ class LibraryListGrid( grids.Grid ):
attach_popup=False,
filterable="advanced" ),
]
columns.append( grids.MulticolFilterColumn( "search library dataset name, info, message, dbkey",
columns.append( grids.MulticolFilterColumn( "search dataset name, info, message, dbkey",
cols_to_filter=[ columns[0], columns[1] ],
key="free-text-search",
visible=False,
+1 -1
View File
@@ -50,7 +50,7 @@ class LibraryListGrid( grids.Grid ):
# Columns that are valid for filtering but are not visible.
grids.DeletedColumn( "Deleted", key="deleted", visible=False, filterable="advanced" )
]
columns.append( grids.MulticolFilterColumn( "search library dataset name, info, message, dbkey",
columns.append( grids.MulticolFilterColumn( "search dataset name, info, message, dbkey",
cols_to_filter=[ columns[0], columns[1] ],
key="free-text-search",
visible=False,
+12 -20
View File
@@ -1706,20 +1706,12 @@ class LibraryCommon( BaseController, UsesFormDefinitions ):
fname = lname.replace( ' ', '_' ) + '_files'
if action == 'zip':
archive.close()
tmpfh = open( tmpf )
# clean up now
try:
os.unlink( tmpf )
os.rmdir( tmpd )
except OSError:
error = True
log.exception( "Unable to remove temporary library download archive and directory" )
message = "Unable to create archive for download, please report this error"
status = 'error'
if not error:
trans.response.set_content_type( "application/x-zip-compressed" )
trans.response.headers[ "Content-Disposition" ] = "attachment; filename=%s.%s" % (fname,outext)
return tmpfh
trans.response.set_content_type( "application/x-zip-compressed" )
trans.response.headers[ "Content-Disposition" ] = "attachment; filename=%s.%s" % (fname,outext)
archive = util.streamball.ZipBall(tmpf, tmpd)
archive.wsgi_status = trans.response.wsgi_status()
archive.wsgi_headeritems = trans.response.wsgi_headeritems()
return archive.stream
elif action == 'ngxzip':
trans.response.set_content_type( "application/zip" )
trans.response.headers[ "Content-Disposition" ] = "attachment; filename=%s.%s" % (fname,outext)
@@ -1831,11 +1823,11 @@ class LibraryCommon( BaseController, UsesFormDefinitions ):
hist_names_str = ", ".join( [ target_history.name for target_history in target_histories ] )
num_source = len( ldda_ids ) - invalid_datasets
num_target = len( target_histories )
message = "%i %s have been imported into %i %s: %s" % ( num_source,
inflector.cond_plural( num_source, "dataset" ),
num_target,
inflector.cond_plural( num_target, "history" ),
hist_names_str )
message = "%i %s imported into %i %s: %s" % ( num_source,
inflector.cond_plural( num_source, "dataset" ),
num_target,
inflector.cond_plural( num_target, "history" ),
hist_names_str )
trans.sa_session.refresh( current_history )
current_user_roles = trans.get_current_user_roles()
source_lddas = []
@@ -2240,7 +2232,7 @@ def whoosh_search( trans, cntrller, search_term, **kwd ):
# Perform search
parser = MultifieldParser( [ 'name', 'info', 'dbkey', 'message' ], schema=schema )
# Search term with wildcards may be slow...
results = searcher.search( parser.parse( '*' + search_term + '*' ), minscore=0.1 )
results = searcher.search( parser.parse( '*' + search_term + '*' ), minscore=0.5 )
ldda_ids = [ result[ 'id' ] for result in results ]
lddas = []
for ldda_id in ldda_ids:
+4 -1
View File
@@ -63,7 +63,10 @@ def get_lddas( sa_session ):
else:
info = ''
dbkey = ldda.metadata.dbkey
message = ldda.message
if ldda.message:
message = ldda.message
else:
message = ''
yield id, name, info, dbkey, message
def get_sa_session_and_needed_config_settings( ini_file ):
+3 -30
View File
@@ -1,6 +1,7 @@
<%namespace file="/message.mako" import="render_msg" />
<%namespace file="/library/common/library_item_info.mako" import="render_library_item_info" />
<%namespace file="/library/common/common.mako" import="render_actions_on_multiple_items" />
<%namespace file="/library/common/common.mako" import="render_compression_types_help" />
<%namespace file="/library/common/common.mako" import="common_javascripts" />
<%!
@@ -564,34 +565,6 @@
</script>
<!-- running: do not change this comment, used by TwillTestCase.library_wait -->
%endif
## Help about compression types
<div class="libraryItemBody">
<p class="infomark">
TIP: You can download individual library files by selecting "Download this dataset" from the context menu (triangle) next to the dataset's name.
</p>
</div>
%if len( comptypes ) > 1:
<div class="libraryItemBody">
<p class="infomark">
TIP: Multiple compression options are available for downloading library datasets:
</p>
<ul style="padding-left: 1em; list-style-type: disc;">
%if 'gz' in comptypes:
<li>gzip: Recommended for fast network connections
%if trans.app.config.upstream_gzip:
NOTE: The file you receive will be an uncompressed .tar file - this is because the Galaxy server compresses it and your browser decompresses it on the fly.
%endif
</li>
%endif
%if 'bz2' in comptypes:
<li>bzip2: Recommended for slower network connections (smaller size but takes longer to compress)</li>
%endif
%if 'zip' in comptypes:
<li>zip: Not recommended but is provided as an option for those who cannot open the above formats</li>
%endif
</ul>
</div>
%endif
${render_compression_types_help( comptypes )}
</%def>
+30
View File
@@ -43,6 +43,36 @@
</script>
</%def>
<%def name="render_compression_types_help( comptypes )">
<div class="libraryItemBody">
<p class="infomark">
TIP: You can download individual library datasets by selecting "Download this dataset" from the context menu (triangle) next to each dataset's name.
</p>
</div>
%if len( comptypes ) > 1:
<div class="libraryItemBody">
<p class="infomark">
TIP: Several compression options are available for downloading multiple library datasets simultaneously:
</p>
<ul style="padding-left: 1em; list-style-type: disc;">
%if 'gz' in comptypes:
<li>gzip: Recommended for fast network connections
%if trans.app.config.upstream_gzip:
NOTE: The file you receive will be an uncompressed .tar file - this is because the Galaxy server compresses it and your browser decompresses it on the fly.
%endif
</li>
%endif
%if 'bz2' in comptypes:
<li>bzip2: Recommended for slower network connections (smaller size but takes longer to compress)</li>
%endif
%if 'zip' in comptypes:
<li>zip: Not recommended but is provided as an option for those who cannot open the above formats</li>
%endif
</ul>
</div>
%endif
</%def>
<%def name="render_upload_form( cntrller, upload_option, action, library_id, folder_id, replace_dataset, file_formats, dbkeys, space_to_tab, link_data_only, widgets, roles_select_list, history, show_deleted )">
<%
import os, os.path
@@ -58,8 +58,14 @@ ${h.js( "jquery", "galaxy.base" )}
<select id="single-dest-select" name="target_history_ids">
<option value=""></option>
%for i, target_history in enumerate( target_histories ):
<% encoded_id = trans.security.encode_id( target_history.id ) %>
<option value="${encoded_id}">${i + 1}: ${h.truncate( target_history.name, 30 )}</option>
<%
encoded_id = trans.security.encode_id( target_history.id )
if target_history == current_history:
current_history_text = " (current history)"
else:
current_history_text = ""
%>
<option value="${encoded_id}">${i + 1}: ${h.truncate( target_history.name, 30 )}${current_history_text}</option>
%endfor
</select>
<br/><br/>
@@ -68,12 +74,15 @@ ${h.js( "jquery", "galaxy.base" )}
<div id="multiple-destination" style="display: none;">
%for i, target_history in enumerate( target_histories ):
<%
cur_history_text = ""
encoded_id = trans.security.encode_id( target_history.id )
if target_history == current_history:
current_history_text = " (current history)"
else:
current_history_text = ""
%>
<div class="form-row">
<input type="checkbox" name="target_history_ids" id="target_history_${encoded_id}" value="${encoded_id}"/>
<label for="target_history_${encoded_id}" style="display: inline; font-weight:normal;">${i + 1}: ${target_history.name}${cur_history_text}</label>
<label for="target_history_${encoded_id}" style="display: inline; font-weight:normal;">${i + 1}: ${target_history.name}${current_history_text}</label>
</div>
%endfor
</div>
@@ -1,6 +1,7 @@
<%namespace file="/message.mako" import="render_msg" />
<%namespace file="/library/common/browse_library.mako" import="render_dataset" />
<%namespace file="/library/common/common.mako" import="render_actions_on_multiple_items" />
<%namespace file="/library/common/common.mako" import="render_compression_types_help" />
<%namespace file="/library/common/common.mako" import="common_javascripts" />
<%!
@@ -127,35 +128,7 @@
${render_actions_on_multiple_items( actions_to_exclude=[ 'manage_permissions' ] )}
</table>
</form>
## Help about compression types
<div class="libraryItemBody">
<p class="infomark">
TIP: You can download individual library files by selecting "Download this dataset" from the context menu (triangle) next to the dataset's name.
</p>
</div>
%if len( comptypes ) > 1:
<div class="libraryItemBody">
<p class="infomark">
TIP: Multiple compression options are available for downloading library datasets:
</p>
<ul style="padding-left: 1em; list-style-type: disc;">
%if 'gz' in comptypes:
<li>gzip: Recommended for fast network connections
%if trans.app.config.upstream_gzip:
NOTE: The file you receive will be an uncompressed .tar file - this is because the Galaxy server compresses it and your browser decompresses it on the fly.
%endif
</li>
%endif
%if 'bz2' in comptypes:
<li>bzip2: Recommended for slower network connections (smaller size but takes longer to compress)</li>
%endif
%if 'zip' in comptypes:
<li>zip: Not recommended but is provided as an option for those who cannot open the above formats</li>
%endif
</ul>
</div>
%endif
${render_compression_types_help( comptypes )}
%elif status != 'error':
<p>The string "${search_term}" was not found in any of the following information components for any library datasets that you can access.</p>
${render_searched_components()}
+1 -1
View File
@@ -300,7 +300,7 @@ class TestLibrarySecurity( TwillTestCase ):
library_id=self.security.encode_id( library1.id ),
ldda_ids=self.security.encode_id( ldda2.id ),
new_history_name='goodbye',
strings_displayed=[ '1 dataset have been imported into 1 history' ] )
strings_displayed=[ '1 dataset imported into 1 history' ] )
self.logout()
# regular_user2 should not be able to see ldda2
self.login( email=regular_user2.email )