summaryrefslogtreecommitdiffstats
path: root/scripts/lib/devtool/utilcmds.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/lib/devtool/utilcmds.py')
-rw-r--r--scripts/lib/devtool/utilcmds.py70
1 files changed, 70 insertions, 0 deletions
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)