diff options
-rw-r--r-- | lib/spack/spack/globals.py | 14 | ||||
-rw-r--r-- | lib/spack/spack/package.py | 8 | ||||
-rw-r--r-- | lib/spack/spack/packages/libelf.py | 16 | ||||
-rw-r--r-- | lib/spack/spack/stage.py | 58 | ||||
-rw-r--r-- | lib/spack/spack/test/stage.py | 12 |
5 files changed, 69 insertions, 39 deletions
diff --git a/lib/spack/spack/globals.py b/lib/spack/spack/globals.py index 4da516803f..ad0fc3df58 100644 --- a/lib/spack/spack/globals.py +++ b/lib/spack/spack/globals.py @@ -104,6 +104,20 @@ do_checksum = True # sys_type = None +# +# Places to download tarballs from. Examples: +# +# For a local directory: +# mirrors = ['file:///Users/gamblin2/spack-mirror'] +# +# For a website: +# mirrors = ['http://spackports.org/spack-mirror/'] +# +# For no mirrors: +# mirrors = [] +# +mirrors = [] + # Important environment variables SPACK_NO_PARALLEL_MAKE = 'SPACK_NO_PARALLEL_MAKE' SPACK_LIB = 'SPACK_LIB' diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py index 2ea367fdc9..db1ff92a5b 100644 --- a/lib/spack/spack/package.py +++ b/lib/spack/spack/package.py @@ -389,7 +389,10 @@ class Package(object): raise ValueError("Can only get a stage for a concrete package.") if self._stage is None: - self._stage = Stage(self.url, str(self.spec)) + mirror_path="%s/%s-%s.tar.gz" % ( + self.name, self.name, self.version) + self._stage = Stage( + self.url, mirror_path=mirror_path, name=str(self.spec)) return self._stage @@ -688,7 +691,8 @@ class Package(object): def install(self, spec, prefix): """Package implementations override this with their own build configuration.""" - tty.die("Packages must provide an install method!") + configure() + #tty.die("Packages must provide an install method!") def do_uninstall(self): diff --git a/lib/spack/spack/packages/libelf.py b/lib/spack/spack/packages/libelf.py index f663ba750d..abfbd0bde7 100644 --- a/lib/spack/spack/packages/libelf.py +++ b/lib/spack/spack/packages/libelf.py @@ -36,12 +36,12 @@ class Libelf(Package): versions = { '0.8.13' : '4136d7b4c04df68b686570afa26988ac', '0.8.12' : 'e21f8273d9f5f6d43a59878dc274fec7', } - def install(self, spec, prefix): - configure("--prefix=" + prefix, - "--enable-shared", - "--disable-dependency-tracking", - "--disable-debug") - make() + # def install(self, spec, prefix): + # configure("--prefix=" + prefix, + # "--enable-shared", + # "--disable-dependency-tracking", + # "--disable-debug") + # make() - # The mkdir commands in libelf's install can fail in parallel - make("install", parallel=False) + # # The mkdir commands in libelf's install can fail in parallel + # make("install", parallel=False) diff --git a/lib/spack/spack/stage.py b/lib/spack/spack/stage.py index 6c303d6824..b4f9c21184 100644 --- a/lib/spack/spack/stage.py +++ b/lib/spack/spack/stage.py @@ -65,7 +65,7 @@ class Stage(object): similar, and are intended to persist for only one run of spack. """ - def __init__(self, url, name=None): + def __init__(self, url, **kwargs): """Create a stage object. Parameters: url URL of the archive to be downloaded into this stage. @@ -75,9 +75,11 @@ class Stage(object): stage object later). If name is not provided, then this stage will be given a unique name automatically. """ + self.name = kwargs.get('name') + self.mirror_path = kwargs.get('mirror_path') + self.tmp_root = find_tmp_root() self.url = url - self.name = name self.path = None # This will be set after setup is called. @@ -210,6 +212,30 @@ class Stage(object): tty.die("Setup failed: no such directory: " + self.path) + def fetch_from_url(self, url): + try: + # Run curl but grab the mime type from the http headers + headers = spack.curl('-#', # status bar + '-O', # save file to disk + '-D', '-', # print out HTML headers + '-L', url, return_output=True) + except: + # clean up archive on failure. + if self.archive_file: + os.remove(self.archive_file) + raise + + # Check if we somehow got an HTML file rather than the archive we + # asked for. We only look at the last content type, to handle + # redirects properly. + content_types = re.findall(r'Content-Type:[^\r\n]+', headers) + if content_types and 'text/html' in content_types[-1]: + tty.warn("The contents of " + self.archive_file + " look like HTML.", + "The checksum will likely be bad. If it is, you can use", + "'spack clean --all' to remove the bad archive, then fix", + "your internet gateway issue and install again.") + + def fetch(self): """Downloads the file at URL to the stage. Returns true if it was downloaded, false if it already existed.""" @@ -218,29 +244,15 @@ class Stage(object): tty.msg("Already downloaded %s." % self.archive_file) else: - tty.msg("Fetching %s" % self.url) + urls = [self.url] + if self.mirror_path: + urls += ["%s/%s" % (m, self.mirror_path) for m in spack.mirrors] - try: - # Run curl but grab the mime type from the http headers - headers = spack.curl('-#', # status bar - '-O', # save file to disk - '-D', '-', # print out HTML headers - '-L', self.url, return_output=True) - except: - # clean up archive on failure. + for url in urls: + tty.msg("Trying to fetch from %s" % url) + self.fetch_from_url(url) if self.archive_file: - os.remove(self.archive_file) - raise - - # Check if we somehow got an HTML file rather than the archive we - # asked for. We only look at the last content type, to handle - # redirects properly. - content_types = re.findall(r'Content-Type:[^\r\n]+', headers) - if content_types and 'text/html' in content_types[-1]: - tty.warn("The contents of " + self.archive_file + " look like HTML.", - "The checksum will likely be bad. If it is, you can use", - "'spack clean --all' to remove the bad archive, then fix", - "your internet gateway issue and install again.") + break if not self.archive_file: raise FailedDownloadError(url) diff --git a/lib/spack/spack/test/stage.py b/lib/spack/spack/test/stage.py index 0b572950ad..942baf6d46 100644 --- a/lib/spack/spack/test/stage.py +++ b/lib/spack/spack/test/stage.py @@ -189,7 +189,7 @@ class StageTest(unittest.TestCase): def checkSetupAndDestroy(self, stage_name=None): - stage = Stage(archive_url, stage_name) + stage = Stage(archive_url, name=stage_name) stage.setup() self.check_setup(stage, stage_name) @@ -218,7 +218,7 @@ class StageTest(unittest.TestCase): def test_chdir(self): - stage = Stage(archive_url, stage_name) + stage = Stage(archive_url, name=stage_name) stage.chdir() self.check_setup(stage, stage_name) @@ -229,7 +229,7 @@ class StageTest(unittest.TestCase): def test_fetch(self): - stage = Stage(archive_url, stage_name) + stage = Stage(archive_url, name=stage_name) stage.fetch() self.check_setup(stage, stage_name) @@ -241,7 +241,7 @@ class StageTest(unittest.TestCase): def test_expand_archive(self): - stage = Stage(archive_url, stage_name) + stage = Stage(archive_url, name=stage_name) stage.fetch() self.check_setup(stage, stage_name) @@ -255,7 +255,7 @@ class StageTest(unittest.TestCase): def test_expand_archive(self): - stage = Stage(archive_url, stage_name) + stage = Stage(archive_url, name=stage_name) stage.fetch() self.check_setup(stage, stage_name) @@ -271,7 +271,7 @@ class StageTest(unittest.TestCase): def test_restage(self): - stage = Stage(archive_url, stage_name) + stage = Stage(archive_url, name=stage_name) stage.fetch() stage.expand_archive() |