diff options
author | Tudor Florea <tudor.florea@enea.com> | 2014-10-16 03:05:19 +0200 |
---|---|---|
committer | Tudor Florea <tudor.florea@enea.com> | 2014-10-16 03:05:19 +0200 |
commit | c527fd1f14c27855a37f2e8ac5346ce8d940ced2 (patch) | |
tree | bb002c1fdf011c41dbd2f0927bed23ecb5f83c97 /scripts/lib/mic/pluginbase.py | |
download | poky-c527fd1f14c27855a37f2e8ac5346ce8d940ced2.tar.gz |
initial commit for Enea Linux 4.0-140929daisy-140929
Migrated from the internal git server on the daisy-enea-point-release branch
Signed-off-by: Tudor Florea <tudor.florea@enea.com>
Diffstat (limited to 'scripts/lib/mic/pluginbase.py')
-rw-r--r-- | scripts/lib/mic/pluginbase.py | 158 |
1 files changed, 158 insertions, 0 deletions
diff --git a/scripts/lib/mic/pluginbase.py b/scripts/lib/mic/pluginbase.py new file mode 100644 index 0000000000..881d9969c6 --- /dev/null +++ b/scripts/lib/mic/pluginbase.py | |||
@@ -0,0 +1,158 @@ | |||
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 mic import msger | ||
21 | from mic.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 'mic_plugin_type' in attrs: | ||
30 | if attrs['mic_plugin_type'] not in cls.plugins: | ||
31 | cls.plugins[attrs['mic_plugin_type']] = {} | ||
32 | |||
33 | elif hasattr(cls, 'mic_plugin_type') and 'name' in attrs: | ||
34 | cls.plugins[cls.mic_plugin_type][attrs['name']] = cls | ||
35 | |||
36 | def show_plugins(cls): | ||
37 | for cls in cls.plugins[cls.mic_plugin_type]: | ||
38 | print cls | ||
39 | |||
40 | def get_plugins(cls): | ||
41 | return cls.plugins | ||
42 | |||
43 | class ImagerPlugin(_Plugin): | ||
44 | mic_plugin_type = "imager" | ||
45 | |||
46 | @classmethod | ||
47 | def check_image_exists(self, destdir, apacking=None, | ||
48 | images=(), | ||
49 | release=None): | ||
50 | |||
51 | # if it's a packing file, reset images | ||
52 | if apacking: | ||
53 | images = [apacking] | ||
54 | |||
55 | # release option will override images | ||
56 | if release is not None: | ||
57 | images = [os.path.basename(destdir.rstrip('/'))] | ||
58 | destdir = os.path.dirname(destdir.rstrip('/')) | ||
59 | |||
60 | for name in images: | ||
61 | if not name: | ||
62 | continue | ||
63 | |||
64 | image = os.path.join(destdir, name) | ||
65 | if not os.path.exists(image): | ||
66 | continue | ||
67 | |||
68 | if msger.ask("Target image/dir: %s already exists, " | ||
69 | "clean up and continue?" % image): | ||
70 | if os.path.isdir(image): | ||
71 | shutil.rmtree(image) | ||
72 | else: | ||
73 | os.unlink(image) | ||
74 | else: | ||
75 | raise errors.Abort("Cancled") | ||
76 | |||
77 | def do_create(self): | ||
78 | pass | ||
79 | |||
80 | def do_chroot(self): | ||
81 | pass | ||
82 | |||
83 | class SourcePlugin(_Plugin): | ||
84 | mic_plugin_type = "source" | ||
85 | """ | ||
86 | The methods that can be implemented by --source plugins. | ||
87 | |||
88 | Any methods not implemented in a subclass inherit these. | ||
89 | """ | ||
90 | |||
91 | @classmethod | ||
92 | def do_install_pkgs(self, part, creator, cr_workdir, oe_builddir, rootfs_dir, | ||
93 | bootimg_dir, kernel_dir, native_sysroot): | ||
94 | """ | ||
95 | Called before partitions have been prepared and assembled into a | ||
96 | disk image. Install packages into rootfs | ||
97 | """ | ||
98 | msger.debug("SourcePlugin: do_install_pkgs: part %s" % part) | ||
99 | |||
100 | @classmethod | ||
101 | def do_install_disk(self, disk, disk_name, cr, workdir, oe_builddir, | ||
102 | bootimg_dir, kernel_dir, native_sysroot): | ||
103 | """ | ||
104 | Called after all partitions have been prepared and assembled into a | ||
105 | disk image. This provides a hook to allow finalization of a | ||
106 | disk image e.g. to write an MBR to it. | ||
107 | """ | ||
108 | msger.debug("SourcePlugin: do_install_disk: disk: %s" % disk_name) | ||
109 | |||
110 | @classmethod | ||
111 | def do_stage_partition(self, part, cr, workdir, oe_builddir, bootimg_dir, | ||
112 | kernel_dir, native_sysroot): | ||
113 | """ | ||
114 | Special content staging hook called before do_prepare_partition(), | ||
115 | normally empty. | ||
116 | |||
117 | Typically, a partition will just use the passed-in parame e.g | ||
118 | straight bootimg_dir, etc, but in some cases, things need to | ||
119 | be more tailored e.g. to use a deploy dir + /boot, etc. This | ||
120 | hook allows those files to be staged in a customized fashion. | ||
121 | Not that get_bitbake_var() allows you to acces non-standard | ||
122 | variables that you might want to use for this. | ||
123 | """ | ||
124 | msger.debug("SourcePlugin: do_stage_partition: part: %s" % part) | ||
125 | |||
126 | @classmethod | ||
127 | def do_configure_partition(self, part, cr, cr_workdir, oe_builddir, | ||
128 | bootimg_dir, kernel_dir, native_sysroot): | ||
129 | """ | ||
130 | Called before do_prepare_partition(), typically used to create | ||
131 | custom configuration files for a partition, for example | ||
132 | syslinux or grub config files. | ||
133 | """ | ||
134 | msger.debug("SourcePlugin: do_configure_partition: part: %s" % part) | ||
135 | |||
136 | @classmethod | ||
137 | def do_prepare_partition(self, part, cr, cr_workdir, oe_builddir, bootimg_dir, | ||
138 | kernel_dir, rootfs_dir, native_sysroot): | ||
139 | """ | ||
140 | Called to do the actual content population for a partition i.e. it | ||
141 | 'prepares' the partition to be incorporated into the image. | ||
142 | """ | ||
143 | msger.debug("SourcePlugin: do_prepare_partition: part: %s" % part) | ||
144 | |||
145 | class BackendPlugin(_Plugin): | ||
146 | mic_plugin_type="backend" | ||
147 | |||
148 | def addRepository(self): | ||
149 | pass | ||
150 | |||
151 | def get_plugins(typen): | ||
152 | ps = ImagerPlugin.get_plugins() | ||
153 | if typen in ps: | ||
154 | return ps[typen] | ||
155 | else: | ||
156 | return None | ||
157 | |||
158 | __all__ = ['ImagerPlugin', 'BackendPlugin', 'SourcePlugin', 'get_plugins'] | ||