summaryrefslogtreecommitdiffstats
path: root/scripts/lib/devtool/utilcmds.py
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/lib/devtool/utilcmds.py
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/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)