Improve some random tool shed code.

This commit is contained in:
John Chilton
2015-12-18 08:53:49 +00:00
parent b5ad20401b
commit 536b4e2a20
2 changed files with 16 additions and 12 deletions
+15
View File
@@ -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.).
+1 -12
View File
@@ -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={} ):