diff options
author | lazlev <lazlev@yopmail.com> | 2015-08-09 00:50:54 +0200 |
---|---|---|
committer | lazlev <lazlev@yopmail.com> | 2015-08-09 00:50:54 +0200 |
commit | b0ef3f1673e1930916604bb1264ca3a38414bc8d (patch) | |
tree | c97936e4d2a4cd6eb1072c65c8a08a7d18816b18 /module/plugins/hooks/MultiHome.py | |
parent | [XFileSharingPro][XFileSharingProFolder] Added default __pattern__ (diff) | |
parent | Fix https://github.com/pyload/pyload/issues/1707 (diff) | |
download | pyload-b0ef3f1673e1930916604bb1264ca3a38414bc8d.tar.xz |
Merge pull request #1 from pyload/stable
sync with stable
Diffstat (limited to 'module/plugins/hooks/MultiHome.py')
-rw-r--r-- | module/plugins/hooks/MultiHome.py | 43 |
1 files changed, 20 insertions, 23 deletions
diff --git a/module/plugins/hooks/MultiHome.py b/module/plugins/hooks/MultiHome.py index a26d139c0..929ab9a25 100644 --- a/module/plugins/hooks/MultiHome.py +++ b/module/plugins/hooks/MultiHome.py @@ -2,64 +2,61 @@ import time -from module.plugins.Hook import Hook +from module.plugins.internal.Addon import Addon -class MultiHome(Hook): +class MultiHome(Addon): __name__ = "MultiHome" __type__ = "hook" - __version__ = "0.12" + __version__ = "0.14" + __status__ = "testing" __config__ = [("interfaces", "str", "Interfaces", "None")] - __description__ = """Ip address changer""" + __description__ = """IP address changer""" __license__ = "GPLv3" __authors__ = [("mkaay", "mkaay@mkaay.de")] - interval = 0 #@TODO: Remove in 0.4.10 - - - def setup(self): - self.info = {} #@TODO: Remove in 0.4.10 + def init(self): self.register = {} self.interfaces = [] - self.parseInterfaces(self.getConfig('interfaces').split(";")) + self.parse_interfaces(self.get_config('interfaces').split(";")) if not self.interfaces: - self.parseInterfaces([self.config['download']['interface']]) - self.setConfig("interfaces", self.toConfig()) + self.parse_interfaces([self.pyload.config.get("download", "interface")]) + self.set_config("interfaces", self.to_config()) - def toConfig(self): + def to_config(self): return ";".join(i.adress for i in self.interfaces) - def parseInterfaces(self, interfaces): + def parse_interfaces(self, interfaces): for interface in interfaces: if not interface or str(interface).lower() == "none": continue self.interfaces.append(Interface(interface)) - def coreReady(self): - requestFactory = self.core.requestFactory + def activate(self): + requestFactory = self.pyload.requestFactory oldGetRequest = requestFactory.getRequest - def getRequest(pluginName, account=None): - iface = self.bestInterface(pluginName, account) + def get_request(pluginName, account=None): + iface = self.best_interface(pluginName, account) if iface: iface.useFor(pluginName, account) requestFactory.iface = lambda: iface.adress - self.logDebug("Using address", iface.adress) + self.log_debug("Using address", iface.adress) return oldGetRequest(pluginName, account) - requestFactory.getRequest = getRequest + requestFactory.getRequest = get_request - def bestInterface(self, pluginName, account): + def best_interface(self, pluginName, account): best = None for interface in self.interfaces: if not best or interface.lastPluginAccess(pluginName, account) < best.lastPluginAccess(pluginName, account): @@ -74,13 +71,13 @@ class Interface(object): self.history = {} - def lastPluginAccess(self, pluginName, account): + def last_plugin_access(self, pluginName, account): if (pluginName, account) in self.history: return self.history[(pluginName, account)] return 0 - def useFor(self, pluginName, account): + def use_for(self, pluginName, account): self.history[(pluginName, account)] = time.time() |