From 089223389a99e09e8874f028866a40a9adeb2bc5 Mon Sep 17 00:00:00 2001 From: Gui Chen Date: Wed, 29 Aug 2012 17:28:42 +0800 Subject: [PATCH] set default pkgmgr to auto and preferred to use zypp Signed-off-by: Gui Chen --- distfiles/mic.conf.in | 2 +- mic/conf.py | 2 ++ plugins/imager/fs_plugin.py | 24 +++++++++++++++--------- plugins/imager/livecd_plugin.py | 24 +++++++++++++++--------- plugins/imager/liveusb_plugin.py | 24 +++++++++++++++--------- plugins/imager/loop_plugin.py | 28 +++++++++++++++------------- plugins/imager/raw_plugin.py | 24 +++++++++++++++--------- 7 files changed, 78 insertions(+), 50 deletions(-) diff --git a/distfiles/mic.conf.in b/distfiles/mic.conf.in index a1d0d70..b79603e 100644 --- a/distfiles/mic.conf.in +++ b/distfiles/mic.conf.in @@ -11,7 +11,7 @@ cachedir= /var/tmp/mic/cache outdir= ./mic-output bootstrapdir= /var/tmp/mic/bootstrap -pkgmgr = zypp +pkgmgr = auto # to set global proxy for repos #proxy = http://proxy.yourcompany.com:8080/ diff --git a/mic/conf.py b/mic/conf.py index 5177480..c72320c 100644 --- a/mic/conf.py +++ b/mic/conf.py @@ -34,6 +34,8 @@ def get_siteconf(): return DEFAULT_GSITECONF class ConfigMgr(object): + prefer_backends = ["zypp", "yum"] + DEFAULTS = {'common': { "distro_name": "Default Distribution", "plugin_dir": "/usr/lib/mic/plugins", # TODO use prefix also? diff --git a/plugins/imager/fs_plugin.py b/plugins/imager/fs_plugin.py index d972fe5..dfb2253 100644 --- a/plugins/imager/fs_plugin.py +++ b/plugins/imager/fs_plugin.py @@ -66,17 +66,23 @@ class FsPlugin(ImagerPlugin): # try to find the pkgmgr pkgmgr = None - for (key, pcls) in pluginmgr.get_plugins('backend').iteritems(): - if 'auto' == creatoropts['pkgmgr']: - pkgmgr = pcls - break - elif key == creatoropts['pkgmgr']: - pkgmgr = pcls - break + backends = pluginmgr.get_plugins('backend') + if 'auto' == creatoropts['pkgmgr']: + for key in configmgr.prefer_backends: + if key in backends: + pkgmgr = backends[key] + break + else: + for key in backends.keys(): + if key == creatoropts['pkgmgr']: + pkgmgr = backends[key] + break if not pkgmgr: - pkgmgrs = pluginmgr.get_plugins('backend').keys() - raise errors.CreatorError("Can't find package manager: %s (availables: %s)" % (creatoropts['pkgmgr'], ', '.join(pkgmgrs))) + raise errors.CreatorError("Can't find backend: %s, " + "available choices: %s" % + (creatoropts['pkgmgr'], + ','.join(backends.keys()))) creator = fs.FsImageCreator(creatoropts, pkgmgr) creator._include_src = opts.include_src diff --git a/plugins/imager/livecd_plugin.py b/plugins/imager/livecd_plugin.py index 424404f..eba099a 100644 --- a/plugins/imager/livecd_plugin.py +++ b/plugins/imager/livecd_plugin.py @@ -66,17 +66,23 @@ class LiveCDPlugin(ImagerPlugin): # try to find the pkgmgr pkgmgr = None - for (key, pcls) in pluginmgr.get_plugins('backend').iteritems(): - if 'auto' == creatoropts['pkgmgr']: - pkgmgr = pcls - break - elif key == creatoropts['pkgmgr']: - pkgmgr = pcls - break + backends = pluginmgr.get_plugins('backend') + if 'auto' == creatoropts['pkgmgr']: + for key in configmgr.prefer_backends: + if key in backends: + pkgmgr = backends[key] + break + else: + for key in backends.keys(): + if key == creatoropts['pkgmgr']: + pkgmgr = backends[key] + break if not pkgmgr: - pkgmgrs = pluginmgr.get_plugins('backend').keys() - raise errors.CreatorError("Can't find package manager: %s (availables: %s)" % (creatoropts['pkgmgr'], ', '.join(pkgmgrs))) + raise errors.CreatorError("Can't find backend: %s, " + "available choices: %s" % + (creatoropts['pkgmgr'], + ','.join(backends.keys()))) creator = livecd.LiveCDImageCreator(creatoropts, pkgmgr) diff --git a/plugins/imager/liveusb_plugin.py b/plugins/imager/liveusb_plugin.py index 01afcbb..07fbfa2 100644 --- a/plugins/imager/liveusb_plugin.py +++ b/plugins/imager/liveusb_plugin.py @@ -68,17 +68,23 @@ class LiveUSBPlugin(ImagerPlugin): # try to find the pkgmgr pkgmgr = None - for (key, pcls) in pluginmgr.get_plugins('backend').iteritems(): - if 'auto' == creatoropts['pkgmgr']: - pkgmgr = pcls - break - elif key == creatoropts['pkgmgr']: - pkgmgr = pcls - break + backends = pluginmgr.get_plugins('backend') + if 'auto' == creatoropts['pkgmgr']: + for key in configmgr.prefer_backends: + if key in backends: + pkgmgr = backends[key] + break + else: + for key in backends.keys(): + if key == creatoropts['pkgmgr']: + pkgmgr = backends[key] + break if not pkgmgr: - pkgmgrs = pluginmgr.get_plugins('backend').keys() - raise errors.CreatorError("Can't find package manager: %s (availables: %s)" % (creatoropts['pkgmgr'], ', '.join(pkgmgrs))) + raise errors.CreatorError("Can't find backend: %s, " + "available choices: %s" % + (creatoropts['pkgmgr'], + ','.join(backends.keys()))) creator = liveusb.LiveUSBImageCreator(creatoropts, pkgmgr) diff --git a/plugins/imager/loop_plugin.py b/plugins/imager/loop_plugin.py index 6c22b82..87e8852 100644 --- a/plugins/imager/loop_plugin.py +++ b/plugins/imager/loop_plugin.py @@ -70,23 +70,25 @@ class LoopPlugin(ImagerPlugin): creatoropts['outdir'] = "%s/%s/images/%s/" % (creatoropts['outdir'], creatoropts['release'], creatoropts['name']) - # try to find the pkgmgr pkgmgr = None - for (key, pcls) in pluginmgr.get_plugins('backend').iteritems(): - if 'auto' == creatoropts['pkgmgr']: - pkgmgr = pcls - break - elif key == creatoropts['pkgmgr']: - pkgmgr = pcls - break + backends = pluginmgr.get_plugins('backend') + if 'auto' == creatoropts['pkgmgr']: + for key in configmgr.prefer_backends: + if key in backends: + pkgmgr = backends[key] + break + else: + for key in backends.keys(): + if key == creatoropts['pkgmgr']: + pkgmgr = backends[key] + break if not pkgmgr: - pkgmgrs = pluginmgr.get_plugins('backend').keys() - raise errors.CreatorError("Can't find package manager: %s " - "(availables: %s)" \ - % (creatoropts['pkgmgr'], - ', '.join(pkgmgrs))) + raise errors.CreatorError("Can't find backend: %s, " + "available choices: %s" % + (creatoropts['pkgmgr'], + ','.join(backends.keys()))) creator = LoopImageCreator(creatoropts, pkgmgr, diff --git a/plugins/imager/raw_plugin.py b/plugins/imager/raw_plugin.py index 8f31c03..b2356d2 100644 --- a/plugins/imager/raw_plugin.py +++ b/plugins/imager/raw_plugin.py @@ -71,17 +71,23 @@ class RawPlugin(ImagerPlugin): # try to find the pkgmgr pkgmgr = None - for (key, pcls) in pluginmgr.get_plugins('backend').iteritems(): - if 'auto' == creatoropts['pkgmgr']: - pkgmgr = pcls - break - elif key == creatoropts['pkgmgr']: - pkgmgr = pcls - break + backends = pluginmgr.get_plugins('backend') + if 'auto' == creatoropts['pkgmgr']: + for key in configmgr.prefer_backends: + if key in backends: + pkgmgr = backends[key] + break + else: + for key in backends.keys(): + if key == creatoropts['pkgmgr']: + pkgmgr = backends[key] + break if not pkgmgr: - pkgmgrs = pluginmgr.get_plugins('backend').keys() - raise errors.CreatorError("Can't find package manager: %s (availables: %s)" % (creatoropts['pkgmgr'], ', '.join(pkgmgrs))) + raise errors.CreatorError("Can't find backend: %s, " + "available choices: %s" % + (creatoropts['pkgmgr'], + ','.join(backends.keys()))) creator = raw.RawImageCreator(creatoropts, pkgmgr, opts.compress_image) -- 2.7.4