From 536b4e2a2038d889486bbf0836341e03d737f53c Mon Sep 17 00:00:00 2001 From: John Chilton Date: Wed, 16 Dec 2015 22:30:13 +0000 Subject: [PATCH] Improve some random tool shed code. --- lib/galaxy/util/__init__.py | 15 +++++++++++++++ lib/tool_shed/util/common_util.py | 13 +------------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/lib/galaxy/util/__init__.py b/lib/galaxy/util/__init__.py index 3335bb1b23c..f6215215f81 100644 --- a/lib/galaxy/util/__init__.py +++ b/lib/galaxy/util/__init__.py @@ -58,6 +58,21 @@ NULL_CHAR = '\000' BINARY_CHARS = [ NULL_CHAR ] +def remove_protocol_from_url( url ): + """ Supplied URL may be null, if not ensure http:// or https:// + etc... is stripped off. + """ + if url is None: + return url + + # We have a URL + if url.find( '://' ) > 0: + new_url = url.split( '://' )[1] + else: + new_url = url + return new_url.rstrip( '/' ) + + def is_binary( value, binary_chars=None ): """ File is binary if it contains a null-byte by default (e.g. behavior of grep, etc.). diff --git a/lib/tool_shed/util/common_util.py b/lib/tool_shed/util/common_util.py index d0286e8631b..091235c4d71 100644 --- a/lib/tool_shed/util/common_util.py +++ b/lib/tool_shed/util/common_util.py @@ -337,18 +337,7 @@ def remove_protocol_and_user_from_clone_url( repository_clone_url ): def remove_protocol_from_tool_shed_url( tool_shed_url ): """Return a partial Tool Shed URL, eliminating the protocol if it exists.""" - try: - if tool_shed_url.find( '://' ) > 0: - new_tool_shed_url = tool_shed_url.split( '://' )[1] - else: - new_tool_shed_url = tool_shed_url - return new_tool_shed_url.rstrip( '/' ) - except Exception, e: - # We receive a lot of calls here where the tool_shed_url is None. The container_util uses - # that value when creating a header row. If the tool_shed_url is not None, we have a problem. - if tool_shed_url is not None: - log.exception( "Handled exception removing the protocol from Tool Shed URL %s:\n%s", str( tool_shed_url ), e ) - return tool_shed_url + return util.remove_protocol_from_url( tool_shed_url ) def tool_shed_get( app, base_url, pathspec=[], params={} ):