Example #1
0
 def standbyTimeout(self):
     if config.usage.standby_to_shutdown_timer_blocktime.value:
         curtime = localtime(time())
         if curtime.tm_year > 1970:  #check if the current time is valid
             curtime = (curtime.tm_hour, curtime.tm_min, curtime.tm_sec)
             begintime = tuple(
                 config.usage.standby_to_shutdown_timer_blocktime_begin.
                 value)
             endtime = tuple(
                 config.usage.standby_to_shutdown_timer_blocktime_end.value)
             if begintime <= endtime and (
                     curtime >= begintime
                     and curtime < endtime) or begintime > endtime and (
                         curtime >= begintime or curtime < endtime):
                 duration = (endtime[0] * 3600 + endtime[1] * 60) - (
                     curtime[0] * 3600 + curtime[1] * 60 + curtime[2])
                 if duration:
                     if duration < 0:
                         duration += 24 * 3600
                     self.standbyTimeoutTimer.startLongTimer(duration)
                     return
     if self.session.screen[
             "TunerInfo"].tuner_use_mask or internalHDDNotSleeping():
         self.standbyTimeoutTimer.startLongTimer(600)
     else:
         from RecordTimer import RecordTimerEntry
         RecordTimerEntry.TryQuitMainloop()
Example #2
0
    def standbyTimeout(self):
        if config.usage.standby_to_shutdown_timer_blocktime.value:
            curtime = localtime(time())
            if curtime.tm_year > 1970:  # check if the current time is valid
                curtime = (curtime.tm_hour, curtime.tm_min, curtime.tm_sec)
                begintime = tuple(config.usage.standby_to_shutdown_timer_blocktime_begin.value)
                endtime = tuple(config.usage.standby_to_shutdown_timer_blocktime_end.value)
                if (
                    begintime <= endtime
                    and (curtime >= begintime and curtime < endtime)
                    or begintime > endtime
                    and (curtime >= begintime or curtime < endtime)
                ):
                    duration = (endtime[0] * 3600 + endtime[1] * 60) - (
                        curtime[0] * 3600 + curtime[1] * 60 + curtime[2]
                    )
                    if duration:
                        if duration < 0:
                            duration += 24 * 3600
                        self.standbyTimeoutTimer.startLongTimer(duration)
                        return
        if self.session.screen["TunerInfo"].tuner_use_mask or internalHDDNotSleeping():
            self.standbyTimeoutTimer.startLongTimer(600)
        else:
            from RecordTimer import RecordTimerEntry

            RecordTimerEntry.TryQuitMainloop()
Example #3
0
def getReasons(session):
    recordings = session.nav.getRecordings()
    jobs = len(job_manager.getPendingJobs())
    reasons = []
    next_rec_time = -1
    if not recordings:
        next_rec_time = session.nav.RecordTimer.getNextRecordingTime()
    if recordings or (next_rec_time > 0 and (next_rec_time - time()) < 360):
        reasons.append(
            _("Recording(s) are in progress or coming up in few seconds!"))
    if jobs:
        if jobs == 1:
            job = job_manager.getPendingJobs()[0]
            reasons.append("%s: %s (%d%%)" %
                           (job.getStatustext(), job.name,
                            int(100 * job.progress / float(job.end))))
        else:
            reasons.append(
                (ngettext("%d job is running in the background!",
                          "%d jobs are running in the background!", jobs) %
                 jobs))
    if eStreamServer.getInstance().getConnectedClients() or StreamServiceList:
        reasons.append(_("Client is streaming from this box!"))
    if not reasons and internalHDDNotSleeping():
        reasons.append(_("Harddisk is not in sleepmode it could be in use!"))
    return "\n".join(reasons)
Example #4
0
 def doPowerOffRun(self):
     if self.session:
         if self.wait_nextday:
             if time() >= self.nextday_time:
                 print "[PowerOffTimer] Cancel waiting shutdown, over limit, set next day."
                 self.powerStateTimerChanged()
                 return
         try_poweroff = True
         if isExternalToolsRunning():
             try_poweroff = False
         if RecordTimerEntry.wasInDeepStandby:
             try_poweroff = False
         if try_poweroff:
             if not self.session.nav.getRecordings():
                 rec_time = self.session.nav.RecordTimer.getNextRecordingTime(
                 )
                 if rec_time > 0 and (rec_time - time()) < 360:
                     try_poweroff = False
             else:
                 try_poweroff = False
         if try_poweroff:
             jobs = len(job_manager.getPendingJobs())
             if Standby.inStandby is None:
                 if not config.usage.poweroff_force.value:
                     try_poweroff = False
             elif jobs or self.session.screen[
                     "TunerInfo"].tuner_use_mask or internalHDDNotSleeping(
                     ):
                 try_poweroff = False
         if try_poweroff:
             if Standby.inStandby is None:
                 reason = _("Power off timer") + '\n\n'
                 if jobs:
                     if jobs == 1:
                         job = job_manager.getPendingJobs()[0]
                         reason += "%s: %s (%d%%)\n" % (
                             job.getStatustext(), job.name,
                             int(100 * job.progress / float(job.end)))
                     else:
                         reason += (ngettext(
                             "%d job is running in the background!",
                             "%d jobs are running in the background!", jobs)
                                    % jobs) + '\n'
                 if self.session.nav.getClientsStreaming():
                     clients = ClientsStreaming("SHORT_ALL")
                     reason += clients.getText() + '\n'
                 self.session.openWithCallback(self.doPowerOffAnswer,
                                               MessageBox,
                                               reason +
                                               _("Really shutdown now?"),
                                               type=MessageBox.TYPE_YESNO,
                                               timeout=180)
             else:
                 self.doPowerOffAnswer(True)
         else:
             print "[PowerOffTimer] Don't shutdown, box in use. Wait 5 min..."
             self.doPowerOffTimer.start(self.wait_nextday_time * 1000, True)
             self.wait_nextday = True
Example #5
0
def getReasons(session):
	recordings = session.nav.getRecordings()
	jobs = len(job_manager.getPendingJobs())
	reasons = []
	next_rec_time = -1
	if not recordings:
		next_rec_time = session.nav.RecordTimer.getNextRecordingTime()
	if recordings or (next_rec_time > 0 and (next_rec_time - time()) < 360):
		reasons.append(_("Recording(s) are in progress or coming up in few seconds!"))
	if jobs:
		if jobs == 1:
			job = job_manager.getPendingJobs()[0]
			reasons.append("%s: %s (%d%%)" % (job.getStatustext(), job.name, int(100*job.progress/float(job.end))))
		else:
			reasons.append((ngettext("%d job is running in the background!", "%d jobs are running in the background!", jobs) % jobs))
	if eStreamServer.getInstance().getConnectedClients() or StreamServiceList:
			reasons.append(_("Client is streaming from this box!"))
	if not reasons and internalHDDNotSleeping():
			reasons.append(_("Harddisk is not in sleepmode it could be in use!"))
	return "\n".join(reasons)
Example #6
0
	def __init__(self, session, retvalue=1, timeout=-1, default_yes = False):
		self.retval = retvalue
		self.connected = False
		reason = getReasons(session)
		if reason and not(internalHDDNotSleeping() and retvalue in (3, 6, 42)):
			text = { 1: _("Really shutdown your %s %s now?") % (MACHINEBRAND, MACHINENAME),
				2: _("Really reboot your %s %s now?") % (MACHINEBRAND, MACHINENAME),
				3: _("Really restart your %s %s now?") % (MACHINEBRAND, MACHINENAME),
				4: _("Really upgrade the frontprocessor and reboot now?"),
				42: _("Really upgrade your %s %s and reboot now?") % (MACHINEBRAND, MACHINENAME),
				43: _("Really WOL now?") }.get(retvalue, _("Invalid reason"))
			MessageBox.__init__(self, session, "%s\n%s" % (reason, text), type = MessageBox.TYPE_YESNO, timeout = timeout, default = default_yes)
			self.skinName = "MessageBoxSimple"
			session.nav.record_event.append(self.getRecordEvent)
			self.connected = True
			self.onShow.append(self.__onShow)
			self.onHide.append(self.__onHide)
		else:
			self.skin = """<screen position="0,0" size="0,0"/>"""
			Screen.__init__(self, session)
			self.close(True)
Example #7
0
 def __init__(self, session, retvalue=1, timeout=-1, default_yes=False):
     self.retval = retvalue
     self.connected = False
     reason = getReasons(session)
     if reason and not (internalHDDNotSleeping()
                        and retvalue in (3, 6, 42)):
         text = {
             1:
             _("Really shutdown your %s %s now?") %
             (MACHINEBRAND, MACHINENAME),
             2:
             _("Really reboot your %s %s now?") %
             (MACHINEBRAND, MACHINENAME),
             3:
             _("Really restart your %s %s now?") %
             (MACHINEBRAND, MACHINENAME),
             4:
             _("Really upgrade the frontprocessor and reboot now?"),
             42:
             _("Really upgrade your %s %s and reboot now?") %
             (MACHINEBRAND, MACHINENAME),
             43:
             _("Really WOL now?")
         }.get(retvalue, _("Invalid reason"))
         MessageBox.__init__(self,
                             session,
                             "%s\n%s" % (reason, text),
                             type=MessageBox.TYPE_YESNO,
                             timeout=timeout,
                             default=default_yes)
         self.skinName = "MessageBoxSimple"
         session.nav.record_event.append(self.getRecordEvent)
         self.connected = True
         self.onShow.append(self.__onShow)
         self.onHide.append(self.__onHide)
     else:
         self.skin = """<screen position="0,0" size="0,0"/>"""
         Screen.__init__(self, session)
         self.close(True)
