summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGregory Lee <lee218@llnl.gov>2019-07-25 11:48:32 -0700
committerTodd Gamblin <tgamblin@llnl.gov>2019-07-25 11:48:32 -0700
commite8a71089a6dba415d8af2f803832ceb1613513df (patch)
tree2112bd2fcfd0e3e0c4c58d7d443ec33212012e35 /lib
parentfff99a8a3acb47e43cce15ce9b968178e7f73061 (diff)
downloadspack-e8a71089a6dba415d8af2f803832ceb1613513df.tar.gz
spack-e8a71089a6dba415d8af2f803832ceb1613513df.tar.bz2
spack-e8a71089a6dba415d8af2f803832ceb1613513df.tar.xz
spack-e8a71089a6dba415d8af2f803832ceb1613513df.zip
use Excecutable instead of exec for editing licenses (#11968)
* fix defunct editor exit in #11691
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/hooks/licensing.py23
1 files changed, 21 insertions, 2 deletions
diff --git a/lib/spack/spack/hooks/licensing.py b/lib/spack/spack/hooks/licensing.py
index cc47f1a4c7..8a56dc122f 100644
--- a/lib/spack/spack/hooks/licensing.py
+++ b/lib/spack/spack/hooks/licensing.py
@@ -9,6 +9,7 @@ import llnl.util.tty as tty
from llnl.util.filesystem import mkdirp
from spack.util.editor import editor
+from spack.util.executable import Executable, which
def pre_install(spec):
@@ -37,8 +38,26 @@ def set_up_license(pkg):
# Create a new license file
write_license_file(pkg, license_path)
# Open up file in user's favorite $EDITOR for editing
- editor(license_path)
- tty.msg("Added global license file %s" % license_path)
+ editor_exe = None
+ if 'VISUAL' in os.environ:
+ editor_exe = Executable(os.environ['VISUAL'])
+ # gvim runs in the background by default so we force it to run
+ # in the foreground to make sure the license file is updated
+ # before we try to install
+ if 'gvim' in os.environ['VISUAL']:
+ editor_exe.add_default_arg('-f')
+ elif 'EDITOR' in os.environ:
+ editor_exe = Executable(os.environ['EDITOR'])
+ else:
+ editor_exe = which('vim', 'vi', 'emacs', 'nano')
+ if editor_exe is None:
+ raise EnvironmentError(
+ 'No text editor found! Please set the VISUAL and/or EDITOR'
+ ' environment variable(s) to your preferred text editor.')
+
+ def editor_wrapper(exe, args):
+ editor_exe(license_path)
+ editor(license_path, _exec_func=editor_wrapper)
else:
# Use already existing license file
tty.msg("Found already existing license %s" % license_path)