1# 2# Copyright BitBake Contributors 3# 4# SPDX-License-Identifier: GPL-2.0-only 5# 6 7import argparse 8import logging 9import os 10 11logger = logging.getLogger('bitbake-layers') 12 13 14class LayerPlugin(): 15 def __init__(self): 16 self.tinfoil = None 17 self.bblayers = [] 18 19 def tinfoil_init(self, tinfoil): 20 self.tinfoil = tinfoil 21 self.bblayers = (self.tinfoil.config_data.getVar('BBLAYERS') or "").split() 22 layerconfs = self.tinfoil.config_data.varhistory.get_variable_items_files('BBFILE_COLLECTIONS') 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)) 40