import os, sys
from optparse import SUPPRESS_HELP
-from mic import pluginmgr, msger
+from mic import msger
from mic.utils import cmdln, errors, rpmmisc
from conf import configmgr
+from plugin import pluginmgr
class Creator(cmdln.Cmdln):
"""${name}: create an image
cmdln.Cmdln.__init__(self, *args, **kwargs)
# get cmds from pluginmgr
- self.plugincmds = pluginmgr.PluginMgr().get_plugins('imager')
-
# mix-in do_subcmd interface
- for subcmd, klass in self.plugincmds.iteritems():
+ for subcmd, klass in pluginmgr.get_plugins('imager').iteritems():
if not hasattr(klass, 'do_create'):
msger.warning("Unsurpport subcmd: %s" % subcmd)
continue
if self.options.arch in supported_arch:
configmgr.create['arch'] = self.options.arch
else:
- raise errors.Usage('Invalid architecture: "%s".\n' \
- ' Supported architectures are: \n' \
+ raise errors.Usage('Invalid architecture: "%s".\n'
+ ' Supported architectures are: \n'
' %s\n' % (self.options.arch, ', '.join(supported_arch)))
if self.options.pkgmgr is not None:
# Temple Place - Suite 330, Boston, MA 02111-1307, USA.
import os, sys
-from mic import msger
-from mic import pluginbase
+import msger
+import pluginbase
+
+__ALL__ = ['PluginMgr', 'pluginmgr']
DEFAULT_PLUGIN_LOCATION = "/usr/lib/mic/plugins"
return cls._instance
- def __init__(self, plugin_dirs=[]):
+ def __init__(self):
# default plugin directory
for pt in PLUGIN_TYPES:
self._add_plugindir(os.path.join(DEFAULT_PLUGIN_LOCATION, pt))
- for dir in plugin_dirs:
- self._add_plugindir(dir)
+ def append_dirs(self, dirs):
+ for path in dirs:
+ self._add_plugindir(path)
- # load all the plugins
+ # load all the plugins AGAIN
self._load_all()
- def _add_plugindir(self, dir):
- dir = os.path.abspath(os.path.expanduser(dir))
+ def _add_plugindir(self, path):
+ path = os.path.abspath(os.path.expanduser(path))
- if not os.path.isdir(dir):
- msger.warning("Plugin dir is not a directory or does not exist: %s" % dir)
+ if not os.path.isdir(path):
+ msger.warning("Plugin dir is not a directory or does not exist: %s" % path)
return
- if dir not in self.plugin_dirs:
- self.plugin_dirs[dir] = False
+ if path not in self.plugin_dirs:
+ self.plugin_dirs[path] = False
# the value True/False means "loaded"
def _load_all(self):
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:
- msger.debug("Module %s already exists, skip" % mod)
+ #self.plugin_dirs[pdir] = True
+ msger.warning("Module %s already exists, skip" % mod)
else:
try:
pymod = __import__(mod)
def get_plugins(self, ptype):
""" the return value is dict of name:class pairs """
+
+ # good place to load all the plugins
+ self._load_all()
+
return pluginbase.get_plugins(ptype)
+
+pluginmgr = PluginMgr()
import os
-from mic import pluginmgr, chroot, msger
+from mic import chroot, msger
from mic.utils import cmdln, misc, errors
from mic.imager import fs
from mic.conf import configmgr
+from mic.plugin import pluginmgr
from mic.pluginbase import ImagerPlugin
class FsPlugin(ImagerPlugin):
# try to find the pkgmgr
pkgmgr = None
- for (key, pcls) in pluginmgr.PluginMgr().get_plugins('backend').iteritems():
+ for (key, pcls) in pluginmgr.get_plugins('backend').iteritems():
if key == creatoropts['pkgmgr']:
pkgmgr = pcls
break
if not pkgmgr:
- pkgmgrs = pluginmgr.PluginMgr().get_plugins('backend').keys()
+ pkgmgrs = pluginmgr.get_plugins('backend').keys()
raise errors.CreatorError("Can't find package manager: %s (availables: %s)" % (creatoropts['pkgmgr'], ', '.join(pkgmgrs)))
creator = fs.FsImageCreator(creatoropts, pkgmgr)
import shutil
import tempfile
-from mic import pluginmgr, chroot, msger
+from mic import chroot, msger
from mic.utils import misc, fs_related, errors
from mic.conf import configmgr
import mic.imager.livecd as livecd
+from mic.plugin import pluginmgr
from mic.pluginbase import ImagerPlugin
class LiveCDPlugin(ImagerPlugin):
# try to find the pkgmgr
pkgmgr = None
- for (key, pcls) in pluginmgr.PluginMgr().get_plugins('backend').iteritems():
+ for (key, pcls) in pluginmgr.get_plugins('backend').iteritems():
if key == creatoropts['pkgmgr']:
pkgmgr = pcls
break
if not pkgmgr:
- pkgmgrs = pluginmgr.PluginMgr().get_plugins('backend').keys()
+ pkgmgrs = pluginmgr.get_plugins('backend').keys()
raise errors.CreatorError("Can't find package manager: %s (availables: %s)" % (creatoropts['pkgmgr'], ', '.join(pkgmgrs)))
creator = livecd.LiveCDImageCreator(creatoropts, pkgmgr)
import shutil
import tempfile
-from mic import pluginmgr, chroot, msger
+from mic import chroot, msger
from mic.utils import misc, fs_related, errors
from mic.utils.partitionedfs import PartitionedMount
from mic.conf import configmgr
+from mic.plugin import pluginmgr
import mic.imager.liveusb as liveusb
# try to find the pkgmgr
pkgmgr = None
- for (key, pcls) in pluginmgr.PluginMgr().get_plugins('backend').iteritems():
+ for (key, pcls) in pluginmgr.get_plugins('backend').iteritems():
if key == creatoropts['pkgmgr']:
pkgmgr = pcls
break
if not pkgmgr:
- pkgmgrs = pluginmgr.PluginMgr().get_plugins('backend').keys()
+ pkgmgrs = pluginmgr.get_plugins('backend').keys()
raise errors.CreatorError("Can't find package manager: %s (availables: %s)" % (creatoropts['pkgmgr'], ', '.join(pkgmgrs)))
creator = liveusb.LiveUSBImageCreator(creatoropts, pkgmgr)
import shutil
import tempfile
-from mic import pluginmgr, chroot, msger
+from mic import chroot, msger
from mic.utils import misc, fs_related, errors, cmdln
from mic.conf import configmgr
+from mic.plugin import pluginmgr
import mic.imager.loop as loop
from mic.pluginbase import ImagerPlugin
# try to find the pkgmgr
pkgmgr = None
- for (key, pcls) in pluginmgr.PluginMgr().get_plugins('backend').iteritems():
+ for (key, pcls) in pluginmgr.get_plugins('backend').iteritems():
if key == creatoropts['pkgmgr']:
pkgmgr = pcls
break
if not pkgmgr:
- pkgmgrs = pluginmgr.PluginMgr().get_plugins('backend').keys()
+ pkgmgrs = pluginmgr.get_plugins('backend').keys()
raise errors.CreatorError("Can't find package manager: %s (availables: %s)" % (creatoropts['pkgmgr'], ', '.join(pkgmgrs)))
creator = loop.LoopImageCreator(creatoropts, pkgmgr, opts.taring_to)
import re
import tempfile
-from mic import pluginmgr, chroot, msger
+from mic import chroot, msger
from mic.utils import misc, fs_related, errors, runner
from mic.conf import configmgr
+from mic.plugin import pluginmgr
from mic.utils.partitionedfs import PartitionedMount
import mic.imager.raw as raw
# try to find the pkgmgr
pkgmgr = None
- for (key, pcls) in pluginmgr.PluginMgr().get_plugins('backend').iteritems():
+ for (key, pcls) in pluginmgr.get_plugins('backend').iteritems():
if key == creatoropts['pkgmgr']:
pkgmgr = pcls
break
if not pkgmgr:
- pkgmgrs = pluginmgr.PluginMgr().get_plugins('backend').keys()
+ pkgmgrs = pluginmgr.get_plugins('backend').keys()
raise errors.CreatorError("Can't find package manager: %s (availables: %s)" % (creatoropts['pkgmgr'], ', '.join(pkgmgrs)))
creator = raw.RawImageCreator(creatoropts, pkgmgr)
# Temple Place - Suite 330, Boston, MA 02111-1307, USA.
import os, sys
-from mic import msger, creator, pluginmgr
+from mic import msger, creator
from mic.utils import cmdln, misc, errors
+from mic.plugin import pluginmgr
from mic.__version__ import VERSION
-class Mic(cmdln.Cmdln):
+class MicCmd(cmdln.Cmdln):
"""
Usage: mic SUBCOMMAND [OPTS] [ARGS...]
- Mic Image Creation Tool.
+ mic Means the Image Creation tool
Try 'mic help SUBCOMAND' for help on a specific subcommand.
${command_list}
srcimager = None
destimager = None
- for iname, icls in pluginmgr.PluginMgr().get_plugins('imager').iteritems():
+ for iname, icls in pluginmgr.get_plugins('imager').iteritems():
if iname == srcformat and hasattr(icls, "do_unpack"):
srcimager = icls
if iname == destformat and hasattr(icls, "do_pack"):
imagetype = "loop"
chrootclass = None
- for pname, pcls in pluginmgr.PluginMgr().get_plugins('imager').iteritems():
+ for pname, pcls in pluginmgr.get_plugins('imager').iteritems():
if pname == imagetype and hasattr(pcls, "do_chroot"):
chrootclass = pcls
break
if __name__ == "__main__":
try:
- mic = Mic()
+ mic = MicCmd()
sys.exit(mic.main())
except KeyboardInterrupt: