diff options
author | Todd Gamblin <tgamblin@llnl.gov> | 2013-11-23 21:01:07 -0800 |
---|---|---|
committer | Todd Gamblin <tgamblin@llnl.gov> | 2013-11-23 21:01:07 -0800 |
commit | 3de3efc75d2687bdb1f92ccdf96a2805a8fd8043 (patch) | |
tree | c93a588431c5184a75cf91aaf99df7c518615bcb /lib | |
parent | 1247036141c1d063f3abd448bb4877659d979bf1 (diff) | |
download | spack-3de3efc75d2687bdb1f92ccdf96a2805a8fd8043.tar.gz spack-3de3efc75d2687bdb1f92ccdf96a2805a8fd8043.tar.bz2 spack-3de3efc75d2687bdb1f92ccdf96a2805a8fd8043.tar.xz spack-3de3efc75d2687bdb1f92ccdf96a2805a8fd8043.zip |
Gracefully handle lack of network connection.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/error.py | 7 | ||||
-rw-r--r-- | lib/spack/spack/package.py | 36 | ||||
-rw-r--r-- | lib/spack/spack/util/web.py | 7 |
3 files changed, 31 insertions, 19 deletions
diff --git a/lib/spack/spack/error.py b/lib/spack/spack/error.py index 3c3c3dafc9..ac069c6b7d 100644 --- a/lib/spack/spack/error.py +++ b/lib/spack/spack/error.py @@ -11,3 +11,10 @@ class UnsupportedPlatformError(SpackError): """Raised by packages when a platform is not supported""" def __init__(self, message): super(UnsupportedPlatformError, self).__init__(message) + + +class NoNetworkConnectionError(SpackError): + """Raised when an operation needs an internet connection.""" + def __init__(self, message, url): + super(NoNetworkConnectionError, self).__init__(message) + self.url = url diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py index 59ce6afd7e..8cbb3f0eaf 100644 --- a/lib/spack/spack/package.py +++ b/lib/spack/spack/package.py @@ -664,21 +664,27 @@ class Package(object): url_regex = os.path.basename(url.wildcard_version(self.url)) wildcard = self.version.wildcard() - page_map = get_pages(self.list_url, depth=self.list_depth) - for site, page in page_map.iteritems(): - strings = re.findall(url_regex, page) - - for s in strings: - match = re.search(wildcard, s) - if match: - v = match.group(0) - self._available_versions.add(Version(v)) - - if not self._available_versions: - tty.warn("Found no versions for %s" % self.name, - "Check the list_url and list_depth attribute on the " - + self.name + " package.", - "Use them to tell Spack where to look for versions.") + try: + page_map = get_pages(self.list_url, depth=self.list_depth) + + for site, page in page_map.iteritems(): + strings = re.findall(url_regex, page) + + for s in strings: + match = re.search(wildcard, s) + if match: + v = match.group(0) + self._available_versions.add(Version(v)) + + if not self._available_versions: + tty.warn("Found no versions for %s" % self.name, + "Check the list_url and list_depth attribute on the " + + self.name + " package.", + "Use them to tell Spack where to look for versions.") + + except spack.error.NoNetworkConnectionError, e: + tty.die("Package.fetch_available_versions couldn't connect to:", + e.url, e.message) return self._available_versions diff --git a/lib/spack/spack/util/web.py b/lib/spack/spack/util/web.py index 32ffe6dbbe..e867c65ce1 100644 --- a/lib/spack/spack/util/web.py +++ b/lib/spack/spack/util/web.py @@ -6,6 +6,7 @@ from multiprocessing import Pool from HTMLParser import HTMLParser import spack +import spack.error import spack.tty as tty from spack.util.compression import ALLOWED_ARCHIVE_TYPES @@ -90,12 +91,10 @@ def _spider(args): for d in dicts: pages.update(d) - except urllib2.HTTPError, e: + except urllib2.URLError, e: # Only report it if it's the root page. We ignore errors when spidering. if depth == 1: - tty.warn("Could not connect to %s" % url, e.reason, - "Package.available_versions requires an internet connection.", - "Version list may be incomplete.") + raise spack.error.NoNetworkConnectionError(e.reason, url) return pages |