]> code.ossystems Code Review - openembedded-core.git/commitdiff
scriptutils: exit politely when no text editor available
authorChang Rebecca Swee Fun <rebecca.swee.fun.chang@intel.com>
Wed, 28 Jun 2017 01:59:17 +0000 (09:59 +0800)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Fri, 21 Jul 2017 11:36:36 +0000 (12:36 +0100)
devtool edit-recipe now has ugly tracebacks if executed without an
editor available. This happens in the build containers whenever no
text editor is available.

subprocess.check_call will run text editing command with recipe path
provided. It will wait for command to complete. If the return code
was zero then return, otherwise raise CalledProcessError exception.

This enhancement will suppress the traceback by catching the exception
and prompt the error messages in a proper manner shown below:

pokyuser@59c99c507238:/workdir/docker-dbg$ devtool edit-recipe ifupdown
/bin/sh: 1: vi: not found
ERROR: Execution of 'vi' failed: Command 'vi
"/workdir/docker-dbg/workspace/recipes/ifupdown/ifupdown_0.8.16.bb"'
returned non-zero exit status 127

[YOCTO #11434]

Signed-off-by: Chang Rebecca Swee Fun <rebecca.swee.fun.chang@intel.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
scripts/lib/scriptutils.py

index 1005dd495ad258946d218c439f0c595fb1c9fcd1..b6217dc059957e87ef318c0af4b854f7f29f9621 100644 (file)
@@ -216,8 +216,8 @@ def run_editor(fn):
     editor = os.getenv('VISUAL', os.getenv('EDITOR', 'vi'))
     try:
         return subprocess.check_call('%s %s' % (editor, params), shell=True)
-    except OSError as exc:
-        logger.error("Execution of editor '%s' failed: %s", editor, exc)
+    except subprocess.CalledProcessError as exc:
+        logger.error("Execution of '%s' failed: %s" % (editor, exc))
         return 1
 
 def is_src_url(param):