diff options
author | Walter Purcaro <vuolter@users.noreply.github.com> | 2015-12-14 03:22:27 +0100 |
---|---|---|
committer | Walter Purcaro <vuolter@users.noreply.github.com> | 2015-12-27 20:53:13 +0100 |
commit | b9f8e6e78c3f4fdbe7082416e75109c25515d0ed (patch) | |
tree | dfc0d704616473af4d7b919d7559b8c8e919a58b /module/plugins/hooks | |
parent | Update notifiers (diff) | |
download | pyload-b9f8e6e78c3f4fdbe7082416e75109c25515d0ed.tar.xz |
Rename IRC and XMPP addon plugins
Diffstat (limited to 'module/plugins/hooks')
-rw-r--r-- | module/plugins/hooks/IRC.py (renamed from module/plugins/hooks/IRCInterface.py) | 47 | ||||
-rw-r--r-- | module/plugins/hooks/XMPP.py (renamed from module/plugins/hooks/XMPPInterface.py) | 52 |
2 files changed, 49 insertions, 50 deletions
diff --git a/module/plugins/hooks/IRCInterface.py b/module/plugins/hooks/IRC.py index 1f337d686..2b7bea5fd 100644 --- a/module/plugins/hooks/IRCInterface.py +++ b/module/plugins/hooks/IRC.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- -import pycurl import re import select import socket @@ -8,17 +7,19 @@ import ssl import time import traceback +import pycurl + from threading import Thread from module.Api import PackageDoesNotExists, FileDoesNotExists -from module.plugins.internal.Addon import Addon -from module.utils import formatSize +from module.plugins.internal.Notifier import Notifier +from module.internal.misc import formatSize -class IRCInterface(Thread, Addon): - __name__ = "IRCInterface" +class IRC(Thread, Notifier): + __name__ = "IRC" __type__ = "hook" - __version__ = "0.18" + __version__ = "0.19" __status__ = "testing" __config__ = [("activated", "bool", "Activated" , False ), @@ -54,7 +55,7 @@ class IRCInterface(Thread, Addon): def package_finished(self, pypack): try: - if self.get_config('info_pack'): + if self.config.get('info_pack'): self.response(_("Package finished: %s") % pypack.name) except Exception: @@ -63,7 +64,7 @@ class IRCInterface(Thread, Addon): def download_finished(self, pyfile): try: - if self.get_config('info_file'): + if self.config.get('info_file'): self.response( _("Download finished: %(name)s @ %(plugin)s ") % {'name': pyfile.name, 'plugin': pyfile.pluginname}) @@ -72,7 +73,7 @@ class IRCInterface(Thread, Addon): def captcha_task(self, task): - if self.get_config('captcha') and task.isTextual(): + if self.config.get('captcha') and task.isTextual(): task.handler.append(self) task.setWaiting(60) @@ -87,16 +88,16 @@ class IRCInterface(Thread, Addon): def run(self): #: Connect to IRC etc. self.sock = socket.socket() - host = self.get_config('host') - self.sock.connect((host, self.get_config('port'))) + host = self.config.get('host') + self.sock.connect((host, self.config.get('port'))) - if self.get_config('ssl'): + if self.config.get('ssl'): self.sock = ssl.wrap_socket(self.sock, cert_reqs=ssl.CERT_NONE) #@TODO: support certificate - nick = self.get_config('nick') + nick = self.config.get('nick') self.sock.send("NICK %s\r\n" % nick) self.sock.send("USER %s %s bla :%s\r\n" % (nick, host, nick)) - for t in self.get_config('owner').split(): + for t in self.config.get('owner').split(): if t.strip().startswith("#"): self.sock.send("JOIN %s\r\n" % t.strip()) self.log_info(_("Connected to"), host) @@ -151,10 +152,10 @@ class IRCInterface(Thread, Addon): def handle_events(self, msg): - if not msg['origin'].split("!", 1)[0] in self.get_config('owner').split(): + if not msg['origin'].split("!", 1)[0] in self.config.get('owner').split(): return - if msg['target'].split("!", 1)[0] is not self.get_config('nick'): + if msg['target'].split("!", 1)[0] is not self.config.get('nick'): return if msg['action'] != "PRIVMSG": @@ -197,7 +198,7 @@ class IRCInterface(Thread, Addon): def response(self, msg, origin=""): if origin == "": - for t in self.get_config('owner').split(): + for t in self.config.get('owner').split(): self.sock.send("PRIVMSG %s :%s\r\n" % (t.strip(), msg)) else: self.sock.send("PRIVMSG %s :%s\r\n" % (origin.split("!", 1)[0], msg)) @@ -236,25 +237,25 @@ class IRCInterface(Thread, Addon): def event_queue(self, args): - ps = self.pyload.api.getQueueData() + pdata = self.pyload.api.getQueueData() - if not ps: + if not pdata: return ["INFO: There are no packages in queue."] lines = [] - for pack in ps: + for pack in pdata: lines.append('PACKAGE #%s: "%s" with %d links.' % (pack.pid, pack.name, len(pack.links))) return lines def event_collector(self, args): - ps = self.pyload.api.getCollectorData() - if not ps: + pdata = self.pyload.api.getCollectorData() + if not pdata: return ["INFO: No packages in collector!"] lines = [] - for pack in ps: + for pack in pdata: lines.append('PACKAGE #%s: "%s" with %d links.' % (pack.pid, pack.name, len(pack.links))) return lines diff --git a/module/plugins/hooks/XMPPInterface.py b/module/plugins/hooks/XMPP.py index b8fe14239..1e0eda59b 100644 --- a/module/plugins/hooks/XMPPInterface.py +++ b/module/plugins/hooks/XMPP.py @@ -1,18 +1,16 @@ # -*- coding: utf-8 -*- -from pyxmpp import streamtls -from pyxmpp.all import JID, Message -from pyxmpp.interface import implements -from pyxmpp.interfaces import * +import pyxmpp + from pyxmpp.jabber.client import JabberClient -from module.plugins.hooks.IRCInterface import IRCInterface +from module.plugins.hooks.IRC import IRC -class XMPPInterface(IRCInterface, JabberClient): - __name__ = "XMPPInterface" +class XMPP(IRC, JabberClient): + __name__ = "XMPP" __type__ = "hook" - __version__ = "0.14" + __version__ = "0.15" __status__ = "testing" __config__ = [("activated", "bool", "Activated" , False ), @@ -29,21 +27,21 @@ class XMPPInterface(IRCInterface, JabberClient): __authors__ = [("RaNaN", "RaNaN@pyload.org")] - implements(IMessageHandlersProvider) + pyxmpp.interface.implements(IMessageHandlersProvider) def __init__(self, *args, **kwargs): - IRCInterface.__init__(self, *args, **kwargs) + IRC.__init__(self, *args, **kwargs) - self.jid = JID(self.get_config('jid')) - password = self.get_config('pw') + self.jid = pyxmpp.all.JID(self.config.get('jid')) + password = self.config.get('pw') #: If bare JID is provided add a resource -- it is required if not self.jid.resource: - self.jid = JID(self.jid.node, self.jid.domain, "pyLoad") + self.jid = pyxmpp.all.JID(self.jid.node, self.jid.domain, "pyLoad") - if self.get_config('tls'): - tls_settings = streamtls.TLSSettings(require=True, verify_peer=False) + if self.config.get('tls'): + tls_settings = pyxmpp.streamtls.TLSSettings(require=True, verify_peer=False) auth = ("sasl:PLAIN", "sasl:DIGEST-MD5") else: tls_settings = None @@ -69,7 +67,7 @@ class XMPPInterface(IRCInterface, JabberClient): def package_finished(self, pypack): try: - if self.get_config('info_pack'): + if self.config.get('info_pack'): self.announce(_("Package finished: %s") % pypack.name) except Exception: @@ -78,7 +76,7 @@ class XMPPInterface(IRCInterface, JabberClient): def download_finished(self, pyfile): try: - if self.get_config('info_file'): + if self.config.get('info_file'): self.announce( _("Download finished: %(name)s @ %(plugin)s") % {'name': pyfile.name, 'plugin': pyfile.pluginname}) @@ -146,11 +144,11 @@ class XMPPInterface(IRCInterface, JabberClient): to_jid = stanza.get_from() from_jid = stanza.get_to() - # j = JID() + # j = pyxmpp.all.JID() to_name = to_jid.as_utf8() from_name = from_jid.as_utf8() - names = self.get_config('owners').split(";") + names = self.config.get('owners').split(";") if to_name in names or to_jid.node + "@" + to_jid.domain in names: messages = [] @@ -171,7 +169,7 @@ class XMPPInterface(IRCInterface, JabberClient): try: res = handler(args) for line in res: - m = Message( + m = pyxmpp.all.Message( to_jid=to_jid, from_jid=from_jid, stanza_type=stanza.get_type(), @@ -197,15 +195,15 @@ class XMPPInterface(IRCInterface, JabberClient): """ Send message to all owners """ - for user in self.get_config('owners').split(";"): + for user in self.config.get('owners').split(";"): self.log_debug("Send message to", user) - to_jid = JID(user) + to_jid = pyxmpp.all.JID(user) - m = Message(from_jid=self.jid, - to_jid=to_jid, - stanza_type="chat", - body=message) + m = pyxmpp.all.Message(from_jid=self.jid, + to_jid=to_jid, + stanza_type="chat", + body=message) stream = self.get_stream() if not stream: @@ -230,7 +228,7 @@ class VersionHandler(object): This class will answer version query and announce 'jabber:iq:version' namespace in the client's disco#info results. """ - implements(IIqHandlersProvider, IFeaturesProvider) + pyxmpp.interface.implements(IIqHandlersProvider, IFeaturesProvider) def __init__(self, client): |