summaryrefslogtreecommitdiffstats
path: root/pyload
diff options
context:
space:
mode:
Diffstat (limited to 'pyload')
-rw-r--r--pyload/AddonManager.py34
-rw-r--r--pyload/PluginManager.py8
-rw-r--r--pyload/interaction/EventManager.py15
-rw-r--r--pyload/plugins/Addon.py38
-rw-r--r--pyload/plugins/accounts/Premium4Me.py32
-rw-r--r--pyload/plugins/addons/MultiHoster.py14
-rw-r--r--pyload/remote/wsbackend/AsyncHandler.py2
-rw-r--r--pyload/threads/ThreadManager.py4
8 files changed, 37 insertions, 110 deletions
diff --git a/pyload/AddonManager.py b/pyload/AddonManager.py
index 5637b1a8e..f1691fbed 100644
--- a/pyload/AddonManager.py
+++ b/pyload/AddonManager.py
@@ -45,7 +45,7 @@ class AddonManager:
self.createIndex()
# manage addons on config change
- self.addEvent("config:changed", self.manageAddons)
+ self.listenTo("config:changed", self.manageAddon)
@lock
def callInHooks(self, event, eventName, *args):
@@ -62,23 +62,6 @@ class AddonManager:
addon.logError(_("Error when executing %s" % f), e)
self.core.print_exc()
- def addRPC(self, plugin, func, doc):
- doc = doc.strip() if doc else ""
-
- if plugin in self.methods:
- self.methods[plugin][func] = doc
- else:
- self.methods[plugin] = {func: doc}
-
- def callRPC(self, plugin, func, args):
- if not args: args = []
- else:
- args = literal_eval(args)
-
- plugin = self.plugins[plugin]
- f = getattr(plugin, func)
- return f(*args)
-
@lock
def createIndex(self):
active = []
@@ -106,7 +89,6 @@ class AddonManager:
else:
deactive.append(pluginname)
-
except:
self.log.warning(_("Failed activating %(name)s") % {"name": pluginname})
self.core.print_exc()
@@ -114,7 +96,7 @@ class AddonManager:
self.log.info(_("Activated addons: %s") % ", ".join(sorted(active)))
self.log.info(_("Deactivate addons: %s") % ", ".join(sorted(deactive)))
- def manageAddons(self, plugin, name, value):
+ def manageAddon(self, plugin, name, value):
# TODO: user
# check if section was a plugin
@@ -193,12 +175,6 @@ class AddonManager:
def packageFinished(self, package):
self.callInHooks("packageFinished", "package:finished", package)
- def beforeReconnecting(self, ip):
- self.callInHooks("beforeReconnecting", "reconnecting:before", ip)
-
- def afterReconnecting(self, ip):
- self.callInHooks("afterReconnecting", "reconnecting:after", ip)
-
@lock
def startThread(self, function, *args, **kwargs):
AddonThread(self.core.threadManager, function, args, kwargs)
@@ -236,12 +212,12 @@ class AddonManager:
for name, plugin in self.plugins.iteritems():
if name in self.events:
for func, event in self.events[name]:
- self.addEvent(event, getattr(plugin, func))
+ self.listenTo(event, getattr(plugin, func))
# clean up
del self.events[name]
- def addEvent(self, *args):
- self.core.eventManager.addEvent(*args)
+ def listenTo(self, *args):
+ self.core.eventManager.listenTo(*args)
def dispatchEvent(self, *args):
self.core.eventManager.dispatchEvent(*args)
diff --git a/pyload/PluginManager.py b/pyload/PluginManager.py
index 159e7d9de..dab5be063 100644
--- a/pyload/PluginManager.py
+++ b/pyload/PluginManager.py
@@ -194,15 +194,13 @@ class PluginManager:
if folder == "addons" and "config" not in attrs and not attrs.get("internal", False):
attrs["config"] = (["activated", "bool", "Activated", False],)
- if "config" in attrs and attrs["config"]:
+ if "config" in attrs and attrs["config"] is not None:
config = attrs["config"]
desc = attrs.get("description", "")
long_desc = attrs.get("long_description", "")
- if type(config[0]) == tuple:
- config = [list(x) for x in config]
- else:
- config = [list(config)]
+ # Convert tuples to list
+ config = [list(x) for x in config]
if folder == "addons" and not attrs.get("internal", False):
for item in config:
diff --git a/pyload/interaction/EventManager.py b/pyload/interaction/EventManager.py
index 7d37ca6b9..329961d93 100644
--- a/pyload/interaction/EventManager.py
+++ b/pyload/interaction/EventManager.py
@@ -3,6 +3,7 @@
from threading import Lock
from traceback import print_exc
+
class EventManager:
"""
Handles all event-related tasks, also stores an event queue for clients, so they can retrieve them later.
@@ -29,19 +30,11 @@ class EventManager:
self.core = core
self.log = core.log
- # uuid : list of events
- self.clients = {}
self.events = {"event": []}
self.lock = Lock()
- def getEvents(self, uuid):
- """ Get accumulated events for uuid since last call, this also registers a new client """
- if uuid not in self.clients:
- self.clients[uuid] = Client()
- return self.clients[uuid].get()
-
- def addEvent(self, event, func):
+ def listenTo(self, event, func):
"""Adds an event listener for event name"""
if event in self.events:
if func in self.events[event]:
@@ -69,7 +62,7 @@ class EventManager:
f(event, *args)
except Exception, e:
self.log.warning("Error calling event handler %s: %s, %s, %s"
- % ("event", f, args, str(e)))
+ % ("event", f, args, str(e)))
if self.core.debug:
print_exc()
@@ -79,6 +72,6 @@ class EventManager:
f(*args)
except Exception, e:
self.log.warning("Error calling event handler %s: %s, %s, %s"
- % (event, f, args, str(e)))
+ % (event, f, args, str(e)))
if self.core.debug:
print_exc() \ No newline at end of file
diff --git a/pyload/plugins/Addon.py b/pyload/plugins/Addon.py
index ff9c57bef..940339bfb 100644
--- a/pyload/plugins/Addon.py
+++ b/pyload/plugins/Addon.py
@@ -40,19 +40,6 @@ def AddEventListener(event):
return f
return _klass
-class ConfigHandler(object):
- """ Register method as config handler.
-
- Your method signature has to be:
- def foo(value=None):
-
- value will be passed to use your method to set the config.
- When value is None your method needs to return an interaction task for configuration.
- """
-
- def __new__(cls, f, *args, **kwargs):
- addonManager.addConfigHandler(class_name(f.__module__), f.func_name)
- return f
def AddonHandler(desc, media=None):
""" Register Handler for files, packages, or arbitrary callable methods.
@@ -90,10 +77,6 @@ class Addon(Base):
#: automatically register event listeners for functions, attribute will be deleted don't use it yourself
event_map = None
- # Alternative to event_map
- #: List of events the plugin can handle, name the functions exactly like eventname.
- event_list = None # dont make duplicate entries in event_map
-
#: periodic call interval in seconds
interval = 60
@@ -114,22 +97,15 @@ class Addon(Base):
for event, funcs in self.event_map.iteritems():
if type(funcs) in (list, tuple):
for f in funcs:
- self.evm.addEvent(event, getattr(self,f))
+ self.evm.listenTo(event, getattr(self,f))
else:
- self.evm.addEvent(event, getattr(self,funcs))
+ self.evm.listenTo(event, getattr(self,funcs))
#delete for various reasons
self.event_map = None
- if self.event_list:
- for f in self.event_list:
- self.evm.addEvent(f, getattr(self,f))
-
- self.event_list = None
-
self.initPeriodical()
self.init()
- self.setup()
def initPeriodical(self):
if self.interval >=1:
@@ -158,10 +134,6 @@ class Addon(Base):
def init(self):
pass
- def setup(self):
- """ more init stuff if needed """
- pass
-
def activate(self):
""" Used to activate the addon """
if has_method(self.__class__, "coreReady"):
@@ -196,10 +168,4 @@ class Addon(Base):
pass
def packageFinished(self, pypack):
- pass
-
- def beforeReconnecting(self, ip):
- pass
-
- def afterReconnecting(self, ip):
pass \ No newline at end of file
diff --git a/pyload/plugins/accounts/Premium4Me.py b/pyload/plugins/accounts/Premium4Me.py
index de1538e4a..fbca3ce84 100644
--- a/pyload/plugins/accounts/Premium4Me.py
+++ b/pyload/plugins/accounts/Premium4Me.py
@@ -1,27 +1,23 @@
-# -*- coding: utf-8 -*-
-from module.plugins.MultiHoster import MultiHoster
+from module.plugins.Account import Account
-class Premium4Me(MultiHoster):
+class Premium4Me(Account):
__name__ = "Premium4Me"
- __version__ = "0.10"
+ __version__ = "0.03"
__type__ = "account"
- __description__ = """Premium4.me account plugin"""
- __author_name__ = ("RaNaN", "zoidberg")
- __author_mail__ = ("RaNaN@pyload.org", "zoidberg@mujmail.cz")
+ __description__ = """Premium.to account plugin"""
+ __author_name__ = ("RaNaN", "zoidberg", "stickell")
+ __author_mail__ = ("RaNaN@pyload.org", "zoidberg@mujmail.cz", "l.stickell@yahoo.it")
- def loadAccountInfo(self, req):
- traffic = req.load("http://premium4.me/api/traffic.php?authcode=%s" % self.authcode)
+ def loadAccountInfo(self, user, req):
+ traffic = req.load("http://premium.to/api/traffic.php?authcode=%s" % self.authcode)
- account_info = {"trafficleft": int(traffic) / 1024, "validuntil": -1}
+ account_info = {"trafficleft": int(traffic) / 1024,
+ "validuntil": -1}
return account_info
- def login(self, req):
- self.authcode = req.load("http://premium4.me/api/getauthcode.php?username=%s&password=%s" % (self.loginname, self.password)).strip()
-
- if "wrong username" in self.authcode:
- self.wrongPassword()
+ def login(self, user, data, req):
+ self.authcode = req.load("http://premium.to/api/getauthcode.php?username=%s&password=%s" % (user, data["password"])).strip()
- def loadHosterList(self, req):
- page = req.load("http://premium4.me/api/hosters.php?authcode=%s" % self.authcode)
- return [x.strip() for x in page.replace("\"", "").split(";")] \ No newline at end of file
+ if "wrong username" in self.authcode:
+ self.wrongPassword() \ No newline at end of file
diff --git a/pyload/plugins/addons/MultiHoster.py b/pyload/plugins/addons/MultiHoster.py
index 825085df8..b7873a3a2 100644
--- a/pyload/plugins/addons/MultiHoster.py
+++ b/pyload/plugins/addons/MultiHoster.py
@@ -4,14 +4,15 @@
import re
from types import MethodType
-from module.plugins.MultiHoster import MultiHoster as MultiHosterAccount, normalize
-from module.plugins.Addon import Addon, AddEventListener
-from module.plugins.PluginManager import PluginTuple
+from pyload.plugins.MultiHoster import MultiHoster as MultiHosterAccount, normalize
+from pyload.plugins.Addon import Addon, AddEventListener
+from pyload.PluginManager import PluginTuple
+
class MultiHoster(Addon):
__version__ = "0.1"
__internal__ = True
- __description__ = "Gives ability to use MultiHoster services. You need to add your account first."
+ __description__ = "Gives ability to use MultiHoster services."
__config__ = []
__author_mail__ = ("pyLoad Team",)
__author_mail__ = ("support@pyload.org",)
@@ -25,7 +26,7 @@ class MultiHoster(Addon):
def addHoster(self, account):
- self.logDebug("New MultiHoster %s" % account.__name__)
+ self.logInfo(_("Added MultiHoster %s") % account.__name__)
pluginMap = {}
for name in self.core.pluginManager.getPlugins("hoster").keys():
@@ -65,12 +66,10 @@ class MultiHoster(Addon):
hoster[account.__name__] = new
-
@AddEventListener("account:deleted")
def refreshAccounts(self, plugin=None, user=None):
self.plugins = {}
-
for name, account in self.core.accountManager.iterAccounts():
if isinstance(account, MultiHosterAccount) and account.isUsable():
self.addHoster(account)
@@ -94,7 +93,6 @@ class MultiHoster(Addon):
pm = self.core.pluginManager
pm.getPlugin = MethodType(getPlugin, pm, object)
-
def deactivate(self):
#restore state
pm = self.core.pluginManager
diff --git a/pyload/remote/wsbackend/AsyncHandler.py b/pyload/remote/wsbackend/AsyncHandler.py
index 88bd371b0..f1c584b7d 100644
--- a/pyload/remote/wsbackend/AsyncHandler.py
+++ b/pyload/remote/wsbackend/AsyncHandler.py
@@ -52,7 +52,7 @@ class AsyncHandler(AbstractHandler):
self.clients = []
self.lock = Lock()
- self.core.evm.addEvent("event", self.add_event)
+ self.core.evm.listenTo("event", self.add_event)
@lock
def on_open(self, req):
diff --git a/pyload/threads/ThreadManager.py b/pyload/threads/ThreadManager.py
index 0044ebcb2..086e8ba51 100644
--- a/pyload/threads/ThreadManager.py
+++ b/pyload/threads/ThreadManager.py
@@ -202,7 +202,7 @@ class ThreadManager:
ip = self.getIP()
- self.core.addonManager.beforeReconnecting(ip)
+ self.core.evm.dispatchEvent("reconnect:before", ip)
self.log.debug("Old IP: %s" % ip)
@@ -219,7 +219,7 @@ class ThreadManager:
reconn.wait()
sleep(1)
ip = self.getIP()
- self.core.addonManager.afterReconnecting(ip)
+ self.core.evm.dispatchEvent("reconnect:after", ip)
self.log.info(_("Reconnected, new IP: %s") % ip)