summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMassimiliano Culpo <massimiliano.culpo@googlemail.com>2015-12-01 12:56:46 +0100
committerMassimiliano Culpo <massimiliano.culpo@googlemail.com>2015-12-01 12:56:46 +0100
commita075d581eff5e07cd4b703cbcd1d1e5f490b1fb4 (patch)
tree06e0c6de103364d49ab8daf6597a9e415497523f
parenta173ab1e3185e322406d0b7379ea77872fbe34c2 (diff)
downloadspack-a075d581eff5e07cd4b703cbcd1d1e5f490b1fb4.tar.gz
spack-a075d581eff5e07cd4b703cbcd1d1e5f490b1fb4.tar.bz2
spack-a075d581eff5e07cd4b703cbcd1d1e5f490b1fb4.tar.xz
spack-a075d581eff5e07cd4b703cbcd1d1e5f490b1fb4.zip
resource : fetch strategy constructed from kwargs instead or hardcoded URLFetchStrategy
-rw-r--r--lib/spack/spack/directives.py5
-rw-r--r--lib/spack/spack/fetch_strategy.py16
2 files changed, 18 insertions, 3 deletions
diff --git a/lib/spack/spack/directives.py b/lib/spack/spack/directives.py
index 4d8333fd7d..741df3a31b 100644
--- a/lib/spack/spack/directives.py
+++ b/lib/spack/spack/directives.py
@@ -62,7 +62,7 @@ from spack.patch import Patch
from spack.variant import Variant
from spack.spec import Spec, parse_anonymous_spec
from spack.resource import Resource
-from spack.fetch_strategy import URLFetchStrategy
+from spack.fetch_strategy import from_kwargs
#
# This is a list of all directives, built up as they are defined in
@@ -279,8 +279,7 @@ def resource(pkg, **kwargs):
destination = kwargs.get('destination', "")
when_spec = parse_anonymous_spec(when, pkg.name)
resources = pkg.resources.setdefault(when_spec, [])
- # FIXME : change URLFetchStrategy with a factory that selects based on kwargs
- fetcher = URLFetchStrategy(**kwargs)
+ fetcher = from_kwargs(**kwargs)
# FIXME : should we infer the name somehow if not passed ?
name = kwargs.get('name')
resources.append(Resource(name, fetcher, destination))
diff --git a/lib/spack/spack/fetch_strategy.py b/lib/spack/spack/fetch_strategy.py
index 5e6850d14b..1f5ef16caa 100644
--- a/lib/spack/spack/fetch_strategy.py
+++ b/lib/spack/spack/fetch_strategy.py
@@ -634,6 +634,22 @@ def from_url(url):
return URLFetchStrategy(url)
+def from_kwargs(**kwargs):
+ """
+ Construct the appropriate FetchStrategy from the given keyword arguments.
+
+ :param kwargs: dictionary of keyword arguments
+ :return: fetcher or raise a FetchError exception
+ """
+ for fetcher in all_strategies:
+ if fetcher.matches(kwargs):
+ return fetcher(**kwargs)
+ # Raise an error in case we can't instantiate any known strategy
+ message = "Cannot instantiate any FetchStrategy"
+ long_message = message + " from the given arguments : {arguments}".format(srguments=kwargs)
+ raise FetchError(message, long_message)
+
+
def args_are_for(args, fetcher):
fetcher.matches(args)