X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/78852d8e7eb86a36e15d0fe5dd77fcfc624084c1..684910d920f90134ade6dd3b944a749336a47029:/RecordTimer.py diff --git a/RecordTimer.py b/RecordTimer.py index a6c19c05..f670417a 100644 --- a/RecordTimer.py +++ b/RecordTimer.py @@ -1,25 +1,23 @@ -import time -#from time import datetime -from Tools import Directories, Notifications, ASCIItranslit - -from Components.config import config -import timer -import xml.etree.cElementTree - from enigma import eEPGCache, getBestPlayableServiceReference, \ eServiceReference, iRecordableService, quitMainloop -from Screens.MessageBox import MessageBox +from Components.config import config +from Components.UsageConfig import defaultMoviePath from Components.TimerSanityCheck import TimerSanityCheck -import NavigationInstance +from Screens.MessageBox import MessageBox import Screens.Standby - -from time import localtime - +from Tools import Directories, Notifications, ASCIItranslit from Tools.XMLTools import stringToXML + +import timer +import xml.etree.cElementTree +import NavigationInstance from ServiceReference import ServiceReference +from time import localtime, strftime, ctime, time +from bisect import insort + # ok, for descriptions etc we have: # service reference (to get the service name) # name (title) @@ -65,8 +63,8 @@ class RecordTimerEntry(timer.TimerEntry, object): recordings = NavigationInstance.instance.getRecordings() if not recordings: # no more recordings exist rec_time = NavigationInstance.instance.RecordTimer.getNextRecordingTime() - if rec_time > 0 and (rec_time - time.time()) < 360: - print "another recording starts in", rec_time - time.time(), "seconds... do not shutdown yet" + if rec_time > 0 and (rec_time - time()) < 360: + print "another recording starts in", rec_time - time(), "seconds... do not shutdown yet" else: print "no starting records in the next 360 seconds... immediate shutdown" RecordTimerEntry.shutdown() # immediate shutdown @@ -96,8 +94,8 @@ class RecordTimerEntry(timer.TimerEntry, object): timer.TimerEntry.__init__(self, int(begin), int(end)) if checkOldTimers == True: - if self.begin < time.time() - 1209600: - self.begin = int(time.time()) + if self.begin < time() - 1209600: + self.begin = int(time()) if self.end < self.begin: self.end = self.begin @@ -125,12 +123,12 @@ class RecordTimerEntry(timer.TimerEntry, object): self.resetState() def log(self, code, msg): - self.log_entries.append((int(time.time()), code, msg)) + self.log_entries.append((int(time()), code, msg)) print "[TIMER]", msg def calculateFilename(self): service_name = self.service_ref.getServiceName() - begin_date = time.strftime("%Y%m%d %H%M", time.localtime(self.begin)) + begin_date = strftime("%Y%m%d %H%M", localtime(self.begin)) print "begin_date: ", begin_date print "service_name: ", service_name @@ -144,11 +142,13 @@ class RecordTimerEntry(timer.TimerEntry, object): if config.recording.ascii_filenames.value: filename = ASCIItranslit.legacyEncode(filename) - if self.dirname and not Directories.fileExists(self.dirname, 'w'): - self.dirnameHadToFallback = True - self.Filename = Directories.getRecordingFilename(filename, None) + if not self.dirname or not Directories.fileExists(self.dirname, 'w'): + if self.dirname: + self.dirnameHadToFallback = True + dirname = defaultMoviePath() else: - self.Filename = Directories.getRecordingFilename(filename, self.dirname) + dirname = self.dirname + self.Filename = Directories.getRecordingFilename(filename, dirname) self.log(0, "Filename calculated as: '%s'" % self.Filename) #begin_date + " - " + service_name + description) @@ -194,7 +194,7 @@ class RecordTimerEntry(timer.TimerEntry, object): # we must calc nur start time before stopRecordService call because in Screens/Standby.py TryQuitMainloop tries to get # the next start time in evEnd event handler... self.do_backoff() - self.start_prepare = time.time() + self.backoff + self.start_prepare = time() + self.backoff NavigationInstance.instance.stopRecordService(self.record_service) self.record_service = None @@ -221,7 +221,8 @@ class RecordTimerEntry(timer.TimerEntry, object): # because another recording at the same time on another service can try to record the same event # i.e. cable / sat.. then the second recording needs an own extension... when we create the file # here than calculateFilename is happy - open(self.Filename + ".ts", "w").close() + if not self.justplay: + open(self.Filename + ".ts", "w").close() # fine. it worked, resources are allocated. self.next_activation = self.begin self.backoff = 0 @@ -268,7 +269,7 @@ class RecordTimerEntry(timer.TimerEntry, object): self.log(13, "start record returned %d" % record_res) self.do_backoff() # retry - self.begin = time.time() + self.backoff + self.begin = time() + self.backoff return False return True @@ -297,7 +298,7 @@ class RecordTimerEntry(timer.TimerEntry, object): if not self.autoincrease: return False if entry is None: - new_end = int(time.time()) + self.autoincreasetime + new_end = int(time()) + self.autoincreasetime else: new_end = entry.begin -30 @@ -310,7 +311,7 @@ class RecordTimerEntry(timer.TimerEntry, object): del simulTimerList new_end -= 30 # 30 Sekunden Prepare-Zeit lassen del dummyentry - if new_end <= time.time(): + if new_end <= time(): return False self.end = new_end return True @@ -348,7 +349,7 @@ class RecordTimerEntry(timer.TimerEntry, object): self.backoff = 0 if int(old_prepare) != int(self.start_prepare): - self.log(15, "record time changed, start prepare is now: %s" % time.ctime(self.start_prepare)) + self.log(15, "record time changed, start prepare is now: %s" % ctime(self.start_prepare)) def gotRecordEvent(self, record, event): # TODO: this is not working (never true), please fix. (comparing two swig wrapped ePtrs) @@ -440,7 +441,36 @@ class RecordTimer(timer.Timer): self.loadTimer() except IOError: print "unable to load timers from file!" - + + def doActivate(self, w): + # when activating a timer which has already passed, + # simply abort the timer. don't run trough all the stages. + if w.shouldSkip(): + w.state = RecordTimerEntry.StateEnded + else: + # when active returns true, this means "accepted". + # otherwise, the current state is kept. + # the timer entry itself will fix up the delay then. + if w.activate(): + w.state += 1 + + self.timer_list.remove(w) + + # did this timer reached the last state? + if w.state < RecordTimerEntry.StateEnded: + # no, sort it into active list + insort(self.timer_list, w) + else: + # yes. Process repeated, and re-add. + if w.repeated: + w.processRepeated() + w.state = RecordTimerEntry.StateWaiting + self.addTimerEntry(w) + else: + insort(self.processed_timers, w) + + self.stateChanged(w) + def isRecording(self): isRunning = False for timer in self.timer_list: @@ -572,7 +602,7 @@ class RecordTimer(timer.Timer): file.close() def getNextZapTime(self): - now = time.time() + now = time() for timer in self.timer_list: if not timer.justplay or timer.begin < now: continue @@ -580,7 +610,7 @@ class RecordTimer(timer.Timer): return -1 def getNextRecordingTime(self): - now = time.time() + now = time() for timer in self.timer_list: next_act = timer.getNextActivation() if timer.justplay or next_act < now: @@ -589,7 +619,7 @@ class RecordTimer(timer.Timer): return -1 def isNextRecordAfterEventActionAuto(self): - now = time.time() + now = time() t = None for timer in self.timer_list: if timer.justplay or timer.begin < now: @@ -663,7 +693,7 @@ class RecordTimer(timer.Timer): chktimecmp_end = chktimecmp + (duration / 60) time = localtime(x.begin) for y in (0, 1, 2, 3, 4, 5, 6): - if x.repeated & (2 ** y) and (x.begin <= begin or begin <= x.begin <= end): + if x.repeated & (1 << y) and (x.begin <= begin or begin <= x.begin <= end): timecmp = y * 1440 + time.tm_hour * 60 + time.tm_min if timecmp <= chktimecmp < (timecmp + ((x.end - x.begin) / 60)): time_match = ((timecmp + ((x.end - x.begin) / 60)) - chktimecmp) * 60