summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2014-12-09 01:07:48 -0800
committerTodd Gamblin <tgamblin@llnl.gov>2014-12-09 01:07:48 -0800
commite309b41972b6fd2cf9dd96e53db626694b6b7c35 (patch)
treed2e9fbff02f0c356e6962eac1af21fcda27d57ad /lib
parentc3fce7b77fe895307c78676a2692757002199399 (diff)
downloadspack-e309b41972b6fd2cf9dd96e53db626694b6b7c35.tar.gz
spack-e309b41972b6fd2cf9dd96e53db626694b6b7c35.tar.bz2
spack-e309b41972b6fd2cf9dd96e53db626694b6b7c35.tar.xz
spack-e309b41972b6fd2cf9dd96e53db626694b6b7c35.zip
Add support for URLs with query strings
- support tarballs from raw github URLs
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/url.py26
1 files changed, 25 insertions, 1 deletions
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):