/usr/share/pyshared/irgenerator/core/plugcentral.py is in installation-report-generator 0.2.3-0ubuntu3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2009 Alessio Treglia
#
# This file is part of installation-report-generator.
#
# installation-report-generator 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, either version 3 of the License, or
# (at your option) any later version.
#
# installation-report-generator 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 installation-report-generator. If not, see <http://www.gnu.org/licenses/>.
import os, sys
import thread, threading, time
import irgenerator.globals
__doc__ = irgenerator.globals.__doc__
class VirtualClassInstanceError(Exception):
def __init__(self):
Exception.__init__(self, "can't create a virtual class instance")
class VirtualMethodCallError(Exception):
def __init__(self):
Exception.__init__(self, "can't call a virtual method")
class IPlugin:
def __init__(self):
if self.__class__.__name__ == "IPlugin":
raise VirtualClassInstanceError
def get_report(self):
raise VirtualMethodError
class AbstractPlugin(threading.Thread):
def __init__(self, active_obj=None, hwconfig=None):
if self.__class__.__name__ != 'AbstractPlugin':
threading.Thread.__init__(self)
self.obj = active_obj
self.hwconfig = hwconfig
else:
raise VirtualClassInstanceError
def run(self):
raise VirtualMethodError
def set_active_obj(self, active_obj):
self.obj = active_obj
def set_hwconfig(self, hwconfig):
self.hwconfig = hwconfig
class PluginCentral(object):
from irgenerator.globals import PLUGINS_PATH
plugins_list = set (map(lambda x: x.split('.')[0], os.listdir(PLUGINS_PATH)))
loaded_plugins = dict()
@staticmethod
def load_plugin(name):
plugin = None
try: # check if it has just been loaded
plugin = PluginCentral.loaded_plugins[name]
except KeyError: # load the plugin
sys.path.append(PluginCentral.PLUGINS_PATH)
plugin_module = __import__(name)
plugin = getattr(plugin_module, name + 'Plugin')
PluginCentral.loaded_plugins[name] = plugin # and insert in to the dict
sys.path.pop()
return plugin # return the class
@staticmethod
def get_available_plugins():
plugins_description = dict()
for name in PluginCentral.plugins_list:
plugin = PluginCentral.load_plugin(name)
if plugin.enabled:
plugins_description[name] = plugin.description
return plugins_description
|