Add fallback value for editor_cmd (#532) (#1091)

Fixes #532
This commit is contained in:
wilfriedroset
2019-06-27 14:56:57 +02:00
committed by Alexander Kukushkin
parent 1a6db4f5af
commit 78999a2d62
+10 -2
View File
@@ -25,6 +25,7 @@ import yaml
from click import ClickException
from contextlib import contextmanager
from distutils.spawn import find_executable
from patroni.config import Config
from patroni.dcs import get_dcs as _get_dcs
from patroni.exceptions import PatroniException
@@ -1088,9 +1089,16 @@ def invoke_editor(before_editing, cluster_name):
:param before_editing: human representation before editing
:returns tuple of human readable and parsed datastructure after changes
"""
editor_cmd = os.environ.get('EDITOR')
if 'EDITOR' in os.environ:
editor_cmd = os.environ.get('EDITOR')
else:
for editor in ('editor', 'vi'):
editor_cmd = find_executable(editor)
if editor_cmd:
logging.debug('Setting fallback editor_cmd=%s', editor)
break
if not editor_cmd:
raise PatroniCtlException('EDITOR environment variable is not set')
raise PatroniCtlException('EDITOR environment variable is not set. editor or vi are not available')
with temporary_file(contents=before_editing.encode('utf-8'),
suffix='.yaml',