diff options
-rw-r--r-- | scripts/lib/devtool/standard.py | 36 | ||||
-rw-r--r-- | scripts/lib/devtool/utilcmds.py | 70 |
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 | ||
1261 | def 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 | |||
1291 | def get_default_srctree(config, recipename=''): | 1261 | def 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 | |||
20 | import os | ||
21 | import sys | ||
22 | import shutil | ||
23 | import tempfile | ||
24 | import logging | ||
25 | import argparse | ||
26 | import subprocess | ||
27 | from devtool import exec_build_env_command, setup_tinfoil, check_workspace_recipe, DevtoolError | ||
28 | from devtool import parse_recipe | ||
29 | |||
30 | logger = logging.getLogger('devtool') | ||
31 | |||
32 | |||
33 | def 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 | |||
64 | def 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) | ||