summaryrefslogtreecommitdiffstats
path: root/scripts/lib/scriptutils.py
diff options
context:
space:
mode:
authorPaul Eggleton <paul.eggleton@linux.intel.com>2016-02-19 22:38:50 +1300
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-02-21 09:32:42 +0000
commite54f9c159d5d9f9f424e1878ad7fedda13201f59 (patch)
tree078b647539598880a5fb67aa6575744b30ba7a60 /scripts/lib/scriptutils.py
parentdd35f69340c399f54759482fc2865874e2f8ab09 (diff)
downloadpoky-e54f9c159d5d9f9f424e1878ad7fedda13201f59.tar.gz
devtool / recipetool: use common code for launching editor
Looking at Chris Larson's code for starting the user's editor for "recipetool newappend" it was slightly better than what I wrote for "devtool edit-recipe" in that it checks VISUAL as well as EDITOR and defaults to vi if neither are set, so break this out to its own function and call it from both places. The broken out version passes shell=True however in case it's a more complicated command rather than just a name of an executable. (From OE-Core rev: 184a256931e8cdc7bea97a905c4e67a435964de0) Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib/scriptutils.py')
-rw-r--r--scripts/lib/scriptutils.py15
1 files changed, 15 insertions, 0 deletions
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