summaryrefslogtreecommitdiff
path: root/src/plugin_manager.py
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2014-04-22 20:02:07 +0200
committermathieui <mathieui@mathieui.net>2014-04-22 20:02:07 +0200
commit3415619895054b2c9a1bf1b98bdfa1153c0bf7e6 (patch)
treee8ae3eaffc57f111a89b48c6cc1be1724b9c9673 /src/plugin_manager.py
parentb14aceaa4f3806dd797cd3e31c1973387409784a (diff)
downloadpoezio-3415619895054b2c9a1bf1b98bdfa1153c0bf7e6.tar.gz
poezio-3415619895054b2c9a1bf1b98bdfa1153c0bf7e6.tar.bz2
poezio-3415619895054b2c9a1bf1b98bdfa1153c0bf7e6.tar.xz
poezio-3415619895054b2c9a1bf1b98bdfa1153c0bf7e6.zip
80-columns wrapping and some docstrings
also bump version, and add some gettext wraps
Diffstat (limited to 'src/plugin_manager.py')
-rw-r--r--src/plugin_manager.py65
1 files changed, 44 insertions, 21 deletions
diff --git a/src/plugin_manager.py b/src/plugin_manager.py
index b3816939..fc8de462 100644
--- a/src/plugin_manager.py
+++ b/src/plugin_manager.py
@@ -27,13 +27,21 @@ class PluginManager(object):
"""
def __init__(self, core):
self.core = core
- self.modules = {} # module name -> module object
- self.plugins = {} # module name -> plugin object
- self.commands = {} # module name -> dict of commands loaded for the module
- self.event_handlers = {} # module name -> list of event_name/handler pairs loaded for the module
- self.tab_commands = {} #module name -> dict of tab types; tab type -> commands loaded by the module
- self.keys = {} # module name → dict of keys/handlers loaded for the module
- self.tab_keys = {} #module name → dict of tab types; tab type → list of keybinds (tuples)
+ # module name -> module object
+ self.modules = {}
+ # module name -> plugin object
+ self.plugins = {}
+ # module name -> dict of commands loaded for the module
+ self.commands = {}
+ # module name -> list of event_name/handler pairs loaded for the module
+ self.event_handlers = {}
+ # module name -> dict of tab types; tab type -> commands
+ # loaded by the module
+ self.tab_commands = {}
+ # module name → dict of keys/handlers loaded for the module
+ self.keys = {}
+ # module name → dict of tab types; tab type → list of keybinds (tuples)
+ self.tab_keys = {}
self.roster_elements = {}
if version_info[1] >= 3: # 3.3 & >
@@ -67,7 +75,8 @@ class PluginManager(object):
imp.acquire_lock()
module = imp.reload(self.modules[name])
else:
- file, filename, info = imp.find_module(name, self.load_path)
+ file, filename, info = imp.find_module(name,
+ self.load_path)
imp.acquire_lock()
module = imp.load_module(name, file, filename, info)
else: # 3.3 & >
@@ -79,7 +88,8 @@ class PluginManager(object):
except Exception as e:
log.debug("Could not load plugin %s", name, exc_info=True)
- self.core.information("Could not load plugin %s: %s" % (name, e), 'Error')
+ self.core.information("Could not load plugin %s: %s" % (name, e),
+ 'Error')
finally:
if version_info[1] < 3 and imp.lock_held():
imp.release_lock()
@@ -94,11 +104,14 @@ class PluginManager(object):
self.event_handlers[name] = []
try:
self.plugins[name] = None
- self.plugins[name] = module.Plugin(self.plugin_api, self.core, self.plugins_conf_dir)
+ self.plugins[name] = module.Plugin(self.plugin_api, self.core,
+ self.plugins_conf_dir)
except Exception as e:
log.error('Error while loading the plugin %s', name, exc_info=True)
if notify:
- self.core.information('Unable to load the plugin %s: %s' % (name, e), 'Error')
+ self.core.information(_('Unable to load the plugin %s: %s') %
+ (name, e),
+ 'Error')
self.unload(name, notify=False)
else:
if notify:
@@ -113,7 +126,8 @@ class PluginManager(object):
del self.core.key_func[key]
for tab in list(self.tab_commands[name].keys()):
for command in self.tab_commands[name][tab][:]:
- self.del_tab_command(name, getattr(tabs, tab), command[0])
+ self.del_tab_command(name, getattr(tabs, tab),
+ command[0])
del self.tab_commands[name][tab]
for tab in list(self.tab_keys[name].keys()):
for key in self.tab_keys[name][tab][:]:
@@ -133,9 +147,12 @@ class PluginManager(object):
self.core.information('Plugin %s unloaded' % name, 'Info')
except Exception as e:
log.debug("Could not unload plugin %s", name, exc_info=True)
- self.core.information("Could not unload plugin %s: %s" % (name, e), 'Error')
+ self.core.information(_("Could not unload plugin %s: %s") %
+ (name, e),
+ 'Error')
- def add_command(self, module_name, name, handler, help, completion=None, short='', usage=''):
+ def add_command(self, module_name, name, handler, help,
+ completion=None, short='', usage=''):
"""
Add a global command.
"""
@@ -155,7 +172,8 @@ class PluginManager(object):
if name in self.core.commands:
del self.core.commands[name]
- def add_tab_command(self, module_name, tab_type, name, handler, help, completion=None, short='', usage=''):
+ def add_tab_command(self, module_name, tab_type, name, handler, help,
+ completion=None, short='', usage=''):
"""
Add a command only for a type of Tab.
"""
@@ -166,7 +184,8 @@ class PluginManager(object):
if not t in commands:
commands[t] = []
commands[t].append((name, handler, help, completion))
- tab_type.plugin_commands[name] = core.Command(handler, help, completion, short, usage)
+ tab_type.plugin_commands[name] = core.Command(handler, help,
+ completion, short, usage)
for tab in self.core.tabs:
if isinstance(tab, tab_type):
tab.update_commands()
@@ -282,14 +301,16 @@ class PluginManager(object):
and name != '__init__.py' and not name.startswith('.')]
plugins_files.sort()
position = the_input.get_argument_position(quoted=False)
- return the_input.new_completion(plugins_files, position, '', quotify=False)
+ return the_input.new_completion(plugins_files, position, '',
+ quotify=False)
def completion_unload(self, the_input):
"""
- completion function that completes the name of the plugins that are loaded
+ completion function that completes the name of loaded plugins
"""
position = the_input.get_argument_position(quoted=False)
- return the_input.new_completion(sorted(self.plugins.keys()), position, '', quotify=False)
+ return the_input.new_completion(sorted(self.plugins.keys()), position,
+ '', quotify=False)
def on_plugins_dir_change(self, new_value):
self.plugins_dir = new_value
@@ -334,7 +355,8 @@ class PluginManager(object):
plugins_dir = config.get('plugins_dir', '')
plugins_dir = plugins_dir or\
os.path.join(os.environ.get('XDG_DATA_HOME') or\
- os.path.join(os.environ.get('HOME'), '.local', 'share'),
+ os.path.join(os.environ.get('HOME'),
+ '.local', 'share'),
'poezio', 'plugins')
self.plugins_dir = os.path.expanduser(plugins_dir)
self.check_create_plugins_dir()
@@ -360,7 +382,8 @@ class PluginManager(object):
self.load_path = []
- default_plugin_path = path.join(path.dirname(path.dirname(__file__)), 'plugins')
+ default_plugin_path = path.join(path.dirname(path.dirname(__file__)),
+ 'plugins')
if os.access(default_plugin_path, os.R_OK | os.X_OK):
self.load_path.insert(0, default_plugin_path)