From 78999a2d621397381b914ede5f26f328e7a7930d Mon Sep 17 00:00:00 2001 From: wilfriedroset Date: Thu, 27 Jun 2019 14:56:57 +0200 Subject: [PATCH] Add fallback value for editor_cmd (#532) (#1091) Fixes #532 --- patroni/ctl.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/patroni/ctl.py b/patroni/ctl.py index 977ddba4..e104988e 100644 --- a/patroni/ctl.py +++ b/patroni/ctl.py @@ -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',