unify the license header of all files
[platform/upstream/mic.git] / mic / pluginbase.py
1 #!/usr/bin/python -tt
2 #
3 # Copyright (c) 2011 Intel, Inc.
4 #
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
8 #
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
12 # for more details.
13 #
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.
17
18 from mic import msger
19
20 class _Plugin(object):
21     class __metaclass__(type):
22         def __init__(cls, name, bases, attrs):
23             if not hasattr(cls, 'plugins'):
24                 cls.plugins = {}
25
26             elif 'mic_plugin_type' in attrs:
27                     if attrs['mic_plugin_type'] not in cls.plugins:
28                         cls.plugins[attrs['mic_plugin_type']] = {}
29
30             elif hasattr(cls, 'mic_plugin_type') and 'name' in attrs:
31                     cls.plugins[cls.mic_plugin_type][attrs['name']] = cls
32
33         def show_plugins(cls):
34             for cls in cls.plugins[cls.mic_plugin_type]:
35                 print cls
36
37         def get_plugins(cls):
38             return cls.plugins
39
40 class ImagerPlugin(_Plugin):
41     mic_plugin_type = "imager"
42
43     def do_create(self):
44         pass
45
46     def do_chroot(self):
47         pass
48
49     def do_pack(self):
50         pass
51
52     def do_unpack(self):
53         pass
54
55 class BackendPlugin(_Plugin):
56     mic_plugin_type="backend"
57
58     # suppress the verbose rpm warnings
59     if msger.get_loglevel() != 'debug':
60         import rpm
61         rpm.setVerbosity(rpm.RPMLOG_ERR)
62
63     def addRepository(self):
64         pass
65
66 def get_plugins(typen):
67     ps = ImagerPlugin.get_plugins()
68     if typen in ps:
69         return ps[typen]
70     else:
71         return None
72
73 __all__ = ['ImagerPlugin', 'BackendPlugin', 'get_plugins']