diff options
Diffstat (limited to 'scripts/lib/wic/pluginbase.py')
-rw-r--r-- | scripts/lib/wic/pluginbase.py | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/scripts/lib/wic/pluginbase.py b/scripts/lib/wic/pluginbase.py new file mode 100644 index 0000000000..06f318f624 --- /dev/null +++ b/scripts/lib/wic/pluginbase.py | |||
@@ -0,0 +1,108 @@ | |||
1 | #!/usr/bin/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 | import os | ||
19 | import shutil | ||
20 | from wic import msger | ||
21 | from wic.utils import errors | ||
22 | |||
23 | class _Plugin(object): | ||
24 | class __metaclass__(type): | ||
25 | def __init__(cls, name, bases, attrs): | ||
26 | if not hasattr(cls, 'plugins'): | ||
27 | cls.plugins = {} | ||
28 | |||
29 | elif 'wic_plugin_type' in attrs: | ||
30 | if attrs['wic_plugin_type'] not in cls.plugins: | ||
31 | cls.plugins[attrs['wic_plugin_type']] = {} | ||
32 | |||
33 | elif hasattr(cls, 'wic_plugin_type') and 'name' in attrs: | ||
34 | cls.plugins[cls.wic_plugin_type][attrs['name']] = cls | ||
35 | |||
36 | def show_plugins(cls): | ||
37 | for cls in cls.plugins[cls.wic_plugin_type]: | ||
38 | print cls | ||
39 | |||
40 | def get_plugins(cls): | ||
41 | return cls.plugins | ||
42 | |||
43 | |||
44 | class ImagerPlugin(_Plugin): | ||
45 | wic_plugin_type = "imager" | ||
46 | |||
47 | |||
48 | class SourcePlugin(_Plugin): | ||
49 | wic_plugin_type = "source" | ||
50 | """ | ||
51 | The methods that can be implemented by --source plugins. | ||
52 | |||
53 | Any methods not implemented in a subclass inherit these. | ||
54 | """ | ||
55 | |||
56 | @classmethod | ||
57 | def do_install_disk(self, disk, disk_name, cr, workdir, oe_builddir, | ||
58 | bootimg_dir, kernel_dir, native_sysroot): | ||
59 | """ | ||
60 | Called after all partitions have been prepared and assembled into a | ||
61 | disk image. This provides a hook to allow finalization of a | ||
62 | disk image e.g. to write an MBR to it. | ||
63 | """ | ||
64 | msger.debug("SourcePlugin: do_install_disk: disk: %s" % disk_name) | ||
65 | |||
66 | @classmethod | ||
67 | def do_stage_partition(self, part, cr, workdir, oe_builddir, bootimg_dir, | ||
68 | kernel_dir, native_sysroot): | ||
69 | """ | ||
70 | Special content staging hook called before do_prepare_partition(), | ||
71 | normally empty. | ||
72 | |||
73 | Typically, a partition will just use the passed-in parame e.g | ||
74 | straight bootimg_dir, etc, but in some cases, things need to | ||
75 | be more tailored e.g. to use a deploy dir + /boot, etc. This | ||
76 | hook allows those files to be staged in a customized fashion. | ||
77 | Not that get_bitbake_var() allows you to acces non-standard | ||
78 | variables that you might want to use for this. | ||
79 | """ | ||
80 | msger.debug("SourcePlugin: do_stage_partition: part: %s" % part) | ||
81 | |||
82 | @classmethod | ||
83 | def do_configure_partition(self, part, cr, cr_workdir, oe_builddir, | ||
84 | bootimg_dir, kernel_dir, native_sysroot): | ||
85 | """ | ||
86 | Called before do_prepare_partition(), typically used to create | ||
87 | custom configuration files for a partition, for example | ||
88 | syslinux or grub config files. | ||
89 | """ | ||
90 | msger.debug("SourcePlugin: do_configure_partition: part: %s" % part) | ||
91 | |||
92 | @classmethod | ||
93 | def do_prepare_partition(self, part, cr, cr_workdir, oe_builddir, bootimg_dir, | ||
94 | kernel_dir, rootfs_dir, 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 | ps = ImagerPlugin.get_plugins() | ||
103 | if typen in ps: | ||
104 | return ps[typen] | ||
105 | else: | ||
106 | return None | ||
107 | |||
108 | __all__ = ['ImagerPlugin', 'SourcePlugin', 'get_plugins'] | ||