Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 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 | |
| 18 | from wic import msger |
| 19 | |
| 20 | class _Plugin(object): |
| 21 | class __metaclass__(type): |
| 22 | def __init__(cls, name, bases, attrs): |
| 23 | if not hasattr(cls, 'plugins'): |
| 24 | cls.plugins = {} |
| 25 | |
| 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 | |
| 30 | elif hasattr(cls, 'wic_plugin_type') and 'name' in attrs: |
| 31 | cls.plugins[cls.wic_plugin_type][attrs['name']] = cls |
| 32 | |
| 33 | def show_plugins(cls): |
| 34 | for cls in cls.plugins[cls.wic_plugin_type]: |
| 35 | print cls |
| 36 | |
| 37 | def get_plugins(cls): |
| 38 | return cls.plugins |
| 39 | |
| 40 | |
| 41 | class ImagerPlugin(_Plugin): |
| 42 | wic_plugin_type = "imager" |
| 43 | |
| 44 | |
| 45 | class SourcePlugin(_Plugin): |
| 46 | wic_plugin_type = "source" |
| 47 | """ |
| 48 | The methods that can be implemented by --source plugins. |
| 49 | |
| 50 | Any methods not implemented in a subclass inherit these. |
| 51 | """ |
| 52 | |
| 53 | @classmethod |
| 54 | def do_install_disk(cls, disk, disk_name, creator, workdir, oe_builddir, |
| 55 | bootimg_dir, kernel_dir, native_sysroot): |
| 56 | """ |
| 57 | Called after all partitions have been prepared and assembled into a |
| 58 | disk image. This provides a hook to allow finalization of a |
| 59 | disk image e.g. to write an MBR to it. |
| 60 | """ |
| 61 | msger.debug("SourcePlugin: do_install_disk: disk: %s" % disk_name) |
| 62 | |
| 63 | @classmethod |
| 64 | def do_stage_partition(cls, part, source_params, creator, cr_workdir, |
| 65 | oe_builddir, bootimg_dir, kernel_dir, |
| 66 | native_sysroot): |
| 67 | """ |
| 68 | Special content staging hook called before do_prepare_partition(), |
| 69 | normally empty. |
| 70 | |
| 71 | Typically, a partition will just use the passed-in parame e.g |
| 72 | straight bootimg_dir, etc, but in some cases, things need to |
| 73 | be more tailored e.g. to use a deploy dir + /boot, etc. This |
| 74 | hook allows those files to be staged in a customized fashion. |
| 75 | Not that get_bitbake_var() allows you to acces non-standard |
| 76 | variables that you might want to use for this. |
| 77 | """ |
| 78 | msger.debug("SourcePlugin: do_stage_partition: part: %s" % part) |
| 79 | |
| 80 | @classmethod |
| 81 | def do_configure_partition(cls, part, source_params, creator, cr_workdir, |
| 82 | oe_builddir, bootimg_dir, kernel_dir, |
| 83 | native_sysroot): |
| 84 | """ |
| 85 | Called before do_prepare_partition(), typically used to create |
| 86 | custom configuration files for a partition, for example |
| 87 | syslinux or grub config files. |
| 88 | """ |
| 89 | msger.debug("SourcePlugin: do_configure_partition: part: %s" % part) |
| 90 | |
| 91 | @classmethod |
| 92 | def do_prepare_partition(cls, part, source_params, creator, cr_workdir, |
| 93 | oe_builddir, bootimg_dir, kernel_dir, rootfs_dir, |
| 94 | native_sysroot): |
| 95 | """ |
| 96 | Called to do the actual content population for a partition i.e. it |
| 97 | 'prepares' the partition to be incorporated into the image. |
| 98 | """ |
| 99 | msger.debug("SourcePlugin: do_prepare_partition: part: %s" % part) |
| 100 | |
| 101 | def get_plugins(typen): |
| 102 | plugins = ImagerPlugin.get_plugins() |
| 103 | if typen in plugins: |
| 104 | return plugins[typen] |
| 105 | else: |
| 106 | return None |
| 107 | |
| 108 | __all__ = ['ImagerPlugin', 'SourcePlugin', 'get_plugins'] |