1c342db35SBrad Bishop# 2*92b42cb3SPatrick Williams# Copyright BitBake Contributors 3*92b42cb3SPatrick Williams# 4c342db35SBrad Bishop# SPDX-License-Identifier: GPL-2.0-only 5c342db35SBrad Bishop# 6c342db35SBrad Bishop 7eb8dc403SDave Cobbleyimport argparse 8eb8dc403SDave Cobbleyimport logging 9eb8dc403SDave Cobbleyimport os 10eb8dc403SDave Cobbley 11eb8dc403SDave Cobbleylogger = logging.getLogger('bitbake-layers') 12eb8dc403SDave Cobbley 13eb8dc403SDave Cobbley 14eb8dc403SDave Cobbleyclass LayerPlugin(): 15eb8dc403SDave Cobbley def __init__(self): 16eb8dc403SDave Cobbley self.tinfoil = None 17eb8dc403SDave Cobbley self.bblayers = [] 18eb8dc403SDave Cobbley 19eb8dc403SDave Cobbley def tinfoil_init(self, tinfoil): 20eb8dc403SDave Cobbley self.tinfoil = tinfoil 21eb8dc403SDave Cobbley self.bblayers = (self.tinfoil.config_data.getVar('BBLAYERS') or "").split() 2282c905dcSAndrew Geissler layerconfs = self.tinfoil.config_data.varhistory.get_variable_items_files('BBFILE_COLLECTIONS') 23eb8dc403SDave Cobbley self.bbfile_collections = {layer: os.path.dirname(os.path.dirname(path)) for layer, path in layerconfs.items()} 24eb8dc403SDave Cobbley 25eb8dc403SDave Cobbley @staticmethod 26eb8dc403SDave Cobbley def add_command(subparsers, cmdname, function, parserecipes=True, *args, **kwargs): 27eb8dc403SDave Cobbley """Convert docstring for function to help.""" 28eb8dc403SDave Cobbley docsplit = function.__doc__.splitlines() 29eb8dc403SDave Cobbley help = docsplit[0] 30eb8dc403SDave Cobbley if len(docsplit) > 1: 31eb8dc403SDave Cobbley desc = '\n'.join(docsplit[1:]) 32eb8dc403SDave Cobbley else: 33eb8dc403SDave Cobbley desc = help 34eb8dc403SDave Cobbley subparser = subparsers.add_parser(cmdname, *args, help=help, description=desc, formatter_class=argparse.RawTextHelpFormatter, **kwargs) 35eb8dc403SDave Cobbley subparser.set_defaults(func=function, parserecipes=parserecipes) 36eb8dc403SDave Cobbley return subparser 37eb8dc403SDave Cobbley 38eb8dc403SDave Cobbley def get_layer_name(self, layerdir): 39eb8dc403SDave Cobbley return os.path.basename(layerdir.rstrip(os.sep)) 40