1 from __future__ import print_function
4 from enigma import eTimer, ePythonMessagePump
7 from Components.config import config
10 from Tools.FuzzyDate import FuzzyTime
11 from Tools.Notifications import AddPopup
12 from Screens.MessageBox import MessageBox
14 NOTIFICATIONID = 'AutoTimerConflictEncounteredNotification'
15 SIMILARNOTIFICATIONID = 'AutoTimerSimilarUsedNotification'
17 from threading import Thread, Semaphore
19 from Queue import Queue
20 except ImportError as ie:
21 from queue import Queue
23 class AutoPollerThread(Thread):
24 """Background thread where the EPG is parsed (unless initiated by the user)."""
27 self.__semaphore = Semaphore(0)
28 self.__queue = Queue(1)
29 self.__pump = ePythonMessagePump()
30 self.__pump.recv_msg.get().append(self.gotThreadMsg)
31 self.__timer = eTimer()
32 self.__timer.callback.append(self.timeout)
36 self.__semaphore.release()
38 def gotThreadMsg(self, msg):
39 """Create Notifications if there is anything to display."""
40 ret = self.__queue.get()
42 if conflicts and config.plugins.autotimer.notifconflict.value:
44 _("%d conflict(s) encountered when trying to add new timers:\n%s") % (len(conflicts), '\n'.join([_("%s: %s at %s") % (x[4], x[0], FuzzyTime(x[2])) for x in conflicts])),
50 if similars and config.plugins.autotimer.notifsimilar.value:
52 _("%d conflict(s) solved with similar timer(s):\n%s") % (len(similars), '\n'.join([_("%s: %s at %s") % (x[4], x[0], FuzzyTime(x[2])) for x in similars])),
58 def start(self, initial=True):
59 # NOTE: we wait for 10 seconds on initial launch to not delay enigma2 startup time
60 if initial: delay = 10
61 else: delay = config.plugins.autotimer.interval.value*3600
63 self.__timer.startLongTimer(delay)
69 self.__semaphore.release()
74 self.__semaphore.acquire()
75 # NOTE: we have to check this here and not using the while to prevent the parser to be started on shutdown
76 if not self.running: break
78 from plugin import autotimer
79 # Ignore any program errors
81 self.__queue.put(autotimer.parseEPG())
84 # Dump error to stdout
86 traceback.print_exc(file=sys.stdout)
88 self.__timer.startLongTimer(config.plugins.autotimer.interval.value*3600)
91 """Manages actual thread which does the polling. Used for convenience."""
94 self.thread = AutoPollerThread()
96 def start(self, initial=True):
97 self.thread.start(initial=initial)
101 # NOTE: while we don't need to join the thread, we should do so in case it's currently parsining