Example #8
0
	def activate(self):
		global DSsave, RSsave, RBsave, aeDSsave, wasPowerTimerWakeup, wakeupEnd

		next_state = self.state + 1
		self.log(5, "activating state %d" % next_state)

		if next_state == 1 and (self.timerType == TIMERTYPE.AUTOSTANDBY or self.timerType == TIMERTYPE.AUTODEEPSTANDBY):
			eActionMap.getInstance().bindAction('', -0x7FFFFFFF, self.keyPressed)
			self.begin = time() + int(self.autosleepdelay)*60
			if self.end <= self.begin:
				self.end = self.begin

		if next_state == self.StatePrepared:
			self.log(6, "prepare ok, waiting for begin")
			self.next_activation = self.begin
			self.backoff = 0
			return True

		elif next_state == self.StateRunning:

			if os.path.exists("/tmp/was_powertimer_wakeup") and not wasPowerTimerWakeup:
				wasPowerTimerWakeup = int(open("/tmp/was_powertimer_wakeup", "r").read()) and True or False

			if wasPowerTimerWakeup and time() >= wakeupEnd:
				resetTimerWakeup()

			# if this timer has been cancelled, just go to "end" state.
			if self.cancelled:
				return True

			if self.failed:
				return True

			if self.timerType == TIMERTYPE.WAKEUP:
				if Screens.Standby.inStandby:
					Screens.Standby.inStandby.Power()
				return True

			elif self.timerType == TIMERTYPE.WAKEUPTOSTANDBY:
				return True

			elif self.timerType == TIMERTYPE.STANDBY:
				if not Screens.Standby.inStandby: # not already in standby
					Notifications.AddNotificationWithCallback(self.sendStandbyNotification, MessageBox, _("A finished powertimer wants to set your\n%s %s to standby. Do that now?") % (getMachineBrand(), getMachineName()), timeout = 180)
				return True

			elif self.timerType == TIMERTYPE.AUTOSTANDBY:
				if not Screens.Standby.inStandby: # not already in standby
					Notifications.AddNotificationWithCallback(self.sendStandbyNotification, MessageBox, _("A finished powertimer wants to set your\n%s %s to standby. Do that now?") % (getMachineBrand(), getMachineName()), timeout = 180)
					if self.autosleeprepeat == "once":
						eActionMap.getInstance().unbindAction('', self.keyPressed)
						return True
					else:
						self.begin = time() + int(self.autosleepdelay)*60
						if self.end <= self.begin:
							self.end = self.begin
				else:
					self.begin = time() + int(self.autosleepdelay)*60
					if self.end <= self.begin:
						self.end = self.begin

			elif self.timerType == TIMERTYPE.AUTODEEPSTANDBY:
				if wasPowerTimerWakeup or (NavigationInstance.instance.RecordTimer.isRecording() or abs(NavigationInstance.instance.RecordTimer.getNextRecordingTime() - time()) <= 900 or abs(NavigationInstance.instance.RecordTimer.getNextZapTime() - time()) <= 900) or (self.autosleepinstandbyonly == 'yes' and not Screens.Standby.inStandby) or (self.autosleepinstandbyonly == 'yes' and Screens.Standby.inStandby and (self.session.screen["TunerInfo"].tuner_use_mask or internalHDDNotSleeping())):
					self.do_backoff()
					# retry
					self.begin = time() + self.backoff
					if self.end <= self.begin:
						self.end = self.begin
					return False
				if not Screens.Standby.inTryQuitMainloop: # not a shutdown messagebox is open
					if self.autosleeprepeat == "once":
						self.disabled = True
					if Screens.Standby.inStandby: # in standby
						print "[PowerTimer] quitMainloop #1"
						quitMainloop(1)
						return True
					else:
						Notifications.AddNotificationWithCallback(self.sendTryQuitMainloopNotification, MessageBox, _("A finished powertimer wants to shutdown your %s %s.\nDo that now?") % (getMachineBrand(), getMachineName()), timeout = 180)
						if self.autosleeprepeat == "once":
							eActionMap.getInstance().unbindAction('', self.keyPressed)
							return True
						else:
							self.begin = time() + int(self.autosleepdelay)*60
							if self.end <= self.begin:
								self.end = self.begin

			elif self.timerType == TIMERTYPE.DEEPSTANDBY:
				if wasPowerTimerWakeup or NavigationInstance.instance.RecordTimer.isRecording() or abs(NavigationInstance.instance.RecordTimer.getNextRecordingTime() - time()) <= 900 or abs(NavigationInstance.instance.RecordTimer.getNextZapTime() - time()) <= 900:
					if int(self.repeated) > 0 and not DSsave:
						self.DSbegin = self.begin
						self.DSend = self.end
						DSsave = True
					self.do_backoff()
					# retry
					self.begin = time() + self.backoff
					if self.end <= self.begin:
						self.end = self.begin
					return False
				if not Screens.Standby.inTryQuitMainloop: # not a shutdown messagebox is open
					if DSsave:
						DSsave = False
						self.begin = self.DSbegin
						self.end = self.DSend
					if Screens.Standby.inStandby: # in standby
						print "[PowerTimer] quitMainloop #2"
						quitMainloop(1)
					else:
						Notifications.AddNotificationWithCallback(self.sendTryQuitMainloopNotification, MessageBox, _("A finished powertimer wants to shutdown your %s %s.\nDo that now?") % (getMachineBrand(), getMachineName()), timeout = 180)
				return True

			elif self.timerType == TIMERTYPE.REBOOT:
				if wasPowerTimerWakeup or NavigationInstance.instance.RecordTimer.isRecording() or abs(NavigationInstance.instance.RecordTimer.getNextRecordingTime() - time()) <= 900 or abs(NavigationInstance.instance.RecordTimer.getNextZapTime() - time()) <= 900:
					if int(self.repeated) > 0 and not RBsave:
						self.RBbegin = self.begin
						self.RBend = self.end
						RBsave = True
					self.do_backoff()
					# retry
					self.begin = time() + self.backoff
					if self.end <= self.begin:
						self.end = self.begin
					return False
				if not Screens.Standby.inTryQuitMainloop: # not a shutdown messagebox is open
					if RBsave:
						RBsave = False
						self.begin = self.RBbegin
						self.end = self.RBend
					if Screens.Standby.inStandby: # in standby
						print "[PowerTimer] quitMainloop #3"
						quitMainloop(2)
					else:
						Notifications.AddNotificationWithCallback(self.sendTryToRebootNotification, MessageBox, _("A finished powertimer wants to reboot your %s %s.\nDo that now?") % (getMachineBrand(), getMachineName()), timeout = 180)
				return True

			elif self.timerType == TIMERTYPE.RESTART:
				if wasPowerTimerWakeup or NavigationInstance.instance.RecordTimer.isRecording() or abs(NavigationInstance.instance.RecordTimer.getNextRecordingTime() - time()) <= 900 or abs(NavigationInstance.instance.RecordTimer.getNextZapTime() - time()) <= 900:
					if int(self.repeated) > 0 and not RSsave:
						self.RSbegin = self.begin
						self.RSend = self.end
						RSsave = True
					self.do_backoff()
					# retry
					self.begin = time() + self.backoff
					if self.end <= self.begin:
						self.end = self.begin
					return False
				if not Screens.Standby.inTryQuitMainloop: # not a shutdown messagebox is open
					if RSsave:
						RSsave = False
						self.begin = self.RSbegin
						self.end = self.RSend
					if Screens.Standby.inStandby: # in standby
						print "[PowerTimer] quitMainloop #4"
						quitMainloop(3)
					else:
						Notifications.AddNotificationWithCallback(self.sendTryToRestartNotification, MessageBox, _("A finished powertimer wants to restart the user interface.\nDo that now?"), timeout = 180)
				return True

		elif next_state == self.StateEnded:
			resetTimerWakeup()
			NavigationInstance.instance.PowerTimer.saveTimer()
			if self.afterEvent == AFTEREVENT.STANDBY:
				if not Screens.Standby.inStandby: # not already in standby
					Notifications.AddNotificationWithCallback(self.sendStandbyNotification, MessageBox, _("A finished powertimer wants to set your\n%s %s to standby. Do that now?") % (getMachineBrand(), getMachineName()), timeout = 180)
			elif self.afterEvent == AFTEREVENT.DEEPSTANDBY:
				if NavigationInstance.instance.RecordTimer.isRecording() or abs(NavigationInstance.instance.RecordTimer.getNextRecordingTime() - time()) <= 900 or abs(NavigationInstance.instance.RecordTimer.getNextZapTime() - time()) <= 900:
					if int(self.repeated) > 0 and not aeDSsave:
						self.aeDSbegin = self.begin
						self.aeDSend = self.end
						aeDSsave = True
					self.do_backoff()
					# retry
					self.begin = time() + self.backoff
					if self.end <= self.begin:
						self.end = self.begin
					return False
				if not Screens.Standby.inTryQuitMainloop: # not a shutdown messagebox is open
					if aeDSsave:
						aeDSsave = False
						self.begin = self.aeDSbegin
						self.end = self.aeDSend
					if Screens.Standby.inStandby: # in standby
						print "[PowerTimer] quitMainloop #5"
						quitMainloop(1)
					else:
						Notifications.AddNotificationWithCallback(self.sendTryQuitMainloopNotification, MessageBox, _("A finished power timer wants to shut down\nyour %s %s. Shutdown now?") % (getMachineBrand(), getMachineName()), timeout = 180)
			return True
	def activate(self):
		next_state = self.state + 1
		self.log(5, "Activating state %d." % next_state)
		if next_state == self.StatePrepared and (self.timerType == TIMERTYPE.AUTOSTANDBY or self.timerType == TIMERTYPE.AUTODEEPSTANDBY):
			# This is the first action for an auto* timer.
			# It binds any key press to keyPressed(), which resets the timer delay,
			# and sets the initial delay.
			eActionMap.getInstance().bindAction("", -maxsize - 1, self.keyPressed)
			self.begin = time() + int(self.autosleepdelay) * 60
			if self.end <= self.begin:
				self.end = self.begin
		if next_state == self.StatePrepared:
			self.log(6, "Prepare okay, waiting for begin.")
			self.next_activation = self.begin
			self.backoff = 0
			return True
		elif next_state == self.StateRunning:
			self.wasPowerTimerWakeup = False
			if exists("/tmp/was_powertimer_wakeup"):
				self.wasPowerTimerWakeup = int(open("/tmp/was_powertimer_wakeup", "r").read()) and True or False
				remove("/tmp/was_powertimer_wakeup")
			# If this timer has been cancelled, just go to "end" state.
			if self.cancelled:
				return True
			if self.failed:
				return True
			if self.timerType == TIMERTYPE.WAKEUP:
				if Screens.Standby.inStandby:
					Screens.Standby.inStandby.Power()
				return True
			elif self.timerType == TIMERTYPE.WAKEUPTOSTANDBY:
				return True
			elif self.timerType == TIMERTYPE.STANDBY:
				if not Screens.Standby.inStandby:  # Not already in standby.
					AddNotificationWithUniqueIDCallback(self.sendStandbyNotification, "PT_StateChange", MessageBox, _("A finished powertimer wants to set your receiver to standby. Do that now?"), timeout=180)
				return True
			elif self.timerType == TIMERTYPE.AUTOSTANDBY:
				if NavigationInstance.instance.getCurrentlyPlayingServiceReference() and ("0:0:0:0:0:0:0:0:0" in NavigationInstance.instance.getCurrentlyPlayingServiceReference().toString() or "4097:" in NavigationInstance.instance.getCurrentlyPlayingServiceReference().toString()):
					self.do_backoff()  # Retry.
					return False
				if not Screens.Standby.inStandby:  # Not already in standby.
					AddNotificationWithUniqueIDCallback(self.sendStandbyNotification, "PT_StateChange", MessageBox, _("A finished powertimer wants to set your receiver to standby. Do that now?"), timeout=180)
					if self.autosleeprepeat == "once":
						eActionMap.getInstance().unbindAction("", self.keyPressed)
						return True
					else:
						self.begin = time() + int(self.autosleepdelay) * 60
						if self.end <= self.begin:
							self.end = self.begin
				else:
					self.begin = time() + int(self.autosleepdelay) * 60
					if self.end <= self.begin:
						self.end = self.begin

			elif self.timerType == TIMERTYPE.AUTODEEPSTANDBY:
				# Check for there being any active Movie playback or IPTV channel
				# or any streaming clients before going to Deep Standby.
				# However, it is possible to put the box into Standby with the
				# MoviePlayer still active (it will play if the box is taken out
				# of Standby) - similarly for the IPTV player. This should not
				# prevent a DeepStandby
				# And check for existing or imminent recordings, etc..
				# Also added () around the test and split them across lines
				# to make it clearer what each test is.
				from Components.Converter.ClientsStreaming import ClientsStreaming
				if ((not Screens.Standby.inStandby and NavigationInstance.instance.getCurrentlyPlayingServiceReference() and
					("0:0:0:0:0:0:0:0:0" in NavigationInstance.instance.getCurrentlyPlayingServiceReference().toString() or
					 "4097:" in NavigationInstance.instance.getCurrentlyPlayingServiceReference().toString()
				     ) or
				     (int(ClientsStreaming("NUMBER").getText()) > 0)
				    ) or
				    (NavigationInstance.instance.RecordTimer.isRecording() or
				     abs(NavigationInstance.instance.RecordTimer.getNextRecordingTime() - time()) <= 900 or
				     abs(NavigationInstance.instance.RecordTimer.getNextZapTime() - time()) <= 900) or
				     (self.autosleepinstandbyonly == "yes" and not Screens.Standby.inStandby) or
				     (self.autosleepinstandbyonly == "yes" and Screens.Standby.inStandby and internalHDDNotSleeping()
				    )
				   ):
					self.do_backoff()  # Retry.
					return False
				if not Screens.Standby.inTryQuitMainloop:  # Not a shutdown messagebox is open.
					if Screens.Standby.inStandby:  # In standby.
						quitMainloop(1)
						return True
					else:
						AddNotificationWithUniqueIDCallback(self.sendTryQuitMainloopNotification, "PT_StateChange", MessageBox, _("A finished powertimer wants to shutdown your receiver. Do that now?"), timeout=180)
						if self.autosleeprepeat == "once":
							eActionMap.getInstance().unbindAction("", self.keyPressed)
							return True
						else:
							self.begin = time() + int(self.autosleepdelay) * 60
							if self.end <= self.begin:
								self.end = self.begin
			elif self.timerType == TIMERTYPE.DEEPSTANDBY and self.wasPowerTimerWakeup:
				return True
			elif self.timerType == TIMERTYPE.DEEPSTANDBY and not self.wasPowerTimerWakeup:
				if NavigationInstance.instance.RecordTimer.isRecording() or abs(NavigationInstance.instance.RecordTimer.getNextRecordingTime() - time()) <= 900 or abs(NavigationInstance.instance.RecordTimer.getNextZapTime() - time()) <= 900:
					self.do_backoff()  # Retry.
					return False
				if not Screens.Standby.inTryQuitMainloop:  # Not a shutdown messagebox is open.
					if Screens.Standby.inStandby:  # In standby.
						quitMainloop(1)
					else:
						AddNotificationWithUniqueIDCallback(self.sendTryQuitMainloopNotification, "PT_StateChange", MessageBox, _("A finished powertimer wants to shutdown your receiver. Do that now?"), timeout=180)
				return True
			elif self.timerType == TIMERTYPE.REBOOT:
				if NavigationInstance.instance.RecordTimer.isRecording() or abs(NavigationInstance.instance.RecordTimer.getNextRecordingTime() - time()) <= 900 or abs(NavigationInstance.instance.RecordTimer.getNextZapTime() - time()) <= 900:
					self.do_backoff()  # Retry.
					return False
				if not Screens.Standby.inTryQuitMainloop:  # Not a shutdown messagebox is open.
					if Screens.Standby.inStandby:  # In standby.
						quitMainloop(2)
					else:
						AddNotificationWithUniqueIDCallback(self.sendTryToRebootNotification, "PT_StateChange", MessageBox, _("A finished powertimer wants to reboot your receiver. Do that now?"), timeout=180)
				return True
			elif self.timerType == TIMERTYPE.RESTART:
				if NavigationInstance.instance.RecordTimer.isRecording() or abs(NavigationInstance.instance.RecordTimer.getNextRecordingTime() - time()) <= 900 or abs(NavigationInstance.instance.RecordTimer.getNextZapTime() - time()) <= 900:
					self.do_backoff()  # Retry.
					return False
				if not Screens.Standby.inTryQuitMainloop:  # Not a shutdown messagebox is open.
					if Screens.Standby.inStandby:  # In standby.
						quitMainloop(3)
					else:
						AddNotificationWithUniqueIDCallback(self.sendTryToRestartNotification, "PT_StateChange", MessageBox, _("A finished powertimer wants to restart the user interface.\nDo that now?"), timeout=180)
				return True
		elif next_state == self.StateEnded:
			old_end = self.end
			NavigationInstance.instance.PowerTimer.saveTimers()
			if self.afterEvent == AFTEREVENT.STANDBY:
				if not Screens.Standby.inStandby:  # Not already in standby.
					AddNotificationWithUniqueIDCallback(self.sendStandbyNotification, "PT_StateChange", MessageBox, _("A finished powertimer wants to set your receiver to standby. Do that now?"), timeout=180)
			elif self.afterEvent == AFTEREVENT.DEEPSTANDBY:
				if NavigationInstance.instance.RecordTimer.isRecording() or abs(NavigationInstance.instance.RecordTimer.getNextRecordingTime() - time()) <= 900 or abs(NavigationInstance.instance.RecordTimer.getNextZapTime() - time()) <= 900:
					self.do_backoff()  # Retry.
					return False
				if not Screens.Standby.inTryQuitMainloop:  # Not a shutdown messagebox is open.
					if Screens.Standby.inStandby:  # In standby.
						quitMainloop(1)
					else:
						AddNotificationWithUniqueIDCallback(self.sendTryQuitMainloopNotification, "PT_StateChange", MessageBox, _("A finished powertimer wants to shutdown your receiver. Do that now?"), timeout=180)
			return True
