AutoPoller.py: fix missing import
[enigma2-plugins.git] / autotimer / src / AutoPoller.py
1 # Timer
2 from enigma import eTimer
3
4 # Config
5 from Components.config import config
6
7 # Notifications
8 from Tools.FuzzyDate import FuzzyTime
9 from Tools.Notifications import AddPopup
10 from Screens.MessageBox import MessageBox
11 NOTIFICATIONID = 'AutoTimerConflictEncounteredNotification'
12
13 class AutoPoller:
14         """Automatically Poll AutoTimer"""
15
16         def __init__(self):
17                 # Init Timer
18                 self.timer = eTimer()
19
20         def start(self, initial = True):
21                 if initial:
22                         delay = 2
23                 else:
24                         delay = config.plugins.autotimer.interval.value*3600
25
26                 if self.query not in self.timer.callback:
27                         self.timer.callback.append(self.query)
28                 self.timer.startLongTimer(delay)
29
30         def stop(self):
31                 if self.query in self.timer.callback:
32                         self.timer.callback.remove(self.query)
33                 self.timer.stop()
34
35         def query(self):
36                 from plugin import autotimer
37
38                 # Ignore any program errors
39                 try:
40                         ret = autotimer.parseEPG()
41                 except Exception:
42                         # Dump error to stdout
43                         import traceback, sys
44                         traceback.print_exc(file=sys.stdout)
45                 else:
46                         conflicts = ret[4]
47                         if conflicts and config.plugins.autotimer.notifconflict.value:
48                                 AddPopup(
49                                         _("%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                                         MessageBox.TYPE_INFO,
51                                         5,
52                                         NOTIFICATIONID
53                                 )
54
55                 self.timer.startLongTimer(config.plugins.autotimer.interval.value*3600)
56