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