Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 1 | # |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 2 | # Copyright BitBake Contributors |
| 3 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 4 | # SPDX-License-Identifier: GPL-2.0-only |
| 5 | # |
| 6 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 7 | import argparse |
| 8 | import logging |
| 9 | import os |
| 10 | |
| 11 | logger = logging.getLogger('bitbake-layers') |
| 12 | |
| 13 | |
| 14 | class LayerPlugin(): |
| 15 | def __init__(self): |
| 16 | self.tinfoil = None |
| 17 | self.bblayers = [] |
| 18 | |
| 19 | def tinfoil_init(self, tinfoil): |
| 20 | self.tinfoil = tinfoil |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 21 | self.bblayers = (self.tinfoil.config_data.getVar('BBLAYERS') or "").split() |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 22 | layerconfs = self.tinfoil.config_data.varhistory.get_variable_items_files('BBFILE_COLLECTIONS') |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 23 | self.bbfile_collections = {layer: os.path.dirname(os.path.dirname(path)) for layer, path in layerconfs.items()} |
| 24 | |
| 25 | @staticmethod |
| 26 | def add_command(subparsers, cmdname, function, parserecipes=True, *args, **kwargs): |
| 27 | """Convert docstring for function to help.""" |
| 28 | docsplit = function.__doc__.splitlines() |
| 29 | help = docsplit[0] |
| 30 | if len(docsplit) > 1: |
| 31 | desc = '\n'.join(docsplit[1:]) |
| 32 | else: |
| 33 | desc = help |
| 34 | subparser = subparsers.add_parser(cmdname, *args, help=help, description=desc, formatter_class=argparse.RawTextHelpFormatter, **kwargs) |
| 35 | subparser.set_defaults(func=function, parserecipes=parserecipes) |
| 36 | return subparser |
| 37 | |
| 38 | def get_layer_name(self, layerdir): |
| 39 | return os.path.basename(layerdir.rstrip(os.sep)) |