Example #10
0
	def activate(self):
		next_state = self.state + 1
		self.log(5, "activating state %d" % next_state)

		if next_state == 1 and (self.timerType == TIMERTYPE.AUTOSTANDBY or self.timerType == TIMERTYPE.AUTODEEPSTANDBY):
			eActionMap.getInstance().bindAction('', -0x7FFFFFFF, self.keyPressed)
			self.begin = time() + int(self.autosleepdelay) * 60
			if self.end <= self.begin:
				self.end = self.begin

		if next_state == self.StatePrepared:
			self.log(6, "prepare ok, waiting for begin")
			self.next_activation = self.begin
			self.backoff = 0
			return True

		elif next_state == self.StateRunning:
			self.wasPowerTimerWakeup = False
			if os.path.exists("/tmp/was_powertimer_wakeup"):
				self.wasPowerTimerWakeup = int(open("/tmp/was_powertimer_wakeup", "r").read()) and True or False
				os.remove("/tmp/was_powertimer_wakeup")
			# If this timer has been cancelled or has failed,
			# just go to "end" state.
			if self.cancelled:
				return True

			if self.failed:
				return True

			if self.timerType == TIMERTYPE.WAKEUP:
				if Screens.Standby.inStandby:
					Screens.Standby.inStandby.Power()
				return True

			elif self.timerType == TIMERTYPE.WAKEUPTOSTANDBY:
				return True

			elif self.timerType == TIMERTYPE.STANDBY:
				if not Screens.Standby.inStandby:  # Not already in standby
					Notifications.AddNotificationWithCallback(self.sendStandbyNotification, MessageBox, _("A finished powertimer wants to set your\n%s %s to standby. Do that now?") % (getMachineBrand(), getMachineName()), timeout=180)
				return True

			elif self.timerType == TIMERTYPE.AUTOSTANDBY:
				if not Screens.Standby.inStandby:  # Not already in standby
					Notifications.AddNotificationWithCallback(self.sendStandbyNotification, MessageBox, _("A finished powertimer wants to set your\n%s %s to standby. Do that now?") % (getMachineBrand(), getMachineName()), timeout=180)
					if self.autosleeprepeat == "once":
						eActionMap.getInstance().unbindAction('', self.keyPressed)
						return True
					else:
						self.begin = time() + int(self.autosleepdelay) * 60
						if self.end <= self.begin:
							self.end = self.begin
				else:
					self.begin = time() + int(self.autosleepdelay) * 60
					if self.end <= self.begin:
						self.end = self.begin

			elif self.timerType == TIMERTYPE.AUTODEEPSTANDBY:
				if (NavigationInstance.instance.RecordTimer.isRecording() or abs(NavigationInstance.instance.RecordTimer.getNextRecordingTime() - time()) <= 900 or abs(NavigationInstance.instance.RecordTimer.getNextZapTime() - time()) <= 900) or (self.autosleepinstandbyonly == 'yes' and not Screens.Standby.inStandby) or (self.autosleepinstandbyonly == 'yes' and Screens.Standby.inStandby and internalHDDNotSleeping()):
					self.do_backoff()
					# Retry
					self.begin = time() + self.backoff
					if self.end <= self.begin:
						self.end = self.begin
					return False
				if not Screens.Standby.inTryQuitMainloop:  # The shutdown messagebox is not open
					if Screens.Standby.inStandby:  # In standby
						quitMainloop(1)
						return True
					else:
						Notifications.AddNotificationWithCallback(self.sendTryQuitMainloopNotification, MessageBox, _("A finished powertimer wants to shutdown your %s %s.\nDo that now?") % (getMachineBrand(), getMachineName()), timeout=180)
						if self.autosleeprepeat == "once":
							eActionMap.getInstance().unbindAction('', self.keyPressed)
							return True
						else:
							self.begin = time() + int(self.autosleepdelay) * 60
							if self.end <= self.begin:
								self.end = self.begin

			elif self.timerType == TIMERTYPE.DEEPSTANDBY and self.wasPowerTimerWakeup:
				return True

			elif self.timerType == TIMERTYPE.DEEPSTANDBY and not self.wasPowerTimerWakeup:
				if NavigationInstance.instance.RecordTimer.isRecording() or abs(NavigationInstance.instance.RecordTimer.getNextRecordingTime() - time()) <= 900 or abs(NavigationInstance.instance.RecordTimer.getNextZapTime() - time()) <= 900:
					self.do_backoff()
					# Retry
					self.begin = time() + self.backoff
					if self.end <= self.begin:
						self.end = self.begin
					return False
				if not Screens.Standby.inTryQuitMainloop:  # The shutdown messagebox is not open
					if Screens.Standby.inStandby:  # In standby
						quitMainloop(1)
					else:
						Notifications.AddNotificationWithCallback(self.sendTryQuitMainloopNotification, MessageBox, _("A finished powertimer wants to shutdown your %s %s.\nDo that now?") % (getMachineBrand(), getMachineName()), timeout=180)
				return True

			elif self.timerType == TIMERTYPE.REBOOT:
				if NavigationInstance.instance.RecordTimer.isRecording() or abs(NavigationInstance.instance.RecordTimer.getNextRecordingTime() - time()) <= 900 or abs(NavigationInstance.instance.RecordTimer.getNextZapTime() - time()) <= 900:
					self.do_backoff()
					# Retry
					self.begin = time() + self.backoff
					if self.end <= self.begin:
						self.end = self.begin
					return False
				if not Screens.Standby.inTryQuitMainloop:  # The shutdown messagebox is not open
					if Screens.Standby.inStandby:  # In standby
						quitMainloop(2)
					else:
						Notifications.AddNotificationWithCallback(self.sendTryToRebootNotification, MessageBox, _("A finished powertimer wants to reboot your %s %s.\nDo that now?") % (getMachineBrand(), getMachineName()), timeout=180)
				return True

			elif self.timerType == TIMERTYPE.RESTART:
				if NavigationInstance.instance.RecordTimer.isRecording() or abs(NavigationInstance.instance.RecordTimer.getNextRecordingTime() - time()) <= 900 or abs(NavigationInstance.instance.RecordTimer.getNextZapTime() - time()) <= 900:
					self.do_backoff()
					# Retry
					self.begin = time() + self.backoff
					if self.end <= self.begin:
						self.end = self.begin
					return False
				if not Screens.Standby.inTryQuitMainloop:  # The shutdown messagebox is not open
					if Screens.Standby.inStandby:  # In standby
						quitMainloop(3)
					else:
						Notifications.AddNotificationWithCallback(self.sendTryToRestartNotification, MessageBox, _("A finished powertimer wants to restart the user interface.\nDo that now?"), timeout=180)
				return True

		elif next_state == self.StateEnded:
			NavigationInstance.instance.PowerTimer.saveTimer()
			if self.afterEvent == AFTEREVENT.STANDBY:
				if not Screens.Standby.inStandby:  # Not already in standby
					Notifications.AddNotificationWithCallback(self.sendStandbyNotification, MessageBox, _("A finished powertimer wants to set your\n%s %s to standby. Do that now?") % (getMachineBrand(), getMachineName()), timeout=180)
			elif self.afterEvent == AFTEREVENT.DEEPSTANDBY:
				if NavigationInstance.instance.RecordTimer.isRecording() or abs(NavigationInstance.instance.RecordTimer.getNextRecordingTime() - time()) <= 900 or abs(NavigationInstance.instance.RecordTimer.getNextZapTime() - time()) <= 900:
					self.do_backoff()
					# Retry
					self.begin = time() + self.backoff
					if self.end <= self.begin:
						self.end = self.begin
					return False
				if not Screens.Standby.inTryQuitMainloop:  # The shutdown messagebox is not open
					if Screens.Standby.inStandby:  # In standby
						quitMainloop(1)
					else:
						Notifications.AddNotificationWithCallback(self.sendTryQuitMainloopNotification, MessageBox, _("A finished power timer wants to shut down\nyour %s %s. Shutdown now?") % (getMachineBrand(), getMachineName()), timeout=180)
			return True
    def activate(self):
        next_state = self.state + 1
        self.log(5, "activating state %d" % next_state)

        if next_state == self.StatePrepared and (
                self.timerType == TIMERTYPE.AUTOSTANDBY
                or self.timerType == TIMERTYPE.AUTODEEPSTANDBY):

            eActionMap.getInstance().bindAction('', -0x7FFFFFFF,
                                                self.keyPressed)
            self.begin = time() + int(self.autosleepdelay) * 60
            if self.end <= self.begin:
                self.end = self.begin

        if next_state == self.StatePrepared:
            self.log(6, "prepare ok, waiting for begin")
            self.next_activation = self.begin
            self.backoff = 0
            return True

        elif next_state == self.StateRunning:
            self.wasPowerTimerWakeup = False
            if os.path.exists("/tmp/was_powertimer_wakeup"):
                self.wasPowerTimerWakeup = int(
                    open("/tmp/was_powertimer_wakeup",
                         "r").read()) and True or False
                os.remove("/tmp/was_powertimer_wakeup")
            if self.cancelled:
                return True

            if self.failed:
                return True

            if self.timerType == TIMERTYPE.WAKEUP:
                if Screens.Standby.inStandby:
                    Screens.Standby.inStandby.Power()
                return True

            elif self.timerType == TIMERTYPE.WAKEUPTOSTANDBY:
                return True

            elif self.timerType == TIMERTYPE.STANDBY:
                if not Screens.Standby.inStandby:
                    Notifications.AddNotificationWithUniqueIDCallback(
                        self.sendStandbyNotification,
                        "PT_StateChange",
                        MessageBox,
                        _("A finished powertimer wants to set your receiver to standby. Do that now?"
                          ),
                        timeout=180)
                return True

            elif self.timerType == TIMERTYPE.AUTOSTANDBY:
                if NavigationInstance.instance.getCurrentlyPlayingServiceReference(
                ) and ('0:0:0:0:0:0:0:0:0' in NavigationInstance.instance.
                       getCurrentlyPlayingServiceReference().toString()
                       or '4097:' in NavigationInstance.instance.
                       getCurrentlyPlayingServiceReference().toString()):
                    self.do_backoff()
                    return False
                if not Screens.Standby.inStandby:
                    Notifications.AddNotificationWithUniqueIDCallback(
                        self.sendStandbyNotification,
                        "PT_StateChange",
                        MessageBox,
                        _("A finished powertimer wants to set your receiver to standby. Do that now?"
                          ),
                        timeout=180)
                    if self.autosleeprepeat == "once":
                        eActionMap.getInstance().unbindAction(
                            '', self.keyPressed)
                        return True
                    else:
                        self.begin = time() + int(self.autosleepdelay) * 60
                        if self.end <= self.begin:
                            self.end = self.begin
                else:
                    self.begin = time() + int(self.autosleepdelay) * 60
                    if self.end <= self.begin:
                        self.end = self.begin

            elif self.timerType == TIMERTYPE.AUTODEEPSTANDBY:

                from Components.Converter.ClientsStreaming import ClientsStreaming
                if ((not Screens.Standby.inStandby and NavigationInstance.
                     instance.getCurrentlyPlayingServiceReference() and
                     ('0:0:0:0:0:0:0:0:0' in NavigationInstance.instance.
                      getCurrentlyPlayingServiceReference().toString()
                      or '4097:' in NavigationInstance.instance.
                      getCurrentlyPlayingServiceReference().toString()) or
                     (int(ClientsStreaming("NUMBER").getText()) > 0)) or
                    (NavigationInstance.instance.RecordTimer.isRecording()
                     or abs(NavigationInstance.instance.RecordTimer.
                            getNextRecordingTime() - time()) <= 900
                     or abs(NavigationInstance.instance.RecordTimer.
                            getNextZapTime() - time()) <= 900)
                        or (self.autosleepinstandbyonly == 'yes'
                            and not Screens.Standby.inStandby)
                        or (self.autosleepinstandbyonly == 'yes'
                            and Screens.Standby.inStandby
                            and internalHDDNotSleeping())):
                    self.do_backoff()
                    return False
                if not Screens.Standby.inTryQuitMainloop:
                    if Screens.Standby.inStandby:
                        quitMainloop(1)
                        return True
                    else:
                        Notifications.AddNotificationWithUniqueIDCallback(
                            self.sendTryQuitMainloopNotification,
                            "PT_StateChange",
                            MessageBox,
                            _("A finished powertimer wants to shutdown your receiver. Do that now?"
                              ),
                            timeout=180)
                        if self.autosleeprepeat == "once":
                            eActionMap.getInstance().unbindAction(
                                '', self.keyPressed)
                            return True
                        else:
                            self.begin = time() + int(self.autosleepdelay) * 60
                            if self.end <= self.begin:
                                self.end = self.begin

            elif self.timerType == TIMERTYPE.DEEPSTANDBY and self.wasPowerTimerWakeup:
                return True

            elif self.timerType == TIMERTYPE.DEEPSTANDBY and not self.wasPowerTimerWakeup:
                if NavigationInstance.instance.RecordTimer.isRecording(
                ) or abs(NavigationInstance.instance.RecordTimer.
                         getNextRecordingTime() -
                         time()) <= 900 or abs(NavigationInstance.instance.
                                               RecordTimer.getNextZapTime() -
                                               time()) <= 900:
                    self.do_backoff()
                    return False
                if not Screens.Standby.inTryQuitMainloop:
                    if Screens.Standby.inStandby:
                        quitMainloop(1)
                    else:
                        Notifications.AddNotificationWithUniqueIDCallback(
                            self.sendTryQuitMainloopNotification,
                            "PT_StateChange",
                            MessageBox,
                            _("A finished powertimer wants to shutdown your receiver. Do that now?"
                              ),
                            timeout=180)
                return True

            elif self.timerType == TIMERTYPE.REBOOT:
                if NavigationInstance.instance.RecordTimer.isRecording(
                ) or abs(NavigationInstance.instance.RecordTimer.
                         getNextRecordingTime() -
                         time()) <= 900 or abs(NavigationInstance.instance.
                                               RecordTimer.getNextZapTime() -
                                               time()) <= 900:
                    self.do_backoff()
                    return False
                if not Screens.Standby.inTryQuitMainloop:
                    if Screens.Standby.inStandby:
                        quitMainloop(2)
                    else:
                        Notifications.AddNotificationWithUniqueIDCallback(
                            self.sendTryToRebootNotification,
                            "PT_StateChange",
                            MessageBox,
                            _("A finished powertimer wants to reboot your receiver. Do that now?"
                              ),
                            timeout=180)
                return True

            elif self.timerType == TIMERTYPE.RESTART:
                if NavigationInstance.instance.RecordTimer.isRecording(
                ) or abs(NavigationInstance.instance.RecordTimer.
                         getNextRecordingTime() -
                         time()) <= 900 or abs(NavigationInstance.instance.
                                               RecordTimer.getNextZapTime() -
                                               time()) <= 900:
                    self.do_backoff()
                    return False
                if not Screens.Standby.inTryQuitMainloop:
                    if Screens.Standby.inStandby:
                        quitMainloop(3)
                    else:
                        Notifications.AddNotificationWithUniqueIDCallback(
                            self.sendTryToRestartNotification,
                            "PT_StateChange",
                            MessageBox,
                            _("A finished powertimer wants to restart the user interface.\nDo that now?"
                              ),
                            timeout=180)
                return True

        elif next_state == self.StateEnded:
            old_end = self.end
            NavigationInstance.instance.PowerTimer.saveTimer()
            if self.afterEvent == AFTEREVENT.STANDBY:
                if not Screens.Standby.inStandby:
                    Notifications.AddNotificationWithUniqueIDCallback(
                        self.sendStandbyNotification,
                        "PT_StateChange",
                        MessageBox,
                        _("A finished powertimer wants to set your receiver to standby. Do that now?"
                          ),
                        timeout=180)
            elif self.afterEvent == AFTEREVENT.DEEPSTANDBY:
                if NavigationInstance.instance.RecordTimer.isRecording(
                ) or abs(NavigationInstance.instance.RecordTimer.
                         getNextRecordingTime() -
                         time()) <= 900 or abs(NavigationInstance.instance.
                                               RecordTimer.getNextZapTime() -
                                               time()) <= 900:
                    self.do_backoff()
                    return False
                if not Screens.Standby.inTryQuitMainloop:
                    if Screens.Standby.inStandby:
                        quitMainloop(1)
                    else:
                        Notifications.AddNotificationWithUniqueIDCallback(
                            self.sendTryQuitMainloopNotification,
                            "PT_StateChange",
                            MessageBox,
                            _("A finished powertimer wants to shutdown your receiver. Do that now?"
                              ),
                            timeout=180)
            return True
