summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2014-10-07 23:26:39 -0700
committerTodd Gamblin <tgamblin@llnl.gov>2014-10-07 23:26:39 -0700
commitee23cc2527c5294aea85b571eb1c39b73da0924a (patch)
tree86ba9817dcdbfa0273b591d1f2a2e720e4f75bc2
parente8d131ef96e33b5fc7f5f7c31511d2fc9e99cb52 (diff)
downloadspack-ee23cc2527c5294aea85b571eb1c39b73da0924a.tar.gz
spack-ee23cc2527c5294aea85b571eb1c39b73da0924a.tar.bz2
spack-ee23cc2527c5294aea85b571eb1c39b73da0924a.tar.xz
spack-ee23cc2527c5294aea85b571eb1c39b73da0924a.zip
Add archive creation capability to fetch strategies.
- fetch strategy needs to know how to create archive of fetched repo - allows mirrors to be created from git/other VCS fetches.
-rw-r--r--lib/spack/spack/fetch_strategy.py52
1 files changed, 46 insertions, 6 deletions
diff --git a/lib/spack/spack/fetch_strategy.py b/lib/spack/spack/fetch_strategy.py
index 321c7fbd54..8905dc7d5f 100644
--- a/lib/spack/spack/fetch_strategy.py
+++ b/lib/spack/spack/fetch_strategy.py
@@ -50,7 +50,7 @@ import spack.util.crypto as crypto
from spack.util.executable import *
from spack.util.string import *
from spack.version import Version, ver
-from spack.util.compression import decompressor_for
+from spack.util.compression import decompressor_for, extension
"""List of all fetch strategies, created by FetchStrategy metaclass."""
all_strategies = []
@@ -81,11 +81,14 @@ class FetchStrategy(object):
# Subclasses need to implement these methods
- def fetch(self): pass # Return True on success, False on fail
- def check(self): pass
- def expand(self): pass
- def reset(self): pass
- def __str__(self):
+ def fetch(self): pass # Return True on success, False on fail.
+ def check(self): pass # Do checksum.
+ def expand(self): pass # Expand archive.
+ def reset(self): pass # Revert to freshly downloaded state.
+
+ def archive(self, destination): pass # Used to create tarball for mirror.
+
+ def __str__(self): # Should be human readable URL.
return "FetchStrategy.__str___"
# This method is used to match fetch strategies to version()
@@ -185,6 +188,14 @@ class URLFetchStrategy(FetchStrategy):
decompress(self.archive_file)
+ def archive(self, destination):
+ """This archive"""
+ if not self.archive_file:
+ raise NoArchiveFileError("Cannot call archive() before fetching.")
+ assert(extension(destination) == extension(self.archive_file))
+ shutil.move(self.archive_file, destination)
+
+
def check(self):
"""Check the downloaded archive against a checksum digest.
No-op if this stage checks code out of a repository."""
@@ -251,6 +262,23 @@ class VCSFetchStrategy(FetchStrategy):
tty.debug("Source fetched with %s is already expanded." % self.name)
+ def archive(self, destination, **kwargs):
+ assert(extension(destination) == 'tar.gz')
+ assert(self.stage.source_path.startswith(self.stage.path))
+
+ tar = which('tar', required=True)
+
+ patterns = kwargs.get('exclude', None)
+ if patterns is not None:
+ if isinstance(patterns, basestring):
+ patterns = [patterns]
+ for p in patterns:
+ tar.add_default_arg('--exclude=%s' % p)
+
+ self.stage.chdir()
+ tar('-czf', destination, os.path.basename(self.stage.source_path))
+
+
def __str__(self):
return self.url
@@ -345,6 +373,10 @@ class GitFetchStrategy(VCSFetchStrategy):
self.stage.chdir_to_source()
+ def archive(self, destination):
+ super(GitFetchStrategy, self).archive(destination, exclude='.git')
+
+
def reset(self):
assert(self.stage)
self.stage.chdir_to_source()
@@ -414,6 +446,10 @@ class SvnFetchStrategy(VCSFetchStrategy):
shutil.rmtree(path, ignore_errors=True)
+ def archive(self, destination):
+ super(SvnFetchStrategy, self).archive(destination, exclude='.svn')
+
+
def reset(self):
assert(self.stage)
self.stage.chdir_to_source()
@@ -474,6 +510,10 @@ class HgFetchStrategy(VCSFetchStrategy):
self.hg(*args)
+ def archive(self, destination):
+ super(HgFetchStrategy, self).archive(destination, exclude='.hg')
+
+
def reset(self):
assert(self.stage)
self.stage.chdir()