diff options
author | Todd Gamblin <tgamblin@llnl.gov> | 2015-12-28 01:14:41 -0800 |
---|---|---|
committer | Todd Gamblin <tgamblin@llnl.gov> | 2015-12-28 01:14:41 -0800 |
commit | e8e6368cc8ab03be4b635731ed43b0fcae47712a (patch) | |
tree | a0eb8b58ba5d2182d397eb697ed2932ecfe56d3b /lib | |
parent | 1f8ba53ca7767ca452f553f71d49eaf90fa19db8 (diff) | |
download | spack-e8e6368cc8ab03be4b635731ed43b0fcae47712a.tar.gz spack-e8e6368cc8ab03be4b635731ed43b0fcae47712a.tar.bz2 spack-e8e6368cc8ab03be4b635731ed43b0fcae47712a.tar.xz spack-e8e6368cc8ab03be4b635731ed43b0fcae47712a.zip |
Rework mirror configuration.
- All of these work:
- `spack mirror add`
- `spack mirror remove`
- `spack mirror list`
- `spack mirror` subcommands (except create) now have their own
--scope argument.
- Mirror config is now stored sanely as an ordered list.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/cmd/mirror.py | 50 | ||||
-rw-r--r-- | lib/spack/spack/stage.py | 6 |
2 files changed, 44 insertions, 12 deletions
diff --git a/lib/spack/spack/cmd/mirror.py b/lib/spack/spack/cmd/mirror.py index a2d2e80f5e..946b50350b 100644 --- a/lib/spack/spack/cmd/mirror.py +++ b/lib/spack/spack/cmd/mirror.py @@ -60,15 +60,22 @@ def setup_parser(subparser): '-o', '--one-version-per-spec', action='store_const', const=1, default=0, help="Only fetch one 'preferred' version per spec, not all known versions.") + add_parser = sp.add_parser('add', help=mirror_add.__doc__) add_parser.add_argument('name', help="Mnemonic name for mirror.") add_parser.add_argument( 'url', help="URL of mirror directory created by 'spack mirror create'.") + add_parser.add_argument('--scope', choices=spack.config.config_scopes, + help="Configuration scope to modify.") remove_parser = sp.add_parser('remove', help=mirror_remove.__doc__) remove_parser.add_argument('name') + remove_parser.add_argument('--scope', choices=spack.config.config_scopes, + help="Configuration scope to modify.") list_parser = sp.add_parser('list', help=mirror_list.__doc__) + list_parser.add_argument('--scope', choices=spack.config.config_scopes, + help="Configuration scope to read from.") def mirror_add(args): @@ -77,31 +84,54 @@ def mirror_add(args): if url.startswith('/'): url = 'file://' + url - mirror_dict = { args.name : url } - spack.config.update_config('mirrors', { args.name : url }, 'user') + mirrors = spack.config.get_config('mirrors', scope=args.scope) + if not mirrors: + mirrors = [] + + for m in mirrors: + for name, u in m.items(): + if name == args.name: + tty.die("Mirror with name %s already exists." % name) + if u == url: + tty.die("Mirror with url %s already exists." % url) + # should only be one item per mirror dict. + + mirrors.insert(0, { args.name : url }) + spack.config.update_config('mirrors', mirrors, scope=args.scope) def mirror_remove(args): """Remove a mirror by name.""" name = args.name - rmd_something = spack.config.remove_from_config('mirrors', name) - if not rmd_something: - tty.die("No such mirror: %s" % name) + mirrors = spack.config.get_config('mirrors', scope=args.scope) + if not mirrors: + mirrors = [] + + names = [n for m in mirrors for n,u in m.items()] + if not name in names: + tty.die("No mirror with name %s" % name) + + old_mirror = mirrors.pop(names.index(name)) + spack.config.update_config('mirrors', mirrors, scope=args.scope) + tty.msg("Removed mirror %s with url %s." % old_mirror.popitem()) def mirror_list(args): """Print out available mirrors to the console.""" - sec_names = spack.config.get_config('mirrors') - if not sec_names: + mirrors = spack.config.get_config('mirrors', scope=args.scope) + if not mirrors: tty.msg("No mirrors configured.") return - max_len = max(len(s) for s in sec_names) + names = [n for m in mirrors for n,u in m.items()] + max_len = max(len(n) for n in names) fmt = "%%-%ds%%s" % (max_len + 4) - for name, val in sec_names.iteritems(): - print fmt % (name, val) + for m in mirrors: + for name, url in m.items(): + print fmt % (name, url) + # should only be one item per mirror dict. def _read_specs_from_file(filename): diff --git a/lib/spack/spack/stage.py b/lib/spack/spack/stage.py index 543a3a6223..a9631d4b62 100644 --- a/lib/spack/spack/stage.py +++ b/lib/spack/spack/stage.py @@ -26,6 +26,7 @@ import os import re import shutil import tempfile +from urlparse import urljoin import llnl.util.tty as tty from llnl.util.filesystem import * @@ -242,8 +243,9 @@ class Stage(object): # TODO: move mirror logic out of here and clean it up! if self.mirror_path: - urls = ["%s/%s" % (u, self.mirror_path) - for name, u in spack.config.get_config('mirrors')] + mirrors = spack.config.get_config('mirrors') + mirrors = [(n,u) for m in mirrors for n,u in m.items()] + urls = [urljoin(u, self.mirror_path) for name, u in mirrors] digest = None if isinstance(self.fetcher, fs.URLFetchStrategy): |