Example #12
0
	def activate(self):
		next_state = self.state + 1
		self.log(5, "activating state %d" % next_state)

		if next_state == self.StatePrepared and (self.timerType == TIMERTYPE.AUTOSTANDBY or self.timerType == TIMERTYPE.AUTODEEPSTANDBY):
# This is the first action for an auto* timer.
# It binds any key press to keyPressed(), which resets the timer delay,
# and sets the initial delay.
#
			eActionMap.getInstance().bindAction('', -0x7FFFFFFF, self.keyPressed)
			self.begin = time() + int(self.autosleepdelay)*60
			if self.end <= self.begin:
				self.end = self.begin

		if next_state == self.StatePrepared:
			self.log(6, "prepare ok, waiting for begin")
			self.next_activation = self.begin
			self.backoff = 0
			return True

		elif next_state == self.StateRunning:
			self.wasPowerTimerWakeup = False
			if os.path.exists("/tmp/was_powertimer_wakeup"):
				self.wasPowerTimerWakeup = int(open("/tmp/was_powertimer_wakeup", "r").read()) and True or False
				os.remove("/tmp/was_powertimer_wakeup")
			# if this timer has been cancelled, just go to "end" state.
			if self.cancelled:
				return True

			if self.failed:
				return True

			if self.timerType == TIMERTYPE.WAKEUP:
				if Screens.Standby.inStandby:
					Screens.Standby.inStandby.Power()
				return True

			elif self.timerType == TIMERTYPE.WAKEUPTOSTANDBY:
				return True

			elif self.timerType == TIMERTYPE.STANDBY:
				if not Screens.Standby.inStandby: # not already in standby
					Notifications.AddNotificationWithUniqueIDCallback(self.sendStandbyNotification, "PT_StateChange", MessageBox, _("A finished powertimer wants to set your\n%s %s to standby. Do that now?") % (getMachineBrand(), getMachineName()), timeout = 180)
				return True

			elif self.timerType == TIMERTYPE.AUTOSTANDBY:
				if NavigationInstance.instance.getCurrentlyPlayingServiceReference() and ('0:0:0:0:0:0:0:0:0' in NavigationInstance.instance.getCurrentlyPlayingServiceReference().toString() or '4097:' in NavigationInstance.instance.getCurrentlyPlayingServiceReference().toString()):
					self.do_backoff()
					# retry
					return False
				if not Screens.Standby.inStandby: # not already in standby
					Notifications.AddNotificationWithUniqueIDCallback(self.sendStandbyNotification, "PT_StateChange", MessageBox, _("A finished powertimer wants to set your\n%s %s to standby. Do that now?") % (getMachineBrand(), getMachineName()), timeout = 180)
					if self.autosleeprepeat == "once":
						eActionMap.getInstance().unbindAction('', self.keyPressed)
						return True
					else:
						self.begin = time() + int(self.autosleepdelay)*60
						if self.end <= self.begin:
							self.end = self.begin
				else:
					self.begin = time() + int(self.autosleepdelay)*60
					if self.end <= self.begin:
						self.end = self.begin

			elif self.timerType == TIMERTYPE.AUTODEEPSTANDBY:

