summaryrefslogtreecommitdiffstats
path: root/scripts/lib
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/lib')
-rw-r--r--scripts/lib/devtool/utilcmds.py13
-rw-r--r--scripts/lib/recipetool/newappend.py8
-rw-r--r--scripts/lib/scriptutils.py15
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
24import logging 24import logging
25import argparse 25import argparse
26import subprocess 26import subprocess
27import scriptutils
27from devtool import exec_build_env_command, setup_tinfoil, check_workspace_recipe, DevtoolError 28from devtool import exec_build_env_command, setup_tinfoil, check_workspace_recipe, DevtoolError
28from devtool import parse_recipe 29from devtool import parse_recipe
29 30
@@ -48,17 +49,7 @@ def edit_recipe(args, config, basepath, workspace):
48 raise DevtoolError("Recipe file for %s is not under the workspace" % 49 raise DevtoolError("Recipe file for %s is not under the workspace" %
49 args.recipename) 50 args.recipename)
50 51
51 editor = os.environ.get('EDITOR', None) 52 return scriptutils.run_editor(recipefile)
52 if not editor:
53 raise DevtoolError("EDITOR environment variable not set")
54
55 import subprocess
56 try:
57 subprocess.check_call('%s "%s"' % (editor, recipefile), shell=True)
58 except subprocess.CalledProcessError as e:
59 return e.returncode
60
61 return 0
62 53
63 54
64def configure_help(args, config, basepath, workspace): 55def 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
27import re 27import re
28import subprocess 28import subprocess
29import sys 29import sys
30import scriptutils
30 31
31 32
32logger = logging.getLogger('recipetool') 33logger = logging.getLogger('recipetool')
@@ -96,12 +97,7 @@ def newappend(args):
96 return 1 97 return 1
97 98
98 if args.edit: 99 if args.edit:
99 editor = os.getenv('VISUAL', os.getenv('EDITOR', 'vi')) 100 return scriptutils.run_editor([append_path, recipe_path])
100 try:
101 return subprocess.check_call([editor, append_path, recipe_path])
102 except OSError as exc:
103 logger.error("Execution of editor '%s' failed: %s", editor, exc)
104 return 1
105 else: 101 else:
106 print(append_path) 102 print(append_path)
107 103
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
20import logging 20import logging
21import glob 21import glob
22import argparse 22import argparse
23import subprocess
23 24
24def logger_create(name): 25def logger_create(name):
25 logger = logging.getLogger(name) 26 logger = logging.getLogger(name)
@@ -101,3 +102,17 @@ def fetch_uri(d, uri, destdir, srcrev=None):
101 os.chdir(olddir) 102 os.chdir(olddir)
102 return ret 103 return ret
103 104
105def run_editor(fn):
106 if isinstance(fn, basestring):
107 params = '"%s"' % fn
108 else:
109 params = ''
110 for fnitem in fn:
111 params += ' "%s"' % fnitem
112
113 editor = os.getenv('VISUAL', os.getenv('EDITOR', 'vi'))
114 try:
115 return subprocess.check_call('%s %s' % (editor, params), shell=True)
116 except OSError as exc:
117 logger.error("Execution of editor '%s' failed: %s", editor, exc)
118 return 1