common.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #
  2. # SPDX-License-Identifier: GPL-2.0-only
  3. #
  4. import argparse
  5. import logging
  6. import os
  7. logger = logging.getLogger('bitbake-layers')
  8. class LayerPlugin():
  9. def __init__(self):
  10. self.tinfoil = None
  11. self.bblayers = []
  12. def tinfoil_init(self, tinfoil):
  13. self.tinfoil = tinfoil
  14. self.bblayers = (self.tinfoil.config_data.getVar('BBLAYERS') or "").split()
  15. layerconfs = self.tinfoil.config_data.varhistory.get_variable_items_files('BBFILE_COLLECTIONS', self.tinfoil.config_data)
  16. self.bbfile_collections = {layer: os.path.dirname(os.path.dirname(path)) for layer, path in layerconfs.items()}
  17. @staticmethod
  18. def add_command(subparsers, cmdname, function, parserecipes=True, *args, **kwargs):
  19. """Convert docstring for function to help."""
  20. docsplit = function.__doc__.splitlines()
  21. help = docsplit[0]
  22. if len(docsplit) > 1:
  23. desc = '\n'.join(docsplit[1:])
  24. else:
  25. desc = help
  26. subparser = subparsers.add_parser(cmdname, *args, help=help, description=desc, formatter_class=argparse.RawTextHelpFormatter, **kwargs)
  27. subparser.set_defaults(func=function, parserecipes=parserecipes)
  28. return subparser
  29. def get_layer_name(self, layerdir):
  30. return os.path.basename(layerdir.rstrip(os.sep))