# Check for there being any active Movie playback or IPTV channel
# or any streaming clients before going to Deep Standby.
# However, it is possible to put the box into Standby with the
# MoviePlayer still active (it will play if the box is taken out
# of Standby) - similarly for the IPTV player. This should not
# prevent a DeepStandby
# And check for existing or imminent recordings, etc..
# Also added () around the test and split them across lines
# to make it clearer what each test is.
#
				from Components.Converter.ClientsStreaming import ClientsStreaming;
				if ((not Screens.Standby.inStandby and NavigationInstance.instance.getCurrentlyPlayingServiceReference() and
					('0:0:0:0:0:0:0:0:0' in NavigationInstance.instance.getCurrentlyPlayingServiceReference().toString() or
					 '4097:' in NavigationInstance.instance.getCurrentlyPlayingServiceReference().toString()
				     ) or
				     (int(ClientsStreaming("NUMBER").getText()) > 0)
				    ) or
				    (NavigationInstance.instance.RecordTimer.isRecording() or
				     abs(NavigationInstance.instance.RecordTimer.getNextRecordingTime() - time()) <= 900 or
				     abs(NavigationInstance.instance.RecordTimer.getNextZapTime() - time()) <= 900) or
				     (self.autosleepinstandbyonly == 'yes' and not Screens.Standby.inStandby) or
				     (self.autosleepinstandbyonly == 'yes' and Screens.Standby.inStandby and internalHDDNotSleeping()
				    )
				   ):
					self.do_backoff()
					# retry
					return False
				if not Screens.Standby.inTryQuitMainloop: # not a shutdown messagebox is open
					if Screens.Standby.inStandby: # in standby
						quitMainloop(1)
						return True
					else:
						Notifications.AddNotificationWithUniqueIDCallback(self.sendTryQuitMainloopNotification, "PT_StateChange", MessageBox, _("A finished powertimer wants to shutdown your %s %s.\nDo that now?") % (getMachineBrand(), getMachineName()), timeout = 180)
						if self.autosleeprepeat == "once":
							eActionMap.getInstance().unbindAction('', self.keyPressed)
							return True
						else:
							self.begin = time() + int(self.autosleepdelay)*60
							if self.end <= self.begin:
								self.end = self.begin

			elif self.timerType == TIMERTYPE.DEEPSTANDBY and self.wasPowerTimerWakeup:
				return True

			elif self.timerType == TIMERTYPE.DEEPSTANDBY and not self.wasPowerTimerWakeup:
				if NavigationInstance.instance.RecordTimer.isRecording() or abs(NavigationInstance.instance.RecordTimer.getNextRecordingTime() - time()) <= 900 or abs(NavigationInstance.instance.RecordTimer.getNextZapTime() - time()) <= 900:
					self.do_backoff()
					# retry
					return False
				if not Screens.Standby.inTryQuitMainloop: # not a shutdown messagebox is open
					if Screens.Standby.inStandby: # in standby
						quitMainloop(1)
					else:
						Notifications.AddNotificationWithUniqueIDCallback(self.sendTryQuitMainloopNotification, "PT_StateChange", MessageBox, _("A finished powertimer wants to shutdown your %s %s.\nDo that now?") % (getMachineBrand(), getMachineName()), timeout = 180)
				return True

			elif self.timerType == TIMERTYPE.REBOOT:
				if NavigationInstance.instance.RecordTimer.isRecording() or abs(NavigationInstance.instance.RecordTimer.getNextRecordingTime() - time()) <= 900 or abs(NavigationInstance.instance.RecordTimer.getNextZapTime() - time()) <= 900:
					self.do_backoff()
					# retry
					return False
				if not Screens.Standby.inTryQuitMainloop: # not a shutdown messagebox is open
					if Screens.Standby.inStandby: # in standby
						quitMainloop(2)
					else:
						Notifications.AddNotificationWithUniqueIDCallback(self.sendTryToRebootNotification, "PT_StateChange", MessageBox, _("A finished powertimer wants to reboot your %s %s.\nDo that now?") % (getMachineBrand(), getMachineName()), timeout = 180)
				return True

			elif self.timerType == TIMERTYPE.RESTART:
				if NavigationInstance.instance.RecordTimer.isRecording() or abs(NavigationInstance.instance.RecordTimer.getNextRecordingTime() - time()) <= 900 or abs(NavigationInstance.instance.RecordTimer.getNextZapTime() - time()) <= 900:
					self.do_backoff()
					# retry
					return False
				if not Screens.Standby.inTryQuitMainloop: # not a shutdown messagebox is open
					if Screens.Standby.inStandby: # in standby
						quitMainloop(3)
					else:
						Notifications.AddNotificationWithUniqueIDCallback(self.sendTryToRestartNotification, "PT_StateChange", MessageBox, _("A finished powertimer wants to restart the user interface.\nDo that now?"), timeout = 180)
				return True

		elif next_state == self.StateEnded:
			old_end = self.end
			NavigationInstance.instance.PowerTimer.saveTimer()
			if self.afterEvent == AFTEREVENT.STANDBY:
				if not Screens.Standby.inStandby: # not already in standby
					Notifications.AddNotificationWithUniqueIDCallback(self.sendStandbyNotification, "PT_StateChange", MessageBox, _("A finished powertimer wants to set your\n%s %s to standby. Do that now?") % (getMachineBrand(), getMachineName()), timeout = 180)
			elif self.afterEvent == AFTEREVENT.DEEPSTANDBY:
				if NavigationInstance.instance.RecordTimer.isRecording() or abs(NavigationInstance.instance.RecordTimer.getNextRecordingTime() - time()) <= 900 or abs(NavigationInstance.instance.RecordTimer.getNextZapTime() - time()) <= 900:
					self.do_backoff()
					# retry
					return False
				if not Screens.Standby.inTryQuitMainloop: # not a shutdown messagebox is open
					if Screens.Standby.inStandby: # in standby
						quitMainloop(1)
					else:
						Notifications.AddNotificationWithUniqueIDCallback(self.sendTryQuitMainloopNotification, "PT_StateChange", MessageBox, _("A finished powertimer wants to shutdown your %s %s.\nDo that now?") % (getMachineBrand(), getMachineName()), timeout = 180)
			return True
