~glatzor/software-center/remove-workaround-747172

« back to all changes in this revision

Viewing changes to softwarecenter/plugin.py

  • Committer: Kiwinote
  • Date: 2012-03-15 22:36:31 UTC
  • mfrom: (2867 trunk)
  • mto: This revision was merged to the branch mainline in revision 2881.
  • Revision ID: kiwinote@gmail.com-20120315223631-lvea6t5sydpkkqni
mergeĀ fromĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 
27
27
from utils import ExecutionTime
28
28
 
 
29
 
29
30
class Plugin(object):
30
31
 
31
32
    """Base class for plugins.
32
 
    
33
33
    """
34
34
    def init_plugin(self):
35
35
        """ Init the plugin (UI, connect signals etc)
36
 
           
 
36
 
37
37
        This should be overwriten by the individual plugins
38
38
        and should return as fast as possible. if some longer
39
39
        init is required, start a glib timer or a thread
43
43
class PluginManager(object):
44
44
 
45
45
    """Class to find and load plugins.
46
 
    
 
46
 
47
47
    Plugins are stored in files named '*_plugin.py' in the list of
48
48
    directories given to the initializer.
49
 
    
50
49
    """
51
 
    
 
50
 
52
51
    def __init__(self, app, plugin_dirs):
53
52
        self._app = app
54
53
        if isinstance(plugin_dirs, basestring):
58
57
 
59
58
    def get_plugin_files(self):
60
59
        """Return all filenames in which plugins may be stored."""
61
 
        
62
60
        names = []
63
61
        for dirname in self._plugin_dirs:
64
62
            if not os.path.exists(dirname):
65
63
                LOG.debug("no dir '%s'" % dirname)
66
64
                continue
67
 
            basenames = [x for x in os.listdir(dirname) 
 
65
            basenames = [x for x in os.listdir(dirname)
68
66
                            if x.endswith(".py")]
69
 
            LOG.debug("Plugin modules in %s: %s" % 
 
67
            LOG.debug("Plugin modules in %s: %s" %
70
68
                            (dirname, " ".join(basenames)))
71
69
            names += [os.path.join(dirname, x) for x in basenames]
72
 
        
73
70
        return names
74
71
 
75
72
    def _find_plugins(self, module):
90
87
        try:
91
88
            module = imp.load_module(module_name, f, filename,
92
89
                                     (".py", "r", imp.PY_SOURCE))
93
 
        except Exception as e: # pragma: no cover
94
 
            LOG.warning("Failed to load plugin '%s' (%s)" % 
 
90
        except Exception as e:  # pragma: no cover
 
91
            LOG.warning("Failed to load plugin '%s' (%s)" %
95
92
                            (module_name, e))
96
93
            return None
97
94
        f.close()
110
107
            filenames = self.get_plugin_files()
111
108
            for filename in filenames:
112
109
                if not os.path.exists(filename):
113
 
                    LOG.warn("plugin '%s' does not exists, dangling symlink?" % filename)
 
110
                    LOG.warn("plugin '%s' does not exists, dangling symlink?" %
 
111
                             filename)
114
112
                    continue
115
113
                with ExecutionTime("loading plugin: '%s'" % filename):
116
114
                    module = self._load_module(filename)