pluginbase.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #!/usr/bin/env python -tt
  2. #
  3. # Copyright (c) 2011 Intel, Inc.
  4. #
  5. # This program is free software; you can redistribute it and/or modify it
  6. # under the terms of the GNU General Public License as published by the Free
  7. # Software Foundation; version 2 of the License
  8. #
  9. # This program is distributed in the hope that it will be useful, but
  10. # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  11. # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. # for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License along
  15. # with this program; if not, write to the Free Software Foundation, Inc., 59
  16. # Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. import os
  18. import shutil
  19. from wic import msger
  20. from wic.utils import errors
  21. class _Plugin(object):
  22. class __metaclass__(type):
  23. def __init__(cls, name, bases, attrs):
  24. if not hasattr(cls, 'plugins'):
  25. cls.plugins = {}
  26. elif 'wic_plugin_type' in attrs:
  27. if attrs['wic_plugin_type'] not in cls.plugins:
  28. cls.plugins[attrs['wic_plugin_type']] = {}
  29. elif hasattr(cls, 'wic_plugin_type') and 'name' in attrs:
  30. cls.plugins[cls.wic_plugin_type][attrs['name']] = cls
  31. def show_plugins(cls):
  32. for cls in cls.plugins[cls.wic_plugin_type]:
  33. print cls
  34. def get_plugins(cls):
  35. return cls.plugins
  36. class ImagerPlugin(_Plugin):
  37. wic_plugin_type = "imager"
  38. class SourcePlugin(_Plugin):
  39. wic_plugin_type = "source"
  40. """
  41. The methods that can be implemented by --source plugins.
  42. Any methods not implemented in a subclass inherit these.
  43. """
  44. @classmethod
  45. def do_install_disk(self, disk, disk_name, cr, workdir, oe_builddir,
  46. bootimg_dir, kernel_dir, native_sysroot):
  47. """
  48. Called after all partitions have been prepared and assembled into a
  49. disk image. This provides a hook to allow finalization of a
  50. disk image e.g. to write an MBR to it.
  51. """
  52. msger.debug("SourcePlugin: do_install_disk: disk: %s" % disk_name)
  53. @classmethod
  54. def do_stage_partition(self, part, source_params, cr, cr_workdir,
  55. oe_builddir, bootimg_dir, kernel_dir,
  56. native_sysroot):
  57. """
  58. Special content staging hook called before do_prepare_partition(),
  59. normally empty.
  60. Typically, a partition will just use the passed-in parame e.g
  61. straight bootimg_dir, etc, but in some cases, things need to
  62. be more tailored e.g. to use a deploy dir + /boot, etc. This
  63. hook allows those files to be staged in a customized fashion.
  64. Not that get_bitbake_var() allows you to acces non-standard
  65. variables that you might want to use for this.
  66. """
  67. msger.debug("SourcePlugin: do_stage_partition: part: %s" % part)
  68. @classmethod
  69. def do_configure_partition(self, part, source_params, cr, cr_workdir,
  70. oe_builddir, bootimg_dir, kernel_dir,
  71. native_sysroot):
  72. """
  73. Called before do_prepare_partition(), typically used to create
  74. custom configuration files for a partition, for example
  75. syslinux or grub config files.
  76. """
  77. msger.debug("SourcePlugin: do_configure_partition: part: %s" % part)
  78. @classmethod
  79. def do_prepare_partition(self, part, source_params, cr, cr_workdir,
  80. oe_builddir, bootimg_dir, kernel_dir, rootfs_dir,
  81. native_sysroot):
  82. """
  83. Called to do the actual content population for a partition i.e. it
  84. 'prepares' the partition to be incorporated into the image.
  85. """
  86. msger.debug("SourcePlugin: do_prepare_partition: part: %s" % part)
  87. def get_plugins(typen):
  88. ps = ImagerPlugin.get_plugins()
  89. if typen in ps:
  90. return ps[typen]
  91. else:
  92. return None
  93. __all__ = ['ImagerPlugin', 'SourcePlugin', 'get_plugins']