1 from Components.config import config
2 from Tools import Notifications
3 from Screens.MessageBox import MessageBox
4 from twisted.internet.defer import Deferred
5 from twisted.internet import reactor
7 from . import NOTIFICATIONID
9 def emergencyDisable(*args, **kwargs):
11 try: args[0].printTraceback()
12 except Exception: pass
14 global growleeConnection
16 growleeConnection.stop()
18 if gotNotification in Notifications.notificationAdded:
19 Notifications.notificationAdded.remove(gotNotification)
20 Notifications.AddPopup(
21 _("Network error.\nDisabling Growlee until next restart!"),
22 MessageBox.TYPE_ERROR,
26 def gotNotification():
27 notifications = Notifications.notifications
29 _, screen, args, kwargs, id = notifications[-1]
30 if screen is MessageBox and id != NOTIFICATIONID:
32 # NOTE: priority is in [-2; 2] but type is [0; 3] so map it
33 # XXX: maybe priority==type-2 would be more appropriate
34 priority = kwargs.get("type", 0) - 1
35 timeout = kwargs.get("timeout", -1)
38 description = kwargs["text"]
41 description = description
43 growleeConnection.sendNotification(title="Dreambox", description=description, priority=priority, timeout=timeout, id=id)
45 class GrowleeConnection:
49 def sendNotification(self, title="Dreambox", description='', priority=-1, timeout=-1, id=""):
50 for connection, host in self.connections:
52 level = int(host.level.value)
56 if connection and id not in host.blacklist.value and not priority < level:
57 connection.sendNotification(title=title, description=description, priority=priority, timeout=timeout)
63 for host in config.plugins.growlee.hosts:
64 if not (host.enable_outgoing.value or host.enable_incoming.value):
67 proto = host.protocol.value
69 from Prowl import ProwlAPI
70 connection = ProwlAPI(host)
71 elif proto == "growl":
72 from GrowlTalk import GrowlTalkAbstraction
73 connection = GrowlTalkAbstraction(host)
74 elif proto == "snarl":
75 from SNP import SnarlNetworkProtocolAbstraction
76 connection = SnarlNetworkProtocolAbstraction(host)
77 else: # proto == "syslog":
78 from Syslog import SyslogAbstraction
79 connection = SyslogAbstraction(host)
81 self.connections.append((connection, host))
83 def maybeClose(self, resOrFail, defer = None):
86 if defer: defer.callback(True)
91 for connection, host in self.connections:
95 d.addBoth(self.maybeClose, defer = defer)
96 del self.connections[:]
99 reactor.callLater(1, defer, True)
102 growleeConnection = GrowleeConnection()