1 # To check if in Standby
7 # To see if in Timespan and to determine begin of timespan
8 from time import localtime, mktime, time, strftime
11 from Components.config import config
13 def checkTimespan(begin, end):
17 # Check if we span a day
18 if begin[0] > end[0] or (begin[0] == end[0] and begin[1] >= end[1]):
19 # Check if begin of event is later than our timespan starts
20 if time.tm_hour > begin[0] or (time.tm_hour == begin[0] and time.tm_min >= begin[1]):
21 # If so, event is in our timespan
23 # Check if begin of event is earlier than our timespan end
24 if time.tm_hour < end[0] or (time.tm_hour == end[0] and time.tm_min <= end[1]):
25 # If so, event is in our timespan
29 # Check if event begins earlier than our timespan starts
30 if time.tm_hour < begin[0] or (time.tm_hour == begin[0] and time.tm_min < begin[1]):
31 # Its out of our timespan then
33 # Check if event begins later than our timespan ends
34 if time.tm_hour > end[0] or (time.tm_hour == end[0] and time.tm_min > end[1]):
35 # Its out of our timespan then
39 class EPGRefreshTimerEntry(timer.TimerEntry):
41 def __init__(self, begin, tocall, nocheck = False):
42 timer.TimerEntry.__init__(self, int(begin), int(begin))
44 self.function = tocall
45 self.nocheck = nocheck
47 self.state = self.StatePrepared
49 def getNextActivation(self):
50 # We delay our activation so we won't rush into reprocessing a repeating one
54 if self.state == self.StateWaiting:
55 # Check if in timespan
56 if checkTimespan(config.plugins.epgrefresh.begin.value, config.plugins.epgrefresh.end.value):
57 print "[EPGRefresh] In Timespan, will check if we're in Standby and have no Recordings running next"
58 # Do we realy want to check nav?
59 from NavigationInstance import instance
60 if config.plugins.epgrefresh.force.value or (Screens.Standby.inStandby and instance is not None and not instance.RecordTimer.isRecording()):
63 print "[EPGRefresh] Box still in use, rescheduling"
66 self.begin = time() + config.plugins.epgrefresh.delay_standby.value*60
69 print "[EPGRefresh] Not in timespan, ending timer"
70 self.state = self.StateEnded
72 elif self.state == self.StateRunning:
78 self.state = self.StateWaiting
79 self.cancelled = False
82 def timeChanged(self):
83 if self.nocheck and self.state < self.StateRunning:
84 self.state = self.StatePrepared
91 "<EPGRefreshTimerEntry (",
93 strftime("%c", localtime(self.begin)),
100 class EPGRefreshTimer(timer.Timer):
102 timer.Timer.__init__(self)
104 def remove(self, entry):
105 print "[EPGRefresh] Timer removed " + str(entry)
108 entry.repeated = False
111 # this sets the end time to current time, so timer will be stopped.
114 if entry.state != entry.StateEnded:
115 self.timeChanged(entry)
117 print "state: ", entry.state
118 print "in processed: ", entry in self.processed_timers
119 print "in running: ", entry in self.timer_list
120 # now the timer should be in the processed_timers list. remove it from there.
121 self.processed_timers.remove(entry)
123 def setRefreshTimer(self, tocall):
126 # XXX: basic workaround if the clock is not yet set
128 if now.tm_year > 2009:
131 (year, now.tm_mon, now.tm_mday,
132 config.plugins.epgrefresh.begin.value[0],
133 config.plugins.epgrefresh.begin.value[1],
134 0, now.tm_wday, now.tm_yday, now.tm_isdst)
137 # If the last scan was finished before our timespan begins/began and
138 # timespan began in the past fire the timer once (timer wouldn't do so
140 if config.plugins.epgrefresh.lastscan.value < begin and begin < time():
143 refreshTimer = EPGRefreshTimerEntry(begin, tocall, nocheck = True)
147 refreshTimer.setRepeated(i)
150 # We can be sure that whenever this function is called the timer list
151 # was wiped, so just add a new timer
152 self.addTimerEntry(refreshTimer)
154 def add(self, entry):
156 print "[EPGRefresh] Timer added " + str(entry)
157 self.addTimerEntry(entry)
163 return len(self.timer_list) > 0
165 epgrefreshtimer = EPGRefreshTimer()