1 from __future__ import print_function
3 # To check if in Standby
9 # To see if in Timespan and to determine begin of timespan
10 from time import localtime, mktime, time, strftime
13 from Components.config import config
15 def checkTimespan(begin, end):
19 # Check if we span a day
20 if begin[0] > end[0] or (begin[0] == end[0] and begin[1] >= end[1]):
21 # Check if begin of event is later than our timespan starts
22 if time.tm_hour > begin[0] or (time.tm_hour == begin[0] and time.tm_min >= begin[1]):
23 # If so, event is in our timespan
25 # Check if begin of event is earlier than our timespan end
26 if time.tm_hour < end[0] or (time.tm_hour == end[0] and time.tm_min <= end[1]):
27 # If so, event is in our timespan
31 # Check if event begins earlier than our timespan starts
32 if time.tm_hour < begin[0] or (time.tm_hour == begin[0] and time.tm_min < begin[1]):
33 # Its out of our timespan then
35 # Check if event begins later than our timespan ends
36 if time.tm_hour > end[0] or (time.tm_hour == end[0] and time.tm_min > end[1]):
37 # Its out of our timespan then
41 class EPGRefreshTimerEntry(timer.TimerEntry):
43 def __init__(self, begin, tocall, nocheck = False):
44 timer.TimerEntry.__init__(self, int(begin), int(begin))
46 self.function = tocall
47 self.nocheck = nocheck
49 self.state = self.StatePrepared
51 def getNextActivation(self):
52 # We delay our activation so we won't rush into reprocessing a repeating one
56 if self.state == self.StateWaiting:
57 # Check if in timespan
58 if checkTimespan(config.plugins.epgrefresh.begin.value, config.plugins.epgrefresh.end.value):
59 print("[EPGRefresh] In Timespan, will check if we're in Standby and have no Recordings running next")
60 # Do we realy want to check nav?
61 from NavigationInstance import instance
62 if config.plugins.epgrefresh.force.value or (Screens.Standby.inStandby and instance is not None and not instance.RecordTimer.isRecording()):
65 print("[EPGRefresh] Box still in use, rescheduling")
68 self.begin = time() + config.plugins.epgrefresh.delay_standby.value*60
71 print("[EPGRefresh] Not in timespan, ending timer")
72 self.state = self.StateEnded
74 elif self.state == self.StateRunning:
80 self.state = self.StateWaiting
81 self.cancelled = False
84 def timeChanged(self):
85 if self.nocheck and self.state < self.StateRunning:
86 self.state = self.StatePrepared
93 "<EPGRefreshTimerEntry (",
95 strftime("%c", localtime(self.begin)),
102 class EPGRefreshTimer(timer.Timer):
104 timer.Timer.__init__(self)
106 def remove(self, entry):
107 print("[EPGRefresh] Timer removed " + str(entry))
110 entry.repeated = False
113 # this sets the end time to current time, so timer will be stopped.
116 if entry.state != entry.StateEnded:
117 self.timeChanged(entry)
119 print("state: ", entry.state)
120 print("in processed: ", entry in self.processed_timers)
121 print("in running: ", entry in self.timer_list)
122 # now the timer should be in the processed_timers list. remove it from there.
123 self.processed_timers.remove(entry)
125 def setRefreshTimer(self, tocall):
128 # XXX: basic workaround if the clock is not yet set
130 if now.tm_year > 2011:
133 (year, now.tm_mon, now.tm_mday,
134 config.plugins.epgrefresh.begin.value[0],
135 config.plugins.epgrefresh.begin.value[1],
136 0, now.tm_wday, now.tm_yday, now.tm_isdst)
139 # If the last scan was finished before our timespan begins/began and
140 # timespan began in the past fire the timer once (timer wouldn't do so
142 if config.plugins.epgrefresh.lastscan.value < begin and begin < time():
145 refreshTimer = EPGRefreshTimerEntry(begin, tocall, nocheck = True)
149 refreshTimer.setRepeated(i)
152 # We can be sure that whenever this function is called the timer list
153 # was wiped, so just add a new timer
154 self.addTimerEntry(refreshTimer)
156 def add(self, entry):
158 print("[EPGRefresh] Timer added " + str(entry))
159 self.addTimerEntry(entry)
165 return len(self.timer_list) > 0
167 epgrefreshtimer = EPGRefreshTimer()