From 42e022a938dd5c23c01328fd12f56114e51ee156 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Mon, 4 Jan 2010 13:46:55 +0000 Subject: [PATCH] Make the factory uglier, but better able to handle not running from inside the library, and make the plugins import from the library. These changes make it possible to run epicrefactor from outside itself, which is necessary to make the top level terminator script work with it --- terminatorlib/factory.py | 10 +++++++++- terminatorlib/plugins/terminal_menu.py | 2 +- terminatorlib/plugins/testplugin.py | 2 +- terminatorlib/plugins/url_handlers.py | 2 +- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/terminatorlib/factory.py b/terminatorlib/factory.py index b75832a9..03002ab2 100755 --- a/terminatorlib/factory.py +++ b/terminatorlib/factory.py @@ -29,7 +29,15 @@ class Factory(Borg): 'Container': 'container', 'Window': 'window'} if classtype in types.keys(): - module = __import__(types[classtype], None, None, ['']) + # This is quite ugly, but we're importing from the current + # directory if that makes sense, otherwise falling back to + # terminatorlib. Someone with real Python skills should fix + # this to be less insane. + try: + module = __import__(types[classtype], None, None, ['']) + except ImportError, ex: + module = __import__('terminatorlib.%s' % types[classtype], + None, None, ['']) return(isinstance(product, getattr(module, classtype))) else: err('Factory::isinstance: unknown class type: %s' % classtype) diff --git a/terminatorlib/plugins/terminal_menu.py b/terminatorlib/plugins/terminal_menu.py index e2fcc1a6..575a5c74 100644 --- a/terminatorlib/plugins/terminal_menu.py +++ b/terminatorlib/plugins/terminal_menu.py @@ -2,7 +2,7 @@ # GPL v2 only """terminal_menu.py - Default plugins for the terminal menu""" import gtk -import plugin +import terminatorlib.plugin as plugin # Every plugin you want Terminator to load *must* be listed in 'available' diff --git a/terminatorlib/plugins/testplugin.py b/terminatorlib/plugins/testplugin.py index dda17ce2..a6bd84c3 100644 --- a/terminatorlib/plugins/testplugin.py +++ b/terminatorlib/plugins/testplugin.py @@ -1,4 +1,4 @@ -import plugin +import terminatorlib.plugin as plugin # available must contain a list of all the classes that you want exposed available = ['TestPlugin'] diff --git a/terminatorlib/plugins/url_handlers.py b/terminatorlib/plugins/url_handlers.py index c4f728a6..a7da4393 100644 --- a/terminatorlib/plugins/url_handlers.py +++ b/terminatorlib/plugins/url_handlers.py @@ -2,7 +2,7 @@ # GPL v2 only """url_handlers.py - Default plugins for URL handling""" import re -import plugin +import terminatorlib.plugin as plugin # Every plugin you want Terminator to load *must* be listed in 'available' available = ['LaunchpadBugURLHandler', 'LaunchpadCodeURLHandler', 'APTURLHandler']