use Excecutable instead of exec for editing licenses (#11968)

* fix defunct editor exit in #11691
This commit is contained in:
Gregory Lee 2019-07-25 11:48:32 -07:00 committed by Todd Gamblin
parent fff99a8a3a
commit e8a71089a6

View file

@ -9,6 +9,7 @@
from llnl.util.filesystem import mkdirp from llnl.util.filesystem import mkdirp
from spack.util.editor import editor from spack.util.editor import editor
from spack.util.executable import Executable, which
def pre_install(spec): def pre_install(spec):
@ -37,8 +38,26 @@ def set_up_license(pkg):
# Create a new license file # Create a new license file
write_license_file(pkg, license_path) write_license_file(pkg, license_path)
# Open up file in user's favorite $EDITOR for editing # Open up file in user's favorite $EDITOR for editing
editor(license_path) editor_exe = None
tty.msg("Added global license file %s" % license_path) 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: else:
# Use already existing license file # Use already existing license file
tty.msg("Found already existing license %s" % license_path) tty.msg("Found already existing license %s" % license_path)