Add support for URLs with query strings

- support tarballs from raw github URLs
This commit is contained in:
Todd Gamblin 2014-12-09 01:07:48 -08:00
parent c3fce7b77f
commit e309b41972

View file

@ -47,7 +47,9 @@
import os import os
import re import re
from StringIO import StringIO from StringIO import StringIO
from urlparse import urlsplit, urlunsplit
import llnl.util.tty as tty
from llnl.util.tty.color import * from llnl.util.tty.color import *
import spack.error import spack.error
@ -80,6 +82,19 @@ def find_list_url(url):
return os.path.dirname(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): def parse_version_offset(path):
"""Try to extract a version string from a filename or URL. This is taken """Try to extract a version string from a filename or URL. This is taken
largely from Homebrew's Version class.""" 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): if re.search(r'((?:sourceforge.net|sf.net)/.*)/download$', path):
path = os.path.dirname(path) path = os.path.dirname(path)
# Remove trailing ?... from URL
path, stripped = strip_url(path)
# Strip archive extension # Strip archive extension
path = comp.strip_extension(path) path = comp.strip_extension(path)
@ -187,6 +205,9 @@ def parse_name_offset(path, v=None):
if v is None: if v is None:
v = parse_version(path) v = parse_version(path)
# Remove trailing ?... from URL
path, stripped = strip_url(path)
# Strip archive extension # Strip archive extension
path = comp.strip_extension(path) path = comp.strip_extension(path)
@ -303,6 +324,9 @@ def wildcard_version(path):
# Get name and version, so we can treat them specially # Get name and version, so we can treat them specially
name, v = parse_name_and_version(path) name, v = parse_name_and_version(path)
# strip URL query/fragment first.
path, query = strip_url(path)
# protect extensions like bz2 from wildcarding. # protect extensions like bz2 from wildcarding.
ext = comp.extension(path) ext = comp.extension(path)
path = comp.strip_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) name_parts[i] = vgroup.join(re.escape(vp) for vp in vparts)
# Put it all back together with original name matches intact. # 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): def substitute_version(path, new_version):