Add support for disabling modules and add CustomCommandsMenu and TestPlugin to it

This commit is contained in:
Chris Jones 2010-01-06 00:27:58 +00:00
parent 8c117ff6e9
commit 68ade515eb
2 changed files with 8 additions and 2 deletions

View File

@ -73,6 +73,7 @@ DEFAULTS = {
'hide_tabbar' : False, 'hide_tabbar' : False,
'scroll_tabbar' : False, 'scroll_tabbar' : False,
'try_posix_regexp' : platform.system() != 'Linux', 'try_posix_regexp' : platform.system() != 'Linux',
'disabled_plugins' : ['TestPlugin', 'CustomCommandsMenu'],
}, },
'keybindings': { 'keybindings': {
'zoom_in' : '<Ctrl>plus', 'zoom_in' : '<Ctrl>plus',

View File

@ -10,7 +10,7 @@
>>> registry = PluginRegistry() >>> registry = PluginRegistry()
>>> registry.instances >>> registry.instances
{} {}
>>> registry.load_plugins() >>> registry.load_plugins(True)
>>> plugins = registry.get_plugins_by_capability('test') >>> plugins = registry.get_plugins_by_capability('test')
>>> len(plugins) >>> len(plugins)
1 1
@ -26,6 +26,7 @@
import sys import sys
import os import os
import borg import borg
from config import Config
from util import dbg, err, get_config_dir from util import dbg, err, get_config_dir
class Plugin(object): class Plugin(object):
@ -61,12 +62,14 @@ class PluginRegistry(borg.Borg):
if not self.done: if not self.done:
self.done = False self.done = False
def load_plugins(self): def load_plugins(self, testing=False):
"""Load all plugins present in the plugins/ directory in our module""" """Load all plugins present in the plugins/ directory in our module"""
if self.done: if self.done:
dbg('PluginRegistry::load_plugins: Already loaded') dbg('PluginRegistry::load_plugins: Already loaded')
return return
config = Config()
for plugindir in self.path: for plugindir in self.path:
sys.path.insert(0, plugindir) sys.path.insert(0, plugindir)
try: try:
@ -82,6 +85,8 @@ class PluginRegistry(borg.Borg):
try: try:
module = __import__(plugin[:-3], None, None, ['']) module = __import__(plugin[:-3], None, None, [''])
for item in getattr(module, 'available'): for item in getattr(module, 'available'):
if not testing and item in config['disabled_plugins']:
continue
if item not in self.instances: if item not in self.instances:
func = getattr(module, item) func = getattr(module, item)
self.instances[item] = func() self.instances[item] = func()