try to avoid multiple refreshs per day,
authorMoritz Venn <ritzmo@users.schwerkraft.elitedvb.net>
Sat, 17 Nov 2007 10:46:41 +0000 (10:46 +0000)
committerMoritz Venn <ritzmo@users.schwerkraft.elitedvb.net>
Sat, 17 Nov 2007 10:46:41 +0000 (10:46 +0000)
fix bsod when doing a forced refresh

epgrefresh/src/EPGRefresh.py
epgrefresh/src/EPGRefreshConfiguration.py
epgrefresh/src/EPGRefreshTimer.py
epgrefresh/src/plugin.py

index a3e846a..23f2d42 100644 (file)
@@ -31,6 +31,7 @@ class EPGRefresh:
                self.previousService = None
                self.forcedScan = False
                self.session = None
+               self.beginOfTimespan = 0
 
                # Mtime of configuration files
                self.configMtime = -1
@@ -78,7 +79,7 @@ class EPGRefresh:
                # Close file
                file.close()
 
-       def refresh(self, session = None):
+       def forceRefresh(self, session = None):
                print "[EPGRefresh] Forcing start of EPGRefresh"
                if session is not None:
                        self.session = session
@@ -159,6 +160,9 @@ class EPGRefresh:
                self.refresh()
 
        def cleanUp(self):
+               config.plugins.epgrefresh.lastscan.value = int(time())
+               config.plugins.epgrefresh.lastscan.save()
+
                # shutdown if we're supposed to go to deepstandby and not recording
                if not self.forcedScan and config.plugins.epgrefresh.afterevent.value and not Screens.Standby.inTryQuitMainloop:
                        self.session.open(
@@ -174,21 +178,28 @@ class EPGRefresh:
                        self.session.nav.playService(self.previousService)
 
        def refresh(self):
-               # Walk Services
-               if self.forcedScan or config.plugins.epgrefresh.force.value or (Screens.Standby.inStandby and not self.session.nav.RecordTimer.isRecording()):
+               if self.forcedScan:
                        self.nextService()
                else:
+                       # Abort if a scan finished later than our begin of timespan
+                       if self.beginOfTimespan < config.plugins.epgrefresh.lastscan.value:
+                               return
+                       if config.plugins.epgrefresh.force.value or (Screens.Standby.inStandby and not self.session.nav.RecordTimer.isRecording()):
+                               self.nextService()
                        # We don't follow our rules here - If the Box is still in Standby and not recording we won't reach this line 
-                       if not checkTimespan(config.plugins.epgrefresh.begin.value, config.plugins.epgrefresh.end.value):
-                               print "[EPGRefresh] Gone out of timespan while refreshing, sorry!"
-                               self.cleanUp()
                        else:
-                               print "[EPGRefresh] Box no longer in Standby or Recording started, rescheduling"
+                               if not checkTimespan(config.plugins.epgrefresh.begin.value, config.plugins.epgrefresh.end.value):
+                                       print "[EPGRefresh] Gone out of timespan while refreshing, sorry!"
+                                       self.cleanUp()
+                               else:
+                                       print "[EPGRefresh] Box no longer in Standby or Recording started, rescheduling"
 
-                               # Recheck later
-                               epgrefreshtimer.add(EPGRefreshTimerEntry(time() + config.plugins.epgrefresh.delay_standby.value*60, self.refresh, nocheck = True))
+                                       # Recheck later
+                                       epgrefreshtimer.add(EPGRefreshTimerEntry(time() + config.plugins.epgrefresh.delay_standby.value*60, self.refresh, nocheck = True))
 
        def createWaitTimer(self):
+               self.beginOfTimespan = time()
+
                # Add wait timer to epgrefreshtimer
                epgrefreshtimer.add(EPGRefreshTimerEntry(time() + 3, self.prepareRefresh))
 
@@ -196,17 +207,16 @@ class EPGRefresh:
                # DEBUG
                print "[EPGRefresh] Maybe zap to next service"
 
-               # Check if more Services present
-               if len(self.scanServices):
+               try:
                        # Get next reference
-                       service = self.scanServices.pop()
+                       service = self.scanServices.pop(0)
 
                        # Play next service
                        self.session.nav.playService(service)
 
                        # Start Timer
                        epgrefreshtimer.add(EPGRefreshTimerEntry(time() + config.plugins.epgrefresh.interval.value*60, self.refresh, nocheck = True))
-               else:
+               except IndexError:
                        # Debug
                        print "[EPGRefresh] Done refreshing EPG"
 
index 0fa73b3..4e689bc 100644 (file)
@@ -78,7 +78,7 @@ class EPGRefreshConfiguration(Screen, ConfigListScreen):
        def forceRefresh(self):
                epgrefresh.services = Set(self.servicelist)
                # TODO: maybe we need to save the configuration here...
-               epgrefresh.refresh(self.session)
+               epgrefresh.forceRefresh(self.session)
 
        def editChannels(self):
                self.session.openWithCallback(
index 96641f8..ad4ddf1 100644 (file)
@@ -50,10 +50,8 @@ class EPGRefreshTimerEntry(timer.TimerEntry):
 
        def activate(self):
                if self.state == self.StateRunning:
-                       print "[EPGRefresh] Timer activated"
                        # Just execute function and signalize success if told to
                        if self.nocheck:
-                               print "[EPGRefresh] Timer is not checking but running function immediately"
                                self.function()
                                return True
 
@@ -72,11 +70,8 @@ class EPGRefreshTimerEntry(timer.TimerEntry):
                                        self.begin = time() + config.plugins.epgrefresh.delay_standby.value*60
                                        return False
                        else:
-                               print "[EPGRefresh] Not in timespan, rescheduling"
-
-                               # Recheck later
-                               self.begin = config.plugins.epgrefresh.delay_standby.value*60
-                               return False
+                               print "[EPGRefresh] Not in timespan, ending timer"
+                               return True
 
                return True
 
@@ -113,8 +108,10 @@ class EPGRefreshTimer(timer.Timer):
                begin[4] = config.plugins.epgrefresh.begin.value[1]
                begin = mktime(begin)
 
-               # Also call function when begin lies in the past (timer won't do so)
-               if begin < time():
+               # If the last scan was finished before our timespan begins/began and
+               # timespan began in the past fire the timer once (timer wouldn't do so
+               # by itself)
+               if config.plugins.epgrefresh.lastscan.value < begin and begin < time():
                        tocall()
 
                refreshTimer = EPGRefreshTimerEntry(begin, tocall, nocheck = True)
index 6eb5ef1..8bfb827 100644 (file)
@@ -24,6 +24,7 @@ config.plugins.epgrefresh.delay_standby = ConfigInteger(default = 10, limits=(1,
 config.plugins.epgrefresh.inherit_autotimer = ConfigEnableDisable(default = False)
 config.plugins.epgrefresh.afterevent = ConfigEnableDisable(default = False)
 config.plugins.epgrefresh.force = ConfigEnableDisable(default = False)
+config.plugins.epgrefresh.lastscan = ConfigInteger(default = 0)
 
 # Plugin
 from EPGRefresh import epgrefresh