diff options
author | Massimiliano Culpo <massimiliano.culpo@googlemail.com> | 2015-12-01 12:56:46 +0100 |
---|---|---|
committer | Massimiliano Culpo <massimiliano.culpo@googlemail.com> | 2015-12-01 12:56:46 +0100 |
commit | a075d581eff5e07cd4b703cbcd1d1e5f490b1fb4 (patch) | |
tree | 06e0c6de103364d49ab8daf6597a9e415497523f /lib | |
parent | a173ab1e3185e322406d0b7379ea77872fbe34c2 (diff) | |
download | spack-a075d581eff5e07cd4b703cbcd1d1e5f490b1fb4.tar.gz spack-a075d581eff5e07cd4b703cbcd1d1e5f490b1fb4.tar.bz2 spack-a075d581eff5e07cd4b703cbcd1d1e5f490b1fb4.tar.xz spack-a075d581eff5e07cd4b703cbcd1d1e5f490b1fb4.zip |
resource : fetch strategy constructed from kwargs instead or hardcoded URLFetchStrategy
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/directives.py | 5 | ||||
-rw-r--r-- | lib/spack/spack/fetch_strategy.py | 16 |
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) |