Example #13
0
    def activate(self):
        next_state = self.state + 1
        self.log(5, "activating state %d" % next_state)

        if next_state == self.StatePrepared and self.timerType in (
                TIMERTYPE.AUTOSTANDBY, TIMERTYPE.AUTODEEPSTANDBY):
            eActionMap.getInstance().bindAction('', -0x7FFFFFFF,
                                                self.keyPressed)
            self.begin = time() + int(self.autosleepdelay) * 60
            if self.end <= self.begin:
                self.end = self.begin

        if next_state == self.StatePrepared:
            self.log(6, "prepare ok, waiting for begin")
            self.next_activation = self.begin
            self.backoff = 0
            return True

        elif next_state == self.StateRunning:
            self.wasPowerTimerWakeup = False
            if os.path.exists("/tmp/was_powertimer_wakeup"):
                self.wasPowerTimerWakeup = bool(
                    int(open("/tmp/was_powertimer_wakeup", "r").read()))
                os.remove("/tmp/was_powertimer_wakeup")
            # If this timer has been cancelled or has failed,
            # just go to "end" state.
            if self.cancelled:
                return True

            if self.failed:
                return True

            if self.timerType == TIMERTYPE.WAKEUP:
                if Screens.Standby.inStandby:
                    Screens.Standby.inStandby.Power()
                return True

            elif self.timerType == TIMERTYPE.WAKEUPTOSTANDBY:
                return True

            elif self.timerType == TIMERTYPE.STANDBY:
                if not Screens.Standby.inStandby:  # Not already in standby
                    Notifications.AddNotificationWithUniqueIDCallback(
                        self.sendStandbyNotification,
                        "PT_StateChange",
                        MessageBox,
                        _("A power timer wants to set your %s %s to standby mode.\nGo to standby mode now?"
                          ) % (getMachineBrand(), getMachineName()),
                        timeout=180)
                return True

            elif self.timerType == TIMERTYPE.AUTOSTANDBY:
                if NavigationInstance.instance.getCurrentlyPlayingServiceReference(
                ) and ('0:0:0:0:0:0:0:0:0' in NavigationInstance.instance.
                       getCurrentlyPlayingServiceReference().toString()
                       or '4097:' in NavigationInstance.instance.
                       getCurrentlyPlayingServiceReference().toString()):
                    self.do_backoff()
                    # retry
                    self.begin = time() + self.backoff
                    if self.end <= self.begin:
                        self.end = self.begin
                    return False
                if not Screens.Standby.inStandby:  # Not already in standby
                    Notifications.AddNotificationWithUniqueIDCallback(
                        self.sendStandbyNotification,
                        "PT_StateChange",
                        MessageBox,
                        _("A power timer wants to set your %s %s to standby mode.\nGo to standby mode now?"
                          ) % (getMachineBrand(), getMachineName()),
                        timeout=180)
                    if self.autosleeprepeat == "once":
                        eActionMap.getInstance().unbindAction(
                            '', self.keyPressed)
                        return True
                    else:
                        self.begin = time() + int(self.autosleepdelay) * 60
                        if self.end <= self.begin:
                            self.end = self.begin
                else:
                    self.begin = time() + int(self.autosleepdelay) * 60
                    if self.end <= self.begin:
                        self.end = self.begin

            elif self.timerType == TIMERTYPE.AUTODEEPSTANDBY:
                # Check for there being any active
                # Movie playback or IPTV channel or
                # any streaming clients before going
                # to Deep Standby.  However, it is
                # possible to put the box into Standby
                # with the MoviePlayer still active
                # (it will play if the box is taken
                # out of Standby) - similarly for the
                # IPTV player. This should not prevent
                # a DeepStandby And check for existing
                # or imminent recordings, etc..  Also
                # added () around the test and split
                # them across lines to make it clearer
                # what each test is.
                from Components.Converter.ClientsStreaming import ClientsStreaming
                if ((not Screens.Standby.inStandby and NavigationInstance.
                     instance.getCurrentlyPlayingServiceReference() and
                     ('0:0:0:0:0:0:0:0:0' in NavigationInstance.instance.
                      getCurrentlyPlayingServiceReference().toString()
                      or '4097:' in NavigationInstance.instance.
                      getCurrentlyPlayingServiceReference().toString()) or
                     (int(ClientsStreaming("NUMBER").getText()) > 0))
                        or recordingsActive(900)
                        or (self.autosleepinstandbyonly == 'yes'
                            and not Screens.Standby.inStandby)
                        or (self.autosleepinstandbyonly == 'yes'
                            and Screens.Standby.inStandby
                            and internalHDDNotSleeping())):
                    self.do_backoff()
                    # Retry
                    self.begin = time() + self.backoff
                    if self.end <= self.begin:
                        self.end = self.begin
                    return False
                if not Screens.Standby.inTryQuitMainloop:  # The shutdown messagebox is not open
                    if Screens.Standby.inStandby:  # In standby
                        quitMainloop(Screens.Standby.QUIT_SHUTDOWN)
                        return True
                    else:
                        Notifications.AddNotificationWithUniqueIDCallback(
                            self.sendTryQuitMainloopNotification,
                            "PT_StateChange",
                            MessageBox,
                            _("A power timer wants to shut down your %s %s.\nShut down now?"
                              ) % (getMachineBrand(), getMachineName()),
                            timeout=180)
                        if self.autosleeprepeat == "once":
                            eActionMap.getInstance().unbindAction(
                                '', self.keyPressed)
                            return True
                        else:
                            self.begin = time() + int(self.autosleepdelay) * 60
                            if self.end <= self.begin:
                                self.end = self.begin

            elif self.timerType == TIMERTYPE.DEEPSTANDBY and self.wasPowerTimerWakeup:
                return True

            elif self.timerType == TIMERTYPE.DEEPSTANDBY and not self.wasPowerTimerWakeup:
                if recordingsActive(900):
                    self.do_backoff()
                    # Retry
                    self.begin = time() + self.backoff
                    if self.end <= self.begin:
                        self.end = self.begin
                    return False
                if not Screens.Standby.inTryQuitMainloop:  # The shutdown messagebox is not open
                    if Screens.Standby.inStandby:  # In standby
                        quitMainloop(Screens.Standby.QUIT_SHUTDOWN)
                    else:
                        Notifications.AddNotificationWithUniqueIDCallback(
                            self.sendTryQuitMainloopNotification,
                            "PT_StateChange",
                            MessageBox,
                            _("A power timer wants to shut down your %s %s.\nShut down now?"
                              ) % (getMachineBrand(), getMachineName()),
                            timeout=180)
                return True

            elif self.timerType == TIMERTYPE.REBOOT:
                if recordingsActive(900):
                    self.do_backoff()
                    # Retry
                    self.begin = time() + self.backoff
                    if self.end <= self.begin:
                        self.end = self.begin
                    return False
                if not Screens.Standby.inTryQuitMainloop:  # The shutdown messagebox is not open
                    if Screens.Standby.inStandby:  # In standby
                        quitMainloop(Screens.Standby.QUIT_REBOOT)
                    else:
                        Notifications.AddNotificationWithUniqueIDCallback(
                            self.sendTryToRebootNotification,
                            "PT_StateChange",
                            MessageBox,
                            _("A power timer wants to reboot your %s %s.\nReboot now?"
                              ) % (getMachineBrand(), getMachineName()),
                            timeout=180)
                return True

            elif self.timerType == TIMERTYPE.RESTART:
                if recordingsActive(900):
                    self.do_backoff()
                    # Retry
                    self.begin = time() + self.backoff
                    if self.end <= self.begin:
                        self.end = self.begin
                    return False
                if not Screens.Standby.inTryQuitMainloop:  # The shutdown messagebox is not open
                    if Screens.Standby.inStandby:  # In standby
                        quitMainloop(Screens.Standby.QUIT_RESTART)
                    else:
                        Notifications.AddNotificationWithUniqueIDCallback(
                            self.sendTryToRestartNotification,
                            "PT_StateChange",
                            MessageBox,
                            _("A power timer wants to restart your %s %s user interface.\nRestart user interface now?"
                              ) % (getMachineBrand(), getMachineName()),
                            timeout=180)
                return True

        elif next_state == self.StateEnded:
            NavigationInstance.instance.PowerTimer.saveTimer()
            if self.afterEvent == AFTEREVENT.STANDBY:
                if not Screens.Standby.inStandby:  # Not already in standby
                    Notifications.AddNotificationWithUniqueIDCallback(
                        self.sendStandbyNotification,
                        "PT_StateChange",
                        MessageBox,
                        _("A power timer wants to set your %s %s to standby mode.\nGo to standby mode now?"
                          ) % (getMachineBrand(), getMachineName()),
                        timeout=180)
            elif self.afterEvent == AFTEREVENT.DEEPSTANDBY:
                if recordingsActive(900):
                    self.do_backoff()
                    # Retry
                    self.begin = time() + self.backoff
                    if self.end <= self.begin:
                        self.end = self.begin
                    return False
                if not Screens.Standby.inTryQuitMainloop:  # The shutdown messagebox is not open
                    if Screens.Standby.inStandby:  # In standby
                        quitMainloop(Screens.Standby.QUIT_SHUTDOWN)
                    else:
                        Notifications.AddNotificationWithUniqueIDCallback(
                            self.sendTryQuitMainloopNotification,
                            "PT_StateChange",
                            MessageBox,
                            _("A power timer wants to shut down your %s %s.\nShut down now?"
                              ) % (getMachineBrand(), getMachineName()),
                            timeout=180)
            return True
