Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1 | # Recipe creation tool - edit plugin |
| 2 | # |
| 3 | # This sub-command edits the recipe and appends for the specified target |
| 4 | # |
| 5 | # Example: recipetool edit busybox |
| 6 | # |
| 7 | # Copyright (C) 2018 Mentor Graphics Corporation |
| 8 | # |
| 9 | # This program is free software; you can redistribute it and/or modify |
| 10 | # it under the terms of the GNU General Public License version 2 as |
| 11 | # published by the Free Software Foundation. |
| 12 | # |
| 13 | # This program is distributed in the hope that it will be useful, |
| 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | # GNU General Public License for more details. |
| 17 | # |
| 18 | # You should have received a copy of the GNU General Public License along |
| 19 | # with this program; if not, write to the Free Software Foundation, Inc., |
| 20 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 21 | |
| 22 | import argparse |
| 23 | import errno |
| 24 | import logging |
| 25 | import os |
| 26 | import re |
| 27 | import subprocess |
| 28 | import sys |
| 29 | import scriptutils |
| 30 | |
| 31 | |
| 32 | logger = logging.getLogger('recipetool') |
| 33 | tinfoil = None |
| 34 | |
| 35 | |
| 36 | def tinfoil_init(instance): |
| 37 | global tinfoil |
| 38 | tinfoil = instance |
| 39 | |
| 40 | |
| 41 | def edit(args): |
| 42 | import oe.recipeutils |
| 43 | |
| 44 | recipe_path = tinfoil.get_recipe_file(args.target) |
| 45 | appends = tinfoil.get_file_appends(recipe_path) |
| 46 | |
| 47 | return scriptutils.run_editor([recipe_path] + appends, logger) |
| 48 | |
| 49 | |
| 50 | def register_commands(subparsers): |
| 51 | parser = subparsers.add_parser('edit', |
| 52 | help='Edit the recipe and appends for the specified target. This obeys $VISUAL if set, otherwise $EDITOR, otherwise vi.') |
| 53 | parser.add_argument('target', help='Target recipe/provide to edit') |
| 54 | parser.set_defaults(func=edit, parserecipes=True) |