diff options
author | Paul Eggleton <paul.eggleton@linux.intel.com> | 2016-02-19 22:38:50 +1300 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-02-21 09:32:42 +0000 |
commit | e54f9c159d5d9f9f424e1878ad7fedda13201f59 (patch) | |
tree | 078b647539598880a5fb67aa6575744b30ba7a60 /scripts/lib | |
parent | dd35f69340c399f54759482fc2865874e2f8ab09 (diff) | |
download | poky-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')
-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 | |||
24 | import logging | 24 | import logging |
25 | import argparse | 25 | import argparse |
26 | import subprocess | 26 | import subprocess |
27 | import scriptutils | ||
27 | from devtool import exec_build_env_command, setup_tinfoil, check_workspace_recipe, DevtoolError | 28 | from devtool import exec_build_env_command, setup_tinfoil, check_workspace_recipe, DevtoolError |
28 | from devtool import parse_recipe | 29 | from 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 | ||
64 | def configure_help(args, config, basepath, workspace): | 55 | 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 | |||
27 | import re | 27 | import re |
28 | import subprocess | 28 | import subprocess |
29 | import sys | 29 | import sys |
30 | import scriptutils | ||
30 | 31 | ||
31 | 32 | ||
32 | logger = logging.getLogger('recipetool') | 33 | logger = 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 | |||
20 | import logging | 20 | import logging |
21 | import glob | 21 | import glob |
22 | import argparse | 22 | import argparse |
23 | import subprocess | ||
23 | 24 | ||
24 | def logger_create(name): | 25 | def 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 | ||
105 | def 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 | ||