Example #14
0
    def activate(self):
        next_state = self.state + 1
        self.log(5, "activating state %d" % next_state)

        if next_state == 1 and (self.timerType == TIMERTYPE.AUTOSTANDBY or
                                self.timerType == TIMERTYPE.AUTODEEPSTANDBY):
            eActionMap.getInstance().bindAction('', -0x7FFFFFFF,
                                                self.keyPressed)
            self.begin = time() + int(self.autosleepdelay) * 60
            if self.end <= self.begin:
                self.end = self.begin

        if next_state == self.StatePrepared:
            self.log(6, "prepare ok, waiting for begin")
            self.next_activation = self.begin
            self.backoff = 0
            return True

        elif next_state == self.StateRunning:
            self.wasPowerTimerWakeup = False
            if os.path.exists("/tmp/was_timer_wakeup"):
                self.wasPowerTimerWakeup = int(
                    open("/tmp/was_powertimer_wakeup",
                         "r").read()) and True or False
                os.remove("/tmp/was_powertimer_wakeup")
            # if this timer has been cancelled, just go to "end" state.
            if self.cancelled:
                return True

            if self.failed:
                return True

            if self.timerType == TIMERTYPE.WAKEUP:
                if Screens.Standby.inStandby:
                    Screens.Standby.inStandby.Power()
                return True

            elif self.timerType == TIMERTYPE.WAKEUPTOSTANDBY:
                return True

            elif self.timerType == TIMERTYPE.STANDBY:
                if not Screens.Standby.inStandby:  # not already in standby
                    Notifications.AddNotificationWithCallback(
                        self.sendStandbyNotification,
                        MessageBox,
                        _("A finished powertimer wants to set your\n%s %s to standby. Do that now?"
                          ) % (getMachineBrand(), getMachineName()),
                        timeout=180)
                return True

            elif self.timerType == TIMERTYPE.AUTOSTANDBY:
                if NavigationInstance.instance.getCurrentlyPlayingServiceReference(
                ) and ('0:0:0:0:0:0:0:0:0' in NavigationInstance.instance.
                       getCurrentlyPlayingServiceReference().toString()
                       or '4097:' in NavigationInstance.instance.
                       getCurrentlyPlayingServiceReference().toString()):
                    self.do_backoff()
                    # retry
                    self.begin = time() + self.backoff
                    if self.end <= self.begin:
                        self.end = self.begin
                    return False
                if not Screens.Standby.inStandby:  # not already in standby
                    Notifications.AddNotificationWithCallback(
                        self.sendStandbyNotification,
                        MessageBox,
                        _("A finished powertimer wants to set your\n%s %s to standby. Do that now?"
                          ) % (getMachineBrand(), getMachineName()),
                        timeout=180)
                    if self.autosleeprepeat == "once":
                        eActionMap.getInstance().unbindAction(
                            '', self.keyPressed)
                        return True
                    else:
                        self.begin = time() + int(self.autosleepdelay) * 60
                        if self.end <= self.begin:
                            self.end = self.begin
                else:
                    self.begin = time() + int(self.autosleepdelay) * 60
                    if self.end <= self.begin:
                        self.end = self.begin

            elif self.timerType == TIMERTYPE.AUTODEEPSTANDBY:

                # GML:2 - Check for there being any active Movie playback or IPTV channel
                #         or any streaming clients before going to Deep Standby.
                #         However, it is possible to put the box into Standby with the
                #         MoviePlayer still active (it will play if the box is taken out
                #         of Standby) - similarly for the IPTV player. This should not
                #         prevent a DeepStandby
                #         And check for existing or imminent recordings, etc..
                #         I've also added () around the test and split them across lines
                #         to make it clearer what each test is.
                #				if (NavigationInstance.instance.getCurrentlyPlayingServiceReference() and ('0:0:0:0:0:0:0:0:0' in NavigationInstance.instance.getCurrentlyPlayingServiceReference().toString() or '4097:' in NavigationInstance.instance.getCurrentlyPlayingServiceReference().toString())) or (NavigationInstance.instance.RecordTimer.isRecording() or abs(NavigationInstance.instance.RecordTimer.getNextRecordingTime() - time()) <= 900 or abs(NavigationInstance.instance.RecordTimer.getNextZapTime() - time()) <= 900) or (self.autosleepinstandbyonly == 'yes' and not Screens.Standby.inStandby) or (self.autosleepinstandbyonly == 'yes' and Screens.Standby.inStandby and internalHDDNotSleeping()):
                #
                from Components.Converter.ClientsStreaming import ClientsStreaming
                if ((not Screens.Standby.inStandby and NavigationInstance.
                     instance.getCurrentlyPlayingServiceReference() and
                     ('0:0:0:0:0:0:0:0:0' in NavigationInstance.instance.
                      getCurrentlyPlayingServiceReference().toString()
                      or '4097:' in NavigationInstance.instance.
                      getCurrentlyPlayingServiceReference().toString()) or
                     (int(ClientsStreaming("NUMBER").getText()) > 0)) or
                    (NavigationInstance.instance.RecordTimer.isRecording()
                     or abs(NavigationInstance.instance.RecordTimer.
                            getNextRecordingTime() - time()) <= 900
                     or abs(NavigationInstance.instance.RecordTimer.
                            getNextZapTime() - time()) <= 900)
                        or (self.autosleepinstandbyonly == 'yes'
                            and not Screens.Standby.inStandby)
                        or (self.autosleepinstandbyonly == 'yes'
                            and Screens.Standby.inStandby
                            and internalHDDNotSleeping())):
                    self.do_backoff()
                    # retry
                    self.begin = time() + self.backoff
                    if self.end <= self.begin:
                        self.end = self.begin
                    return False
                if not Screens.Standby.inTryQuitMainloop:  # not a shutdown messagebox is open
                    if Screens.Standby.inStandby:  # in standby
                        quitMainloop(1)
                        return True
                    else:
                        Notifications.AddNotificationWithCallback(
                            self.sendTryQuitMainloopNotification,
                            MessageBox,
                            _("A finished powertimer wants to shutdown your %s %s.\nDo that now?"
                              ) % (getMachineBrand(), getMachineName()),
                            timeout=180)
                        if self.autosleeprepeat == "once":
                            eActionMap.getInstance().unbindAction(
                                '', self.keyPressed)
                            return True
                        else:
                            self.begin = time() + int(self.autosleepdelay) * 60
                            if self.end <= self.begin:
                                self.end = self.begin

            elif self.timerType == TIMERTYPE.DEEPSTANDBY and self.wasPowerTimerWakeup:
                return True

            elif self.timerType == TIMERTYPE.DEEPSTANDBY and not self.wasPowerTimerWakeup:
                if NavigationInstance.instance.RecordTimer.isRecording(
                ) or abs(NavigationInstance.instance.RecordTimer.
                         getNextRecordingTime() -
                         time()) <= 900 or abs(NavigationInstance.instance.
                                               RecordTimer.getNextZapTime() -
                                               time()) <= 900:
                    self.do_backoff()
                    # retry
                    self.begin = time() + self.backoff
                    if self.end <= self.begin:
                        self.end = self.begin
                    return False
                if not Screens.Standby.inTryQuitMainloop:  # not a shutdown messagebox is open
                    if Screens.Standby.inStandby:  # in standby
                        quitMainloop(1)
                    else:
                        Notifications.AddNotificationWithCallback(
                            self.sendTryQuitMainloopNotification,
                            MessageBox,
                            _("A finished powertimer wants to shutdown your %s %s.\nDo that now?"
                              ) % (getMachineBrand(), getMachineName()),
                            timeout=180)
                return True

            elif self.timerType == TIMERTYPE.REBOOT:
                if NavigationInstance.instance.RecordTimer.isRecording(
                ) or abs(NavigationInstance.instance.RecordTimer.
                         getNextRecordingTime() -
                         time()) <= 900 or abs(NavigationInstance.instance.
                                               RecordTimer.getNextZapTime() -
                                               time()) <= 900:
                    self.do_backoff()
                    # retry
                    self.begin = time() + self.backoff
                    if self.end <= self.begin:
                        self.end = self.begin
                    return False
                if not Screens.Standby.inTryQuitMainloop:  # not a shutdown messagebox is open
                    if Screens.Standby.inStandby:  # in standby
                        quitMainloop(2)
                    else:
                        Notifications.AddNotificationWithCallback(
                            self.sendTryToRebootNotification,
                            MessageBox,
                            _("A finished powertimer wants to reboot your %s %s.\nDo that now?"
                              ) % (getMachineBrand(), getMachineName()),
                            timeout=180)
                return True

            elif self.timerType == TIMERTYPE.RESTART:
                if NavigationInstance.instance.RecordTimer.isRecording(
                ) or abs(NavigationInstance.instance.RecordTimer.
                         getNextRecordingTime() -
                         time()) <= 900 or abs(NavigationInstance.instance.
                                               RecordTimer.getNextZapTime() -
                                               time()) <= 900:
                    self.do_backoff()
                    # retry
                    self.begin = time() + self.backoff
                    if self.end <= self.begin:
                        self.end = self.begin
                    return False
                if not Screens.Standby.inTryQuitMainloop:  # not a shutdown messagebox is open
                    if Screens.Standby.inStandby:  # in standby
                        quitMainloop(3)
                    else:
                        Notifications.AddNotificationWithCallback(
                            self.sendTryToRestartNotification,
                            MessageBox,
                            _("A finished powertimer wants to restart the user interface.\nDo that now?"
                              ),
                            timeout=180)
                return True

        elif next_state == self.StateEnded:
            old_end = self.end
            NavigationInstance.instance.PowerTimer.saveTimer()
            if self.afterEvent == AFTEREVENT.STANDBY:
                if not Screens.Standby.inStandby:  # not already in standby
                    Notifications.AddNotificationWithCallback(
                        self.sendStandbyNotification,
                        MessageBox,
                        _("A finished powertimer wants to set your\n%s %s to standby. Do that now?"
                          ) % (getMachineBrand(), getMachineName()),
                        timeout=180)
            elif self.afterEvent == AFTEREVENT.DEEPSTANDBY:
                if NavigationInstance.instance.RecordTimer.isRecording(
                ) or abs(NavigationInstance.instance.RecordTimer.
                         getNextRecordingTime() -
                         time()) <= 900 or abs(NavigationInstance.instance.
                                               RecordTimer.getNextZapTime() -
                                               time()) <= 900:
                    self.do_backoff()
                    # retry
                    self.begin = time() + self.backoff
                    if self.end <= self.begin:
                        self.end = self.begin
                    return False
                if not Screens.Standby.inTryQuitMainloop:  # not a shutdown messagebox is open
                    if Screens.Standby.inStandby:  # in standby
                        quitMainloop(1)
                    else:
                        Notifications.AddNotificationWithCallback(
                            self.sendTryQuitMainloopNotification,
                            MessageBox,
                            _("A finished power timer wants to shut down\nyour %s %s. Shutdown now?"
                              ) % (getMachineBrand(), getMachineName()),
                            timeout=180)
            return True