+ f.write(rec_ref.toString() + "\n")
+ f.write(self.name + "\n")
+ f.write(self.description + "\n")
+ f.write(str(self.begin) + "\n")
+ f.close()
+ except IOError:
+ self.log(4, "failed to write meta information")
+ self.record_service = None
+ return False
+ return True
+
+ def do_backoff(self):
+ if self.backoff == 0:
+ self.backoff = 5
+ else:
+ self.backoff *= 2
+ if self.backoff > 100:
+ self.backoff = 100
+ self.log(10, "backoff: retry in %d seconds" % self.backoff)
+
+ def activate(self):
+ next_state = self.state + 1
+ self.log(5, "activating state %d" % next_state)
+
+ if next_state == self.StatePrepared:
+ if self.tryPrepare():
+ self.log(6, "prepare ok, waiting for begin")
+ # fine. it worked, resources are allocated.
+ self.next_activation = self.begin
+ self.backoff = 0
+ return True
+
+ self.log(7, "prepare failed")
+ if self.first_try_prepare:
+ self.first_try_prepare = False
+ if not config.recording.asktozap.value:
+ self.log(8, "asking user to zap away")
+ Notifications.AddNotificationWithCallback(self.failureCB, MessageBox, _("A timer failed to record!\nDisable TV and try again?\n"), timeout=20)
+ else: # zap without asking
+ self.log(9, "zap without asking")
+ Notifications.AddNotification(MessageBox, _("In order to record a timer, the TV was switched to the recording service!\n"), type=MessageBox.TYPE_INFO, timeout=20)
+ self.failureCB(True)
+
+ self.do_backoff()
+ # retry
+ self.start_prepare = time.time() + self.backoff
+ return False
+ elif next_state == self.StateRunning:
+ # if this timer has been cancelled, just go to "end" state.
+ if self.cancelled:
+ return True
+
+ if self.justplay:
+ self.log(11, "zapping")
+ NavigationInstance.instance.playService(self.service_ref.ref)
+ return True
+ else:
+ self.log(11, "start recording")
+ record_res = self.record_service.start()