From e309b41972b6fd2cf9dd96e53db626694b6b7c35 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Tue, 9 Dec 2014 01:07:48 -0800 Subject: Add support for URLs with query strings - support tarballs from raw github URLs --- lib/spack/spack/url.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/spack/spack/url.py b/lib/spack/spack/url.py index 27ef6f3b29..6b1f74a06a 100644 --- a/lib/spack/spack/url.py +++ b/lib/spack/spack/url.py @@ -47,7 +47,9 @@ it's never been told about that version before. import os import re from StringIO import StringIO +from urlparse import urlsplit, urlunsplit +import llnl.util.tty as tty from llnl.util.tty.color import * import spack.error @@ -80,6 +82,19 @@ def find_list_url(url): return os.path.dirname(url) +def strip_url(path): + """Strip query (?..) and fragment (#..) from URLs. Returns URL as two + parts: the URL and the stripped part. + """ + try: + components = urlsplit(path) + stripped = components[:3] + (None, None) + return (urlunsplit(stripped), "?%s#%s" % components[3:5]) + except ValueError: + tty.debug("Got error parsing path %s" % path) + return (path, '') # Ignore URL parse errors here + + def parse_version_offset(path): """Try to extract a version string from a filename or URL. This is taken largely from Homebrew's Version class.""" @@ -88,6 +103,9 @@ def parse_version_offset(path): if re.search(r'((?:sourceforge.net|sf.net)/.*)/download$', path): path = os.path.dirname(path) + # Remove trailing ?... from URL + path, stripped = strip_url(path) + # Strip archive extension path = comp.strip_extension(path) @@ -187,6 +205,9 @@ def parse_name_offset(path, v=None): if v is None: v = parse_version(path) + # Remove trailing ?... from URL + path, stripped = strip_url(path) + # Strip archive extension path = comp.strip_extension(path) @@ -303,6 +324,9 @@ def wildcard_version(path): # Get name and version, so we can treat them specially name, v = parse_name_and_version(path) + # strip URL query/fragment first. + path, query = strip_url(path) + # protect extensions like bz2 from wildcarding. ext = comp.extension(path) path = comp.strip_extension(path) @@ -326,7 +350,7 @@ def wildcard_version(path): name_parts[i] = vgroup.join(re.escape(vp) for vp in vparts) # Put it all back together with original name matches intact. - return ''.join(name_parts) + '.' + ext + return ''.join(name_parts) + '.' + ext + query def substitute_version(path, new_version): -- cgit v1.2.3-70-g09d2