Add a utility function for finding ~/.config/terminator and use it in PLuginRegistry to load plugins from the user's homedir
This commit is contained in:
parent
0a67d73592
commit
60a1b085b4
|
@ -26,7 +26,7 @@
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import borg
|
import borg
|
||||||
from util import dbg, err
|
from util import dbg, err, get_config_dir
|
||||||
|
|
||||||
class Plugin(object):
|
class Plugin(object):
|
||||||
"""Definition of our base plugin class"""
|
"""Definition of our base plugin class"""
|
||||||
|
@ -52,10 +52,10 @@ class PluginRegistry(borg.Borg):
|
||||||
if not self.instances:
|
if not self.instances:
|
||||||
self.instances = {}
|
self.instances = {}
|
||||||
if not self.path:
|
if not self.path:
|
||||||
|
self.path = []
|
||||||
(head, tail) = os.path.split(borg.__file__)
|
(head, tail) = os.path.split(borg.__file__)
|
||||||
# FIXME: self.path should really be a list so we can have something
|
self.path.append(os.path.join(head, 'plugins'))
|
||||||
# in the users home directory
|
self.path.append(os.path.join(get_config_dir(), 'plugins'))
|
||||||
self.path = os.path.join(head, 'plugins')
|
|
||||||
dbg('PluginRegistry::prepare_attributes: Plugin path: %s' %
|
dbg('PluginRegistry::prepare_attributes: Plugin path: %s' %
|
||||||
self.path)
|
self.path)
|
||||||
if not self.done:
|
if not self.done:
|
||||||
|
@ -67,21 +67,26 @@ class PluginRegistry(borg.Borg):
|
||||||
dbg('PluginRegistry::load_plugins: Already loaded')
|
dbg('PluginRegistry::load_plugins: Already loaded')
|
||||||
return
|
return
|
||||||
|
|
||||||
sys.path.insert(0, self.path)
|
for plugindir in self.path:
|
||||||
files = os.listdir(self.path)
|
sys.path.insert(0, plugindir)
|
||||||
for plugin in files:
|
try:
|
||||||
pluginpath = os.path.join(self.path, plugin)
|
files = os.listdir(plugindir)
|
||||||
if os.path.isfile(pluginpath) and plugin[-3:] == '.py':
|
except OSError:
|
||||||
dbg('PluginRegistry::load_plugins: Importing plugin %s' %
|
sys.path.remove(plugindir)
|
||||||
plugin)
|
continue
|
||||||
try:
|
for plugin in files:
|
||||||
module = __import__(plugin[:-3], None, None, [''])
|
pluginpath = os.path.join(plugindir, plugin)
|
||||||
for item in getattr(module, 'available'):
|
if os.path.isfile(pluginpath) and plugin[-3:] == '.py':
|
||||||
if item not in self.instances:
|
dbg('PluginRegistry::load_plugins: Importing plugin %s' %
|
||||||
func = getattr(module, item)
|
plugin)
|
||||||
|
try:
|
||||||
|
module = __import__(plugin[:-3], None, None, [''])
|
||||||
|
for item in getattr(module, 'available'):
|
||||||
|
if item not in self.instances:
|
||||||
|
func = getattr(module, item)
|
||||||
self.instances[item] = func()
|
self.instances[item] = func()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
err('PluginRegistry::load_plugins: Importing plugin %s \
|
err('PluginRegistry::load_plugins: Importing plugin %s \
|
||||||
failed: %s' % (plugin, e))
|
failed: %s' % (plugin, e))
|
||||||
|
|
||||||
self.done = True
|
self.done = True
|
||||||
|
|
|
@ -123,3 +123,13 @@ def widget_pixbuf(widget, maxsize=None):
|
||||||
|
|
||||||
return(scaledpixbuf)
|
return(scaledpixbuf)
|
||||||
|
|
||||||
|
def get_config_dir():
|
||||||
|
"""Expand all the messy nonsense for finding where ~/.config/terminator
|
||||||
|
really is"""
|
||||||
|
try:
|
||||||
|
configdir = os.environ['XDG_CONFIG_HOME']
|
||||||
|
except KeyError:
|
||||||
|
configdir = os.path.join(os.path.expanduser('~'), '.config')
|
||||||
|
|
||||||
|
return(os.path.join(configdir, 'terminator'))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue