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:53:38 +0100
commit31f0360f1fd4ebc9dfcaed42d1c50d2448b4632e (patch)
tree7d8882b785efdb755de36a28dffa69712cf9b365 /scripts/lib/mic/pluginbase.py
parent95455ae4251e06d66e60945092b784d2d9ef165c (diff)
downloadopenembedded-core-contrib-31f0360f1fd4ebc9dfcaed42d1c50d2448b4632e.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. 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 @@
+#!/usr/bin/python -tt
+#
+# Copyright (c) 2011 Intel, Inc.
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the Free
+# Software Foundation; version 2 of the License
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc., 59
+# Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+import os
+import shutil
+from mic import msger
+from mic.utils import errors
+
+class _Plugin(object):
+ class __metaclass__(type):
+ def __init__(cls, name, bases, attrs):
+ if not hasattr(cls, 'plugins'):
+ cls.plugins = {}
+
+ elif 'mic_plugin_type' in attrs:
+ if attrs['mic_plugin_type'] not in cls.plugins:
+ cls.plugins[attrs['mic_plugin_type']] = {}
+
+ elif hasattr(cls, 'mic_plugin_type') and 'name' in attrs:
+ cls.plugins[cls.mic_plugin_type][attrs['name']] = cls
+
+ def show_plugins(cls):
+ for cls in cls.plugins[cls.mic_plugin_type]:
+ print cls
+
+ def get_plugins(cls):
+ return cls.plugins
+
+class ImagerPlugin(_Plugin):
+ mic_plugin_type = "imager"
+
+ @classmethod
+ def check_image_exists(self, destdir, apacking=None,
+ images=(),
+ release=None):
+
+ # if it's a packing file, reset images
+ if apacking:
+ images = [apacking]
+
+ # release option will override images
+ if release is not None:
+ images = [os.path.basename(destdir.rstrip('/'))]
+ destdir = os.path.dirname(destdir.rstrip('/'))
+
+ for name in images:
+ if not name:
+ continue
+
+ image = os.path.join(destdir, name)
+ if not os.path.exists(image):
+ continue
+
+ if msger.ask("Target image/dir: %s already exists, "
+ "clean up and continue?" % image):
+ if os.path.isdir(image):
+ shutil.rmtree(image)
+ else:
+ os.unlink(image)
+ else:
+ raise errors.Abort("Cancled")
+
+ def do_create(self):
+ pass
+
+ def do_chroot(self):
+ pass
+
+class BackendPlugin(_Plugin):
+ mic_plugin_type="backend"
+
+ # suppress the verbose rpm warnings
+ if msger.get_loglevel() != 'debug':
+ import rpm
+ rpm.setVerbosity(rpm.RPMLOG_ERR)
+
+ def addRepository(self):
+ pass
+
+def get_plugins(typen):
+ ps = ImagerPlugin.get_plugins()
+ if typen in ps:
+ return ps[typen]
+ else:
+ return None
+
+__all__ = ['ImagerPlugin', 'BackendPlugin', 'get_plugins']