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:
Chris Jones 2009-12-24 21:35:07 +00:00
parent 0a67d73592
commit 60a1b085b4
2 changed files with 33 additions and 18 deletions

View File

@ -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,10 +67,15 @@ 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)
try:
files = os.listdir(plugindir)
except OSError:
sys.path.remove(plugindir)
continue
for plugin in files: for plugin in files:
pluginpath = os.path.join(self.path, plugin) pluginpath = os.path.join(plugindir, plugin)
if os.path.isfile(pluginpath) and plugin[-3:] == '.py': if os.path.isfile(pluginpath) and plugin[-3:] == '.py':
dbg('PluginRegistry::load_plugins: Importing plugin %s' % dbg('PluginRegistry::load_plugins: Importing plugin %s' %
plugin) plugin)

View File

@ -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'))