diff options
-rw-r--r-- | scripts/lib/devtool/utilcmds.py | 13 | ||||
-rw-r--r-- | scripts/lib/recipetool/newappend.py | 8 | ||||
-rw-r--r-- | scripts/lib/scriptutils.py | 15 |
3 files changed, 19 insertions, 17 deletions
diff --git a/scripts/lib/devtool/utilcmds.py b/scripts/lib/devtool/utilcmds.py index a8f5e97833..18eddb78b0 100644 --- a/scripts/lib/devtool/utilcmds.py +++ b/scripts/lib/devtool/utilcmds.py @@ -24,6 +24,7 @@ import tempfile import logging import argparse import subprocess +import scriptutils from devtool import exec_build_env_command, setup_tinfoil, check_workspace_recipe, DevtoolError from devtool import parse_recipe @@ -48,17 +49,7 @@ def edit_recipe(args, config, basepath, workspace): raise DevtoolError("Recipe file for %s is not under the workspace" % args.recipename) - editor = os.environ.get('EDITOR', None) - if not editor: - raise DevtoolError("EDITOR environment variable not set") - - import subprocess - try: - subprocess.check_call('%s "%s"' % (editor, recipefile), shell=True) - except subprocess.CalledProcessError as e: - return e.returncode - - return 0 + return scriptutils.run_editor(recipefile) def configure_help(args, config, basepath, workspace): diff --git a/scripts/lib/recipetool/newappend.py b/scripts/lib/recipetool/newappend.py index 5625a8ed52..bdf0693ec7 100644 --- a/scripts/lib/recipetool/newappend.py +++ b/scripts/lib/recipetool/newappend.py @@ -27,6 +27,7 @@ import os import re import subprocess import sys +import scriptutils logger = logging.getLogger('recipetool') @@ -96,12 +97,7 @@ def newappend(args): return 1 if args.edit: - editor = os.getenv('VISUAL', os.getenv('EDITOR', 'vi')) - try: - return subprocess.check_call([editor, append_path, recipe_path]) - except OSError as exc: - logger.error("Execution of editor '%s' failed: %s", editor, exc) - return 1 + return scriptutils.run_editor([append_path, recipe_path]) else: print(append_path) diff --git a/scripts/lib/scriptutils.py b/scripts/lib/scriptutils.py index 69e76d8ea2..aef19d3d73 100644 --- a/scripts/lib/scriptutils.py +++ b/scripts/lib/scriptutils.py @@ -20,6 +20,7 @@ import os import logging import glob import argparse +import subprocess def logger_create(name): logger = logging.getLogger(name) @@ -101,3 +102,17 @@ def fetch_uri(d, uri, destdir, srcrev=None): os.chdir(olddir) return ret +def run_editor(fn): + if isinstance(fn, basestring): + params = '"%s"' % fn + else: + params = '' + for fnitem in fn: + params += ' "%s"' % fnitem + + 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) + return 1 |