summaryrefslogtreecommitdiffstats
path: root/pyload/AddonManager.py
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2013-11-25 22:57:33 +0100
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2013-11-25 22:57:33 +0100
commit10bd0793f4dc0191d97da390a43552a272c8290e (patch)
tree87b62f81e62b630a89e80beabdec5dd54a359338 /pyload/AddonManager.py
parentrender addon menu for packages (diff)
downloadpyload-10bd0793f4dc0191d97da390a43552a272c8290e.tar.xz
invoke addons via context menu
Diffstat (limited to 'pyload/AddonManager.py')
-rw-r--r--pyload/AddonManager.py24
1 files changed, 18 insertions, 6 deletions
diff --git a/pyload/AddonManager.py b/pyload/AddonManager.py
index 5c5524061..6fa0c5849 100644
--- a/pyload/AddonManager.py
+++ b/pyload/AddonManager.py
@@ -18,7 +18,6 @@
import __builtin__
from gettext import gettext
-from copy import copy
from thread import start_new_thread
from threading import RLock
@@ -27,7 +26,7 @@ from new_collections import namedtuple
from types import MethodType
-from pyload.Api import AddonService, AddonInfo
+from pyload.Api import AddonService, AddonInfo, ServiceException, ServiceDoesNotExist
from pyload.threads.AddonThread import AddonThread
from utils import lock, to_string
@@ -70,14 +69,27 @@ class AddonManager:
self.call(inst, event, *args)
self.dispatchEvent(eventName, *args)
- def call(self, addon, f, *args):
+ def call(self, plugin, f, *args):
try:
- func = getattr(addon, f)
+ func = getattr(plugin, f)
return func(*args)
except Exception, e:
- addon.logError(_("Error when executing %s" % f), e)
+ plugin.logError(_("Error when executing %s" % f), e)
self.core.print_exc()
+ def invoke(self, plugin, func_name, args):
+ """ Invokes a registered method """
+
+ if plugin not in self.plugins and func_name not in self.plugins[plugin].handler:
+ raise ServiceDoesNotExist(plugin, func_name)
+
+ # TODO: choose correct instance
+ try:
+ func = getattr(self.plugins[plugin].instances[0], func_name)
+ return func(*args)
+ except Exception, e:
+ raise ServiceException(e.message)
+
@lock
def createIndex(self):
active = []
@@ -159,7 +171,7 @@ class AddonManager:
self.log.debug("Removed callback %s" % self.core.scheduler.removeJob(addon.cb))
# todo: only delete instances, meta data is lost otherwise
- del self.plugins[addon.__name__]
+ del self.plugins[addon.__name__].instances[:]
# TODO: could be improved
#remove event listener