| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1 | #!/usr/bin/env python3 | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2 |  | 
|  | 3 | # This script has subcommands which operate against your bitbake layers, either | 
|  | 4 | # displaying useful information, or acting against them. | 
|  | 5 | # See the help output for details on available commands. | 
|  | 6 |  | 
|  | 7 | # Copyright (C) 2011 Mentor Graphics Corporation | 
|  | 8 | # Copyright (C) 2011-2015 Intel Corporation | 
|  | 9 | # | 
|  | 10 | # This program is free software; you can redistribute it and/or modify | 
|  | 11 | # it under the terms of the GNU General Public License version 2 as | 
|  | 12 | # published by the Free Software Foundation. | 
|  | 13 | # | 
|  | 14 | # This program is distributed in the hope that it will be useful, | 
|  | 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|  | 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|  | 17 | # GNU General Public License for more details. | 
|  | 18 | # | 
|  | 19 | # You should have received a copy of the GNU General Public License along | 
|  | 20 | # with this program; if not, write to the Free Software Foundation, Inc., | 
|  | 21 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | 
|  | 22 |  | 
|  | 23 | import logging | 
|  | 24 | import os | 
|  | 25 | import sys | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 26 | import argparse | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 27 | import signal | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 28 |  | 
|  | 29 | bindir = os.path.dirname(__file__) | 
|  | 30 | topdir = os.path.dirname(bindir) | 
|  | 31 | sys.path[0:0] = [os.path.join(topdir, 'lib')] | 
|  | 32 |  | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 33 | import bb.tinfoil | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 34 | import bb.msg | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 35 |  | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 36 | logger = bb.msg.logger_create('bitbake-layers', sys.stdout) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 37 |  | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 38 | def main(): | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 39 | signal.signal(signal.SIGPIPE, signal.SIG_DFL) | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 40 | parser = argparse.ArgumentParser( | 
|  | 41 | description="BitBake layers utility", | 
|  | 42 | epilog="Use %(prog)s <subcommand> --help to get help on a specific command", | 
|  | 43 | add_help=False) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 44 | parser.add_argument('-d', '--debug', help='Enable debug output', action='store_true') | 
|  | 45 | parser.add_argument('-q', '--quiet', help='Print only errors', action='store_true') | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 46 | parser.add_argument('--color', choices=['auto', 'always', 'never'], default='auto', help='Colorize output (where %(metavar)s is %(choices)s)', metavar='COLOR') | 
|  | 47 |  | 
|  | 48 | global_args, unparsed_args = parser.parse_known_args() | 
|  | 49 |  | 
|  | 50 | # Help is added here rather than via add_help=True, as we don't want it to | 
|  | 51 | # be handled by parse_known_args() | 
|  | 52 | parser.add_argument('-h', '--help', action='help', default=argparse.SUPPRESS, | 
|  | 53 | help='show this help message and exit') | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 54 | subparsers = parser.add_subparsers(title='subcommands', metavar='<subcommand>') | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 55 | subparsers.required = True | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 56 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 57 | if global_args.debug: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 58 | logger.setLevel(logging.DEBUG) | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 59 | elif global_args.quiet: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 60 | logger.setLevel(logging.ERROR) | 
|  | 61 |  | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 62 | # Need to re-run logger_create with color argument | 
|  | 63 | # (will be the same logger since it has the same name) | 
|  | 64 | bb.msg.logger_create('bitbake-layers', output=sys.stdout, color=global_args.color) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 65 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 66 | plugins = [] | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 67 | tinfoil = bb.tinfoil.Tinfoil(tracking=True) | 
|  | 68 | tinfoil.logger.setLevel(logger.getEffectiveLevel()) | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 69 | try: | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 70 | tinfoil.prepare(True) | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 71 | for path in ([topdir] + | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 72 | tinfoil.config_data.getVar('BBPATH').split(':')): | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 73 | pluginpath = os.path.join(path, 'lib', 'bblayers') | 
|  | 74 | bb.utils.load_plugins(logger, plugins, pluginpath) | 
|  | 75 |  | 
|  | 76 | registered = False | 
|  | 77 | for plugin in plugins: | 
|  | 78 | if hasattr(plugin, 'register_commands'): | 
|  | 79 | registered = True | 
|  | 80 | plugin.register_commands(subparsers) | 
|  | 81 | if hasattr(plugin, 'tinfoil_init'): | 
|  | 82 | plugin.tinfoil_init(tinfoil) | 
|  | 83 |  | 
|  | 84 | if not registered: | 
|  | 85 | logger.error("No commands registered - missing plugins?") | 
|  | 86 | sys.exit(1) | 
|  | 87 |  | 
|  | 88 | args = parser.parse_args(unparsed_args, namespace=global_args) | 
|  | 89 |  | 
|  | 90 | if getattr(args, 'parserecipes', False): | 
|  | 91 | tinfoil.config_data.disableTracking() | 
|  | 92 | tinfoil.parseRecipes() | 
|  | 93 | tinfoil.config_data.enableTracking() | 
|  | 94 |  | 
|  | 95 | return args.func(args) | 
|  | 96 | finally: | 
|  | 97 | tinfoil.shutdown() | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 98 |  | 
|  | 99 |  | 
|  | 100 | if __name__ == "__main__": | 
|  | 101 | try: | 
|  | 102 | ret = main() | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 103 | except bb.BBHandledException: | 
|  | 104 | ret = 1 | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 105 | except Exception: | 
|  | 106 | ret = 1 | 
|  | 107 | import traceback | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 108 | traceback.print_exc() | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 109 | sys.exit(ret) |