summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorPaul Eggleton <paul.eggleton@linux.intel.com>2016-01-26 15:53:53 +1300
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-01-26 18:05:13 +0000
commite00eac862eb429f171b3263a624721bdf3a6171b (patch)
treeb4fa69e78c782137a3ec6ac0d62942d9613308d9 /scripts
parent6720bdac233099e9afe2f9510b1d401cd5b6f903 (diff)
downloadpoky-e00eac862eb429f171b3263a624721bdf3a6171b.tar.gz
devtool: move edit-recipe to a separate module
standard.py is getting a bit large; move the "utility" commands to another module. (From OE-Core rev: 5089b93f5b341dc28c343f7afe15efda2081ed36) Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/lib/devtool/standard.py36
-rw-r--r--scripts/lib/devtool/utilcmds.py70
2 files changed, 70 insertions, 36 deletions
diff --git a/scripts/lib/devtool/standard.py b/scripts/lib/devtool/standard.py
index f19de27a86..83ec7d8efa 100644
--- a/scripts/lib/devtool/standard.py
+++ b/scripts/lib/devtool/standard.py
@@ -1258,36 +1258,6 @@ def reset(args, config, basepath, workspace):
1258 return 0 1258 return 0
1259 1259
1260 1260
1261def edit_recipe(args, config, basepath, workspace):
1262 """Entry point for the devtool 'edit-recipe' subcommand"""
1263 if args.any_recipe:
1264 tinfoil = setup_tinfoil(config_only=False, basepath=basepath)
1265 try:
1266 rd = parse_recipe(config, tinfoil, args.recipename, True)
1267 if not rd:
1268 return 1
1269 recipefile = rd.getVar('FILE', True)
1270 finally:
1271 tinfoil.shutdown()
1272 else:
1273 check_workspace_recipe(workspace, args.recipename)
1274 recipefile = workspace[args.recipename]['recipefile']
1275 if not recipefile:
1276 raise DevtoolError("Recipe file for %s is not under the workspace" %
1277 args.recipename)
1278
1279 editor = os.environ.get('EDITOR', None)
1280 if not editor:
1281 raise DevtoolError("EDITOR environment variable not set")
1282
1283 import subprocess
1284 try:
1285 subprocess.check_call('%s "%s"' % (editor, recipefile), shell=True)
1286 except subprocess.CalledProcessError as e:
1287 return e.returncode
1288
1289 return 0
1290
1291def get_default_srctree(config, recipename=''): 1261def get_default_srctree(config, recipename=''):
1292 """Get the default srctree path""" 1262 """Get the default srctree path"""
1293 srctreeparent = config.get('General', 'default_source_parent_dir', config.workspace_path) 1263 srctreeparent = config.get('General', 'default_source_parent_dir', config.workspace_path)
@@ -1365,9 +1335,3 @@ def register_commands(subparsers, context):
1365 parser_reset.add_argument('--all', '-a', action="store_true", help='Reset all recipes (clear workspace)') 1335 parser_reset.add_argument('--all', '-a', action="store_true", help='Reset all recipes (clear workspace)')
1366 parser_reset.add_argument('--no-clean', '-n', action="store_true", help='Don\'t clean the sysroot to remove recipe output') 1336 parser_reset.add_argument('--no-clean', '-n', action="store_true", help='Don\'t clean the sysroot to remove recipe output')
1367 parser_reset.set_defaults(func=reset) 1337 parser_reset.set_defaults(func=reset)
1368
1369 parser_edit_recipe = subparsers.add_parser('edit-recipe', help='Edit a recipe file in your workspace',
1370 description='Runs the default editor (as specified by the EDITOR variable) on the specified recipe. Note that the recipe file itself must be in the workspace (i.e. as a result of "devtool add" or "devtool upgrade"); you can override this with the -a/--any-recipe option.')
1371 parser_edit_recipe.add_argument('recipename', help='Recipe to edit')
1372 parser_edit_recipe.add_argument('--any-recipe', '-a', action="store_true", help='Edit any recipe, not just where the recipe file itself is in the workspace')
1373 parser_edit_recipe.set_defaults(func=edit_recipe)
diff --git a/scripts/lib/devtool/utilcmds.py b/scripts/lib/devtool/utilcmds.py
new file mode 100644
index 0000000000..375d7a3756
--- /dev/null
+++ b/scripts/lib/devtool/utilcmds.py
@@ -0,0 +1,70 @@
1# Development tool - utility commands plugin
2#
3# Copyright (C) 2015-2016 Intel Corporation
4#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License version 2 as
7# published by the Free Software Foundation.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License along
15# with this program; if not, write to the Free Software Foundation, Inc.,
16# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18"""Devtool utility plugins"""
19
20import os
21import sys
22import shutil
23import tempfile
24import logging
25import argparse
26import subprocess
27from devtool import exec_build_env_command, setup_tinfoil, check_workspace_recipe, DevtoolError
28from devtool import parse_recipe
29
30logger = logging.getLogger('devtool')
31
32
33def edit_recipe(args, config, basepath, workspace):
34 """Entry point for the devtool 'edit-recipe' subcommand"""
35 if args.any_recipe:
36 tinfoil = setup_tinfoil(config_only=False, basepath=basepath)
37 try:
38 rd = parse_recipe(config, tinfoil, args.recipename, True)
39 if not rd:
40 return 1
41 recipefile = rd.getVar('FILE', True)
42 finally:
43 tinfoil.shutdown()
44 else:
45 check_workspace_recipe(workspace, args.recipename)
46 recipefile = workspace[args.recipename]['recipefile']
47 if not recipefile:
48 raise DevtoolError("Recipe file for %s is not under the workspace" %
49 args.recipename)
50
51 editor = os.environ.get('EDITOR', None)
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
63
64def register_commands(subparsers, context):
65 """Register devtool subcommands from this plugin"""
66 parser_edit_recipe = subparsers.add_parser('edit-recipe', help='Edit a recipe file in your workspace',
67 description='Runs the default editor (as specified by the EDITOR variable) on the specified recipe. Note that the recipe file itself must be in the workspace (i.e. as a result of "devtool add" or "devtool upgrade"); you can override this with the -a/--any-recipe option.')
68 parser_edit_recipe.add_argument('recipename', help='Recipe to edit')
69 parser_edit_recipe.add_argument('--any-recipe', '-a', action="store_true", help='Edit any recipe, not just where the recipe file itself is in the workspace')
70 parser_edit_recipe.set_defaults(func=edit_recipe)