blob: 657d2b6a7b10d6f6f14c2dd235477f7ca6996450 [file] [log] [blame]
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001# Recipe creation tool - set variable plugin
2#
3# Copyright (C) 2015 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
18import sys
19import os
20import argparse
21import glob
22import fnmatch
23import re
24import logging
25import scriptutils
26
27logger = logging.getLogger('recipetool')
28
29tinfoil = None
30plugins = None
31
32def tinfoil_init(instance):
33 global tinfoil
34 tinfoil = instance
35
36def setvar(args):
37 import oe.recipeutils
38
39 if args.delete:
40 if args.value:
41 logger.error('-D/--delete and specifying a value are mutually exclusive')
42 return 1
43 value = None
44 else:
45 if args.value is None:
46 logger.error('You must specify a value if not using -D/--delete')
47 return 1
48 value = args.value
49 varvalues = {args.varname: value}
50
51 if args.recipe_only:
52 patches = [oe.recipeutils.patch_recipe_file(args.recipefile, varvalues, patch=args.patch)]
53 else:
54 rd = oe.recipeutils.parse_recipe(args.recipefile, None, tinfoil.config_data)
55 if not rd:
56 return 1
57 patches = oe.recipeutils.patch_recipe(rd, args.recipefile, varvalues, patch=args.patch)
58 if args.patch:
59 for patch in patches:
60 for line in patch:
61 sys.stdout.write(line)
62 return 0
63
64
65def register_commands(subparsers):
66 parser_setvar = subparsers.add_parser('setvar',
67 help='Set a variable within a recipe',
68 description='Adds/updates the value a variable is set to in a recipe')
69 parser_setvar.add_argument('recipefile', help='Recipe file to update')
70 parser_setvar.add_argument('varname', help='Variable name to set')
71 parser_setvar.add_argument('value', nargs='?', help='New value to set the variable to')
72 parser_setvar.add_argument('--recipe-only', '-r', help='Do not set variable in any include file if present', action='store_true')
73 parser_setvar.add_argument('--patch', '-p', help='Create a patch to make the change instead of modifying the recipe', action='store_true')
74 parser_setvar.add_argument('--delete', '-D', help='Delete the specified value instead of setting it', action='store_true')
75 parser_setvar.set_defaults(func=setvar)