commit/galaxy-central: greg: Persist the encoded string resulting from the information needed to install tool shed repositories if the string generates an HTTP request longer than 8177 bytes and enhance the necessary tool shed and Galaxy methods to handle this scenario.
1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/dc7d35578676/ Changeset: dc7d35578676 User: greg Date: 2013-05-12 16:47:33 Summary: Persist the encoded string resulting from the information needed to install tool shed repositories if the string generates an HTTP request longer than 8177 bytes and enhance the necessary tool shed and Galaxy methods to handle this scenario. Affected #: 2 files diff -r d09a3531b3d35a3921fdaa52beed7481f0391ca8 -r dc7d35578676935777d1f315693a4c15498919e8 lib/galaxy/webapps/tool_shed/controllers/repository.py --- a/lib/galaxy/webapps/tool_shed/controllers/repository.py +++ b/lib/galaxy/webapps/tool_shed/controllers/repository.py @@ -4,9 +4,11 @@ import re import string import tempfile +import urllib2 from time import gmtime from time import strftime -from datetime import date, datetime +from datetime import date +from datetime import datetime from galaxy import util from galaxy import web from galaxy.util.odict import odict @@ -1471,12 +1473,29 @@ repo_info_dicts=repo_info_dicts ) @web.json - def get_required_repo_info_dict( self, trans, encoded_str ): + def get_required_repo_info_dict( self, trans, encoded_str=None, **kwd ): """ Retrieve and return a dictionary that includes a list of dictionaries that each contain all of the information needed to install the list of repositories defined by the received encoded_str. """ - encoded_required_repository_str = encoding_util.tool_shed_decode( encoded_str ) + # In some cases the received encoded_str will be long. With apache, the default limit for the length of the request line is 8190 bytes + # (http://httpd.apache.org/docs/2.2/mod/core.html#limitrequestline). And if we subtract three bytes for the request method (i.e. GET), + # eight bytes for the version information (i.e. HTTP/1.0/HTTP/1.1) and two bytes for the separating space, we end up with 8177 bytes for + # the URI path plus query. The referer handles requests longer than this by persisting the encoded_str to a temporary file which we + # can read. + encoded_tmp_file_name = kwd.get( 'encoded_tmp_file_name', None ) + if encoded_str: + encoded_required_repository_str = encoding_util.tool_shed_decode( encoded_str ) + else: + # The request would have been longer than 8190 bytes if it included the encoded_str, so we'll send a request to the Galaxy instance to + # stream the string to us. + galaxy_url = suc.handle_galaxy_url( trans, **kwd ) + if galaxy_url and encoded_tmp_file_name: + url = suc.url_join( galaxy_url, '/common_install_util/stream_file_contents?encoded_tmp_file_name=%s' % encoded_tmp_file_name ) + response = urllib2.urlopen( url ) + encoded_required_repository_str = response.read() + else: + raise Exception( "Required galaxy_url or encoded_tmp_file_name request parameters missing." ) encoded_required_repository_tups = encoded_required_repository_str.split( encoding_util.encoding_sep2 ) decoded_required_repository_tups = [] for encoded_required_repository_tup in encoded_required_repository_tups: diff -r d09a3531b3d35a3921fdaa52beed7481f0391ca8 -r dc7d35578676935777d1f315693a4c15498919e8 lib/tool_shed/util/common_install_util.py --- a/lib/tool_shed/util/common_install_util.py +++ b/lib/tool_shed/util/common_install_util.py @@ -1,5 +1,6 @@ import logging import os +import tempfile from galaxy import eggs from galaxy import util from galaxy.util import json @@ -285,7 +286,43 @@ encoded_required_repository_str = encoding_util.encoding_sep2.join( encoded_required_repository_tups ) encoded_required_repository_str = encoding_util.tool_shed_encode( encoded_required_repository_str ) url = suc.url_join( tool_shed_url, '/repository/get_required_repo_info_dict?encoded_str=%s' % encoded_required_repository_str ) - text = common_util.tool_shed_get( trans.app, tool_shed_url, url ) + # In some cases the above URL will be long. With apache, the default limit for the length of the request line is 8190 bytes + # (http://httpd.apache.org/docs/2.2/mod/core.html#limitrequestline). And if we subtract three bytes for the request method + # (i.e. GET), eight bytes for the version information (i.e. HTTP/1.0/HTTP/1.1) and two bytes for the separating space, we end + # up with 8177 bytes for the URI path plus query. + if len( url ) >= 8177: + # Persist the encoded string to a temporary file. + fh = tempfile.NamedTemporaryFile( 'wb' ) + tmp_file_name = fh.name + fh.close() + fh = open( tmp_file_name, 'wb' ) + fh.write( encoded_required_repository_str ) + fh.close() + encoded_tmp_file_name = encoding_util.tool_shed_encode( os.path.abspath( tmp_file_name ) ) + # Send a request to the tool shed to enable it to read the temporary file. + url = suc.url_join( tool_shed_url, '/repository/get_required_repo_info_dict?encoded_tmp_file_name=%s' % encoded_tmp_file_name ) + else: + encoded_tmp_file_name = None + tmp_file_name = None + try: + text = common_util.tool_shed_get( trans.app, tool_shed_url, url ) + except Exception, e: + if encoded_tmp_file_name: + message = 'The selected tool shed repositories cannot be installed until the tool shed at ' + message += '%s and the Galaxy instance at %s ' % ( str( tool_shed_url ), str( trans.request.base ) ) + message += 'are both updated to at least the June 3, 2013 Galaxy release. These upgrades ' + message += 'are necessary because the number of repositories you are attemping to install ' + message += 'generates an HTTP request that is longer than 8177 bytes which cannot be handled ' + message += 'by tool shed or Galaxy instances older than this release.' + log.debug( message ) + else: + log.exception() + text = None + if tmp_file_name: + try: + os.unlink( tmp_file_name ) + except: + pass if text: required_repo_info_dict = json.from_json_string( text ) required_repo_info_dicts = [] @@ -356,3 +393,7 @@ app.model.ToolDependency.installation_status.ERROR ]: installed_tool_dependencies.append( tool_dependency ) return installed_tool_dependencies + +def stream_file_contents( trans, encoded_tmp_file_name ): + tmp_file_name = encoding_util.tool_shed_decode( encoded_tmp_file_name ) + return open( tmp_file_name ) 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.
participants (1)
-
commits-noreply@bitbucket.org