summaryrefslogtreecommitdiffstats
path: root/scripts/lib/mic/pluginbase.py
diff options
context:
space:
mode:
authorTom Zanussi <tom.zanussi@linux.intel.com>2013-08-24 15:31:34 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2013-10-01 22:56:03 +0100
commit9fc88f96d40b17c90bac53b90045a87b2d2cff84 (patch)
tree63010e5aabf895697655baf89bd668d6752b3f97 /scripts/lib/mic/pluginbase.py
parent53a1d9a788fd9f970af980da2ab975cca60685c4 (diff)
downloadpoky-9fc88f96d40b17c90bac53b90045a87b2d2cff84.tar.gz
wic: Add mic w/pykickstart
This is the starting point for the implemention described in [YOCTO 3847] which came to the conclusion that it would make sense to use kickstart syntax to implement image creation in OpenEmbedded. I subsequently realized that there was an existing tool that already implemented image creation using kickstart syntax, the Tizen/Meego mic tool. As such, it made sense to use that as a starting point - this commit essentially just copies the relevant Python code from the MIC tool to the scripts/lib dir, where it can be accessed by the previously created wic tool. Most of this will be removed or renamed by later commits, since we're initially focusing on partitioning only. Care should be taken so that we can easily add back any additional functionality should we decide later to expand the tool, though (we may also want to contribute our local changes to the mic tool to the Tizen project if it makes sense, and therefore should avoid gratuitous changes to the original code if possible). Added the /mic subdir from Tizen mic repo as a starting point: git clone git://review.tizen.org/tools/mic.git For reference, the top commit: commit 20164175ddc234a17b8a12c33d04b012347b1530 Author: Gui Chen <gui.chen@intel.com> Date: Sun Jun 30 22:32:16 2013 -0400 bump up to 0.19.2 Also added the /plugins subdir, moved to under the /mic subdir (to match the default plugin_dir location in mic.conf.in, which was renamed to yocto-image.conf (moved and renamed by later patches) and put into /scripts. (From OE-Core rev: 31f0360f1fd4ebc9dfcaed42d1c50d2448b4632e) Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com> Signed-off-by: Saul Wold <sgw@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib/mic/pluginbase.py')
-rw-r--r--scripts/lib/mic/pluginbase.py101
1 files changed, 101 insertions, 0 deletions
diff --git a/scripts/lib/mic/pluginbase.py b/scripts/lib/mic/pluginbase.py
new file mode 100644
index 0000000000..6ac195b42d
--- /dev/null
+++ b/scripts/lib/mic/pluginbase.py
@@ -0,0 +1,101 @@
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
18import os
19import shutil
20from mic import msger
21from mic.utils import errors
22
23class _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
43class 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
83class BackendPlugin(_Plugin):
84 mic_plugin_type="backend"
85
86 # suppress the verbose rpm warnings
87 if msger.get_loglevel() != 'debug':
88 import rpm
89 rpm.setVerbosity(rpm.RPMLOG_ERR)
90
91 def addRepository(self):
92 pass
93
94def get_plugins(typen):
95 ps = ImagerPlugin.get_plugins()
96 if typen in ps:
97 return ps[typen]
98 else:
99 return None
100
101__all__ = ['ImagerPlugin', 'BackendPlugin', 'get_plugins']