summaryrefslogtreecommitdiffstats
path: root/scripts/lib/mic/plugin.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/plugin.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/plugin.py')
-rw-r--r--scripts/lib/mic/plugin.py98
1 files changed, 98 insertions, 0 deletions
diff --git a/scripts/lib/mic/plugin.py b/scripts/lib/mic/plugin.py
new file mode 100644
index 0000000000..18c93ad259
--- /dev/null
+++ b/scripts/lib/mic/plugin.py
@@ -0,0 +1,98 @@
+#!/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, sys
+
+from mic import msger
+from mic import pluginbase
+from mic.conf import configmgr
+from mic.utils import errors
+
+
+__ALL__ = ['PluginMgr', 'pluginmgr']
+
+PLUGIN_TYPES = ["imager", "backend"] # TODO "hook"
+
+
+class PluginMgr(object):
+ plugin_dirs = {}
+
+ # make the manager class as singleton
+ _instance = None
+ def __new__(cls, *args, **kwargs):
+ if not cls._instance:
+ cls._instance = super(PluginMgr, cls).__new__(cls, *args, **kwargs)
+
+ return cls._instance
+
+ def __init__(self):
+ self.plugin_dir = configmgr.common['plugin_dir']
+
+ def append_dirs(self, dirs):
+ for path in dirs:
+ self._add_plugindir(path)
+
+ # load all the plugins AGAIN
+ self._load_all()
+
+ def _add_plugindir(self, path):
+ path = os.path.abspath(os.path.expanduser(path))
+
+ if not os.path.isdir(path):
+ msger.warning("Plugin dir is not a directory or does not exist: %s"\
+ % path)
+ return
+
+ if path not in self.plugin_dirs:
+ self.plugin_dirs[path] = False
+ # the value True/False means "loaded"
+
+ def _load_all(self):
+ for (pdir, loaded) in self.plugin_dirs.iteritems():
+ if loaded: continue
+
+ sys.path.insert(0, pdir)
+ for mod in [x[:-3] for x in os.listdir(pdir) if x.endswith(".py")]:
+ if mod and mod != '__init__':
+ if mod in sys.modules:
+ #self.plugin_dirs[pdir] = True
+ msger.warning("Module %s already exists, skip" % mod)
+ else:
+ try:
+ pymod = __import__(mod)
+ self.plugin_dirs[pdir] = True
+ msger.debug("Plugin module %s:%s imported"\
+ % (mod, pymod.__file__))
+ except ImportError, err:
+ msg = 'Failed to load plugin %s/%s: %s' \
+ % (os.path.basename(pdir), mod, err)
+ msger.warning(msg)
+
+ del(sys.path[0])
+
+ def get_plugins(self, ptype):
+ """ the return value is dict of name:class pairs """
+
+ if ptype not in PLUGIN_TYPES:
+ raise errors.CreatorError('%s is not valid plugin type' % ptype)
+
+ self._add_plugindir(os.path.join(self.plugin_dir, ptype))
+ self._load_all()
+
+ return pluginbase.get_plugins(ptype)
+
+pluginmgr = PluginMgr()