3 # Copyright (c) 2011 Intel, Inc.
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
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
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.
21 from mic.utils import errors
23 class _Plugin(object):
24 class __metaclass__(type):
25 def __init__(cls, name, bases, attrs):
26 if not hasattr(cls, 'plugins'):
29 elif 'mic_plugin_type' in attrs:
30 if attrs['mic_plugin_type'] not in cls.plugins:
31 cls.plugins[attrs['mic_plugin_type']] = {}
33 elif hasattr(cls, 'mic_plugin_type') and 'name' in attrs:
34 cls.plugins[cls.mic_plugin_type][attrs['name']] = cls
36 def show_plugins(cls):
37 for cls in cls.plugins[cls.mic_plugin_type]:
43 class ImagerPlugin(_Plugin):
44 mic_plugin_type = "imager"
47 def check_image_exists(self, destdir, apacking=None,
51 # if it's a packing file, reset images
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('/'))
64 image = os.path.join(destdir, name)
65 if not os.path.exists(image):
68 if msger.ask("Target image/dir: %s already exists, "
69 "clean up and continue?" % image):
70 if os.path.isdir(image):
75 raise errors.Abort("Canceled")
83 class BackendPlugin(_Plugin):
84 mic_plugin_type="backend"
86 # suppress the verbose rpm warnings
87 if msger.get_loglevel() != 'debug':
89 rpm.setVerbosity(rpm.RPMLOG_ERR)
91 def addRepository(self):
94 def get_plugins(typen):
95 ps = ImagerPlugin.get_plugins()
101 __all__ = ['ImagerPlugin', 'BackendPlugin', 'get_plugins']