summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lesana/command.py27
1 files changed, 14 insertions, 13 deletions
diff --git a/lesana/command.py b/lesana/command.py
index b25fb3d..9c27eca 100644
--- a/lesana/command.py
+++ b/lesana/command.py
@@ -11,21 +11,22 @@ from . import Collection, Entry, TemplatingError
def edit_file_in_external_editor(filepath):
# First we try to use $EDITOR
- try:
- editor = os.environ['EDITOR']
- subprocess.call([editor, filepath])
- except FileNotFoundError as e:
- if editor in str(e):
- logging.info(
- 'Could not open file {} with $EDITOR (currently {})'.format(
- filepath, editor
+ editor = os.environ.get('EDITOR')
+ if editor:
+ try:
+ subprocess.call([editor, filepath])
+ except FileNotFoundError as e:
+ if editor in str(e):
+ logging.info(
+ 'Could not open file {} with $EDITOR (currently {})'.format(
+ filepath, editor
+ )
)
- )
+ else:
+ logging.warning("Could not open file {}".format(filepath))
+ return False
else:
- logging.warning("Could not open file {}".format(filepath))
- return False
- else:
- return True
+ return True
# then we try to use sensible-editor (which should be available on
# debian and derivatives)
try: