From de01d70ae4746432270138881e3f8e573708c554 Mon Sep 17 00:00:00 2001 From: Zack Galbreath Date: Tue, 10 Apr 2018 11:00:14 -0400 Subject: Allow --overwrite and --log-format to be used together Restructure the logic of the spack install command to allow these two command-line arguments to be used at the same time. --- lib/spack/spack/cmd/install.py | 71 +++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 36 deletions(-) (limited to 'lib') diff --git a/lib/spack/spack/cmd/install.py b/lib/spack/spack/cmd/install.py index a4c6e5932e..99572a1ff2 100644 --- a/lib/spack/spack/cmd/install.py +++ b/lib/spack/spack/cmd/install.py @@ -216,41 +216,40 @@ def install(parser, args, **kwargs): if len(specs) == 0: tty.die('The `spack install` command requires a spec to install.') - if args.overwrite: - # If we asked to overwrite an existing spec we must ensure that: - # 1. We have only one spec - # 2. The spec is already installed - assert len(specs) == 1, \ - "only one spec is allowed when overwriting an installation" - - spec = specs[0] - t = spack.store.db.query(spec) - assert len(t) == 1, "to overwrite a spec you must install it first" - - # Give the user a last chance to think about overwriting an already - # existing installation - if not args.yes_to_all: - tty.msg('The following package will be reinstalled:\n') - - display_args = { - 'long': True, - 'show_flags': True, - 'variants': True - } - - spack.cmd.display_specs(t, **display_args) - answer = tty.get_yes_or_no( - 'Do you want to proceed?', default=False - ) - if not answer: - tty.die('Reinstallation aborted.') - - with fs.replace_directory_transaction(specs[0].prefix): - install_spec(args, kwargs, specs[0]) - - else: - - filename = args.log_file or default_log_file(specs[0]) - with spack.report.collect_info(specs, args.log_format, filename): + filename = args.log_file or default_log_file(specs[0]) + with spack.report.collect_info(specs, args.log_format, filename): + if args.overwrite: + # If we asked to overwrite an existing spec we must ensure that: + # 1. We have only one spec + # 2. The spec is already installed + assert len(specs) == 1, \ + "only one spec is allowed when overwriting an installation" + + spec = specs[0] + t = spack.store.db.query(spec) + assert len(t) == 1, "to overwrite a spec you must install it first" + + # Give the user a last chance to think about overwriting an already + # existing installation + if not args.yes_to_all: + tty.msg('The following package will be reinstalled:\n') + + display_args = { + 'long': True, + 'show_flags': True, + 'variants': True + } + + spack.cmd.display_specs(t, **display_args) + answer = tty.get_yes_or_no( + 'Do you want to proceed?', default=False + ) + if not answer: + tty.die('Reinstallation aborted.') + + with fs.replace_directory_transaction(specs[0].prefix): + install_spec(args, kwargs, specs[0]) + + else: for spec in specs: install_spec(args, kwargs, spec) -- cgit v1.2.3-70-g09d2