def importFromAutoTimer(self): removeInstance = False try: # Import Instance from Plugins.Extensions.AutoTimer.plugin import autotimer if autotimer is None: removeInstance = True # Create an instance from Plugins.Extensions.AutoTimer.AutoTimer import AutoTimer autotimer = AutoTimer() # Read in configuration autotimer.readXml() except Exception as e: self.session.open(MessageBox, _("Could not read AutoTimer timer list: %s") % e, type=MessageBox.TYPE_ERROR) else: # Fetch match strings # XXX: we could use the timer title as description options = [(x.match, x.match) for x in autotimer.getTimerList()] self.session.openWithCallback(self.searchEPGWrapper, ChoiceBox, title=_("Select text to search for"), list=options) finally: # Remove instance if there wasn't one before if removeInstance: autotimer = None
def openAutoTimerList(self): self.closeEventViewDialog() global autopoller global autotimer try: from Plugins.Extensions.AutoTimer.AutoPoller import AutoPoller from Plugins.Extensions.AutoTimer.AutoTimer import AutoTimer from Plugins.Extensions.AutoTimer.plugin import autostart, main autopoller = AutoPoller() autotimer = AutoTimer() try: autotimer.readXml() except SyntaxError as se: self.session.open( MessageBox, _("Your config file is not well formed:\n%s") % str(se), type=MessageBox.TYPE_ERROR, timeout=10) return if autopoller is not None: autopoller.stop() from Plugins.Extensions.AutoTimer.AutoTimerOverview import AutoTimerOverview self.session.openWithCallback(self.editCallback, AutoTimerOverview, autotimer) except ImportError: self.session.open(MessageBox, self.noAutotimer, type=MessageBox.TYPE_INFO, timeout=10)
def cleanUp(self): config.plugins.epgrefresh.lastscan.value = int(time()) config.plugins.epgrefresh.lastscan.save() # Eventually force autotimer to parse epg if config.plugins.epgrefresh.parse_autotimer.value: removeInstance = False try: # Import Instance from Plugins.Extensions.AutoTimer.plugin import autotimer if autotimer is None: removeInstance = True # Create an instance from Plugins.Extensions.AutoTimer.AutoTimer import AutoTimer autotimer = AutoTimer() # Parse EPG autotimer.parseEPG() except Exception as e: print("[EPGRefresh] Could not start AutoTimer:", e) finally: # Remove instance if there wasn't one before if removeInstance: autotimer = None self.finish()
def generateServicelist(self, services, bouquets): # This will hold services which are not explicitely in our list additionalServices = [] additionalBouquets = [] # See if we are supposed to read in autotimer services if config.plugins.epgrefresh.inherit_autotimer.value: removeInstance = False try: # Import Instance from Plugins.Extensions.AutoTimer.plugin import autotimer if autotimer is None: removeInstance = True # Create an instance from Plugins.Extensions.AutoTimer.AutoTimer import AutoTimer autotimer = AutoTimer() # Read in configuration autotimer.readXml() except Exception as e: print("[EPGRefresh] Could not inherit AutoTimer Services:", e) else: # Fetch services for timer in autotimer.getEnabledTimerList(): additionalServices.extend( [EPGRefreshService(x, None) for x in timer.services]) additionalBouquets.extend( [EPGRefreshService(x, None) for x in timer.bouquets]) finally: # Remove instance if there wasn't one before if removeInstance: autotimer = None scanServices = [] channelIdList = [] self.addServices(services, scanServices, channelIdList) serviceHandler = eServiceCenter.getInstance() for bouquet in bouquets.union(additionalBouquets): myref = eServiceReference(bouquet.sref) list = serviceHandler.list(myref) if list is not None: while 1: s = list.getNext() # TODO: I wonder if its sane to assume we get services here (and not just new lists) if s.valid(): additionalServices.append( EPGRefreshService(s.toString(), None)) else: break del additionalBouquets[:] self.addServices(additionalServices, scanServices, channelIdList) del additionalServices[:] return scanServices
def getPartnerboxAutoTimerListCallback(self, result, partnerboxentry): if result is not None: from Plugins.Extensions.AutoTimer.AutoTimer import AutoTimer autotimer = AutoTimer() autotimer.readXml(xml_string=result) self.session.openWithCallback( boundFunction(self.callbackAutoTimerOverview, partnerboxentry, autotimer), PartnerboxAutoTimerOverview, autotimer, partnerboxentry.name.value)
def generateServicelist(self, services, bouquets): additionalServices = [] additionalBouquets = [] if config.plugins.epgrefresh.inherit_autotimer.value: try: from Plugins.Extensions.AutoTimer.plugin import autotimer if autotimer is None: from Plugins.Extensions.AutoTimer.AutoTimer import AutoTimer autotimer = AutoTimer() autotimer.readXml() except Exception as e: print("[EPGRefresh] Could not inherit AutoTimer Services:", e) else: for timer in autotimer.getEnabledTimerList(): additionalServices.extend( [EPGRefreshService(x, None) for x in timer.services]) additionalBouquets.extend( [EPGRefreshService(x, None) for x in timer.bouquets]) scanServices = [] channelIdList = [] self.addServices(services, scanServices, channelIdList) serviceHandler = eServiceCenter.getInstance() for bouquet in bouquets.union(additionalBouquets): myref = eServiceReference(bouquet.sref) list = serviceHandler.list(myref) if list is not None: while 1: s = list.getNext() if s and s.valid() and s.type == eServiceReference.idDVB: additionalServices.append( EPGRefreshService(s.toString(), None)) else: break del additionalBouquets[:] def sortServices(services): # sort by positions - better for motor unsortedServices = [] for service in services: ref = service.sref position = ref.split(":")[6][:-4] if not position: position = "0" auxiliarySortParameter = int(position, 16) if auxiliarySortParameter > 1800: auxiliarySortParameter = 3600 - auxiliarySortParameter unsortedServices.append((auxiliarySortParameter, service)) unsortedServices.sort() sortedServices = [] for service in unsortedServices: sortedServices.append(service[1]) return sortedServices self.addServices(additionalServices, scanServices, channelIdList) scanServices = sortServices(scanServices) del additionalServices[:] return scanServices
def __init__(self): self.timezones = {} self.readTimezonesFromSystem() if path.exists( "/usr/lib/enigma2/python/Plugins/Extensions/AutoTimer/plugin.pyo" ): from Plugins.Extensions.AutoTimer.AutoTimer import AutoTimer from Plugins.Extensions.AutoTimer.AutoPoller import AutoPoller self.autopoller = AutoPoller() self.autotimer = AutoTimer() self.timer = eTimer() self.ATupdate = None
def cleanUp(self): config.plugins.epgrefresh.lastscan.value = int(time()) config.plugins.epgrefresh.lastscan.save() if config.plugins.epgrefresh.save_epg.value: try: from enigma import eEPGCache epgcache = eEPGCache.getInstance() epgcache.save() print("[EPGRefresh] save epgcache...") except: pass if config.plugins.epgrefresh_extra.save_backup.value and config.plugins.epgrefresh_extra.epgcachepath.value != "/etc/enigma2/": from os import system as my_system from os import chmod as my_chmod from os import path as my_path restore_backup = config.misc.epgcache_filename.value + ".backup" if my_path.exists(config.misc.epgcache_filename.value): try: my_system("cp -f %s %s" % (config.misc.epgcache_filename.value, restore_backup)) my_chmod("%s" % (restore_backup), 0644) print("[EPGRefresh] save epgcache backup...") except: pass if config.plugins.epgrefresh.parse_autotimer.value: try: from Plugins.Extensions.AutoTimer.plugin import autotimer if autotimer is None: from Plugins.Extensions.AutoTimer.AutoTimer import AutoTimer autotimer = AutoTimer() autotimer.readXml() autotimer.parseEPGAsync(simulateOnly=False) if not self.autotimer_pause.isActive(): if config.plugins.epgrefresh.afterevent.value and not self.DontShutdown: try: from Plugins.Extensions.SeriesPlugin.plugin import renameTimer except: self.autotimer_pause.startLongTimer(120) else: self.autotimer_pause.startLongTimer( int(config.plugins.epgrefresh.timeout_shutdown. value) * 60) else: self.finish() except Exception as e: print("[EPGRefresh] Could not start AutoTimer:", e) self.finish() else: self.finish()
def render(self, request): request.setResponseCode(http.OK) request.setHeader('Content-type', 'application/xhtml+xml') request.setHeader('charset', 'UTF-8') try: from Plugins.Extensions.AutoTimer.AutoTimer import AutoTimer autotimer = AutoTimer() try: autotimer.readXml() except Exception: return '<?xml version="1.0" encoding="UTF-8" ?><e2simplexmlresult><e2state>false</e2state><e2statetext>AutoTimer Config not found</e2statetext></e2simplexmlresult>' return ''.join(autotimer.getXml()) except ImportError: return '<?xml version="1.0" encoding="UTF-8" ?><e2simplexmlresult><e2state>false</e2state><e2statetext>AutoTimer Plugin not found</e2statetext></e2simplexmlresult>'
def importFromAutoTimer(self): removeInstance = False try: # Import Instance from Plugins.Extensions.AutoTimer.plugin import autotimer if autotimer is None: removeInstance = True # Create an instance from Plugins.Extensions.AutoTimer.AutoTimer import AutoTimer autotimer = AutoTimer() # Read in configuration autotimer.readXml() except Exception, e: self.session.open(MessageBox, _("Could not read AutoTimer timer list: %s") % e, type=MessageBox.TYPE_ERROR)
def _ToDoCallAutotimerCB(self, parseAT): print("[EPGRefresh] Debug: Call AutoTimer: " + str(parseAT)) if parseAT: try: # Import Instance from Plugins.Extensions.AutoTimer.plugin import autotimer if autotimer is None: # Create an instance from Plugins.Extensions.AutoTimer.AutoTimer import AutoTimer autotimer = AutoTimer() # Parse EPG autotimer.parseEPGAsync(simulateOnly=False).addCallback(self._nextTodo).addErrback(self._autotimerErrback) except: from traceback import format_exc print("[EPGRefresh] Could not start AutoTimer:" + str(format_exc())) self._nextTodo() else: self._nextTodo()
def doneImport(reboot=False, epgfile=None): global _session, lastImportResult, BouquetChannelListList, parse_autotimer, serviceIgnoreList BouquetChannelListList = None serviceIgnoreList = None lastImportResult = (time.time(), epgimport.eventCount) try: start, count = lastImportResult localtime = time.asctime( time.localtime(time.time())) lastimport = "%s, %d" % (localtime, count) config.plugins.extra_epgimport.last_import.value = lastimport config.plugins.extra_epgimport.last_import.save() print>>log, "[EPGImport] Save last import date and count event" except: print>>log, "[EPGImport] Error to save last import date and count event" if reboot: if Screens.Standby.inStandby: print>>log, "[EPGImport] Restart enigma2" restartEnigma(True) else: msg = _("EPG Import finished, %d events") % epgimport.eventCount + "\n" + _("You must restart Enigma2 to load the EPG data,\nis this OK?") _session.openWithCallback(restartEnigma, MessageBox, msg, MessageBox.TYPE_YESNO, timeout = 15, default = True) print>>log, "[EPGImport] Need restart enigma2" else: if config.plugins.epgimport.parse_autotimer.value and fileExists("/usr/lib/enigma2/python/Plugins/Extensions/AutoTimer/plugin.py"): try: from Plugins.Extensions.AutoTimer.plugin import autotimer if autotimer is None: from Plugins.Extensions.AutoTimer.AutoTimer import AutoTimer autotimer = AutoTimer() if not parse_autotimer: autotimer.readXml() checkDeepstandby(_session, parse=True) autotimer.parseEPGAsync(simulateOnly=False) print>>log, "[EPGImport] Run start parse autotimers" parse_autotimer = True except: print>>log, "[EPGImport] Could not start autotimers" checkDeepstandby(_session, parse=False) else: checkDeepstandby(_session, parse=False)
def cleanUp(self): config.plugins.epgrefresh.lastscan.value = int(time()) config.plugins.epgrefresh.lastscan.save() # Eventually force autotimer to parse epg if config.plugins.epgrefresh.parse_autotimer.value: removeInstance = False try: # Import Instance from Plugins.Extensions.AutoTimer.plugin import autotimer if autotimer is None: removeInstance = True # Create an instance from Plugins.Extensions.AutoTimer.AutoTimer import AutoTimer autotimer = AutoTimer() # Parse EPG autotimer.parseEPG() except Exception as e: print("[EPGRefresh] Could not start AutoTimer:", e) finally: # Remove instance if there wasn't one before if removeInstance: autotimer = None # 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(Screens.Standby.TryQuitMainloop, 1) if not Screens.Standby.inStandby and not config.plugins.epgrefresh.background and config.plugins.epgrefresh.enablemessage.value: Notifications.AddNotification(MessageBox, _("EPG refresh finished."), type=MessageBox.TYPE_INFO, timeout=4) self.forcedScan = False epgrefreshtimer.cleanup() self.maybeStopAdapter()
class EPGRefresh: """Simple Class to refresh EPGData""" def __init__(self): # Initialize self.services = (set(), set()) self.previousService = None self.forcedScan = False self.session = None self.beginOfTimespan = 0 # Mtime of configuration files self.configMtime = -1 # Read in Configuration self.readConfiguration() def readConfiguration(self): # Check if file exists if not path.exists(CONFIG): return # Check if file did not change mtime = path.getmtime(CONFIG) if mtime == self.configMtime: return # Keep mtime self.configMtime = mtime # Empty out list self.services[0].clear() self.services[1].clear() # Open file configuration = cet_parse(CONFIG).getroot() # Add References for service in configuration.findall("service"): value = service.text if value: # strip all after last : (custom name) pos = value.rfind(':') if pos != -1: value = value[:pos + 1] duration = service.get('duration', None) duration = duration and int(duration) self.services[0].add(EPGRefreshService(value, duration)) for bouquet in configuration.findall("bouquet"): value = bouquet.text if value: duration = bouquet.get('duration', None) duration = duration and int(duration) self.services[1].add(EPGRefreshService(value, duration)) def buildConfiguration(self, webif=False): list = ['<?xml version="1.0" ?>\n<epgrefresh>\n\n'] if webif: TAGSERVICE = 'e2servicereference' TAGBOUQUET = 'e2servicereference' TAGNAME = 'e2servicename' else: TAGSERVICE = 'service' TAGBOUQUET = 'bouquet' TAGNAME = '!--' for service in self.services[0]: ref = ServiceReference(service.sref) list.extend((' <', TAGNAME, '>', stringToXML(ref.getServiceName().replace( '\xc2\x86', '').replace('\xc2\x87', '')), '</', TAGNAME, '>\n')) list.extend((' <', TAGSERVICE)) if service.duration is not None: list.extend((' duration="', str(service.duration), '"')) list.extend( ('>', stringToXML(service.sref), '</', TAGSERVICE, '>\n')) for bouquet in self.services[1]: ref = ServiceReference(bouquet.sref) list.extend((' <', TAGNAME, '>', stringToXML(ref.getServiceName().replace( '\xc2\x86', '').replace('\xc2\x87', '')), '</', TAGNAME, '>\n')) list.extend((' <', TAGBOUQUET)) if bouquet.duration is not None: list.extend((' duration="', str(bouquet.duration), '"')) list.extend( ('>', stringToXML(bouquet.sref), '</', TAGBOUQUET, '>\n')) list.append('\n</epgrefresh>') return list def saveConfiguration(self): file = open(CONFIG, 'w') file.writelines(self.buildConfiguration()) file.close() def forceRefresh(self, session=None): print "[EPGRefresh] Forcing start of EPGRefresh" if self.session is None: if session is not None: self.session = session else: return False self.forcedScan = True self.prepareRefresh() return True def start(self, session=None): if session is not None: self.session = session epgrefreshtimer.setRefreshTimer(self.createWaitTimer) def stop(self): print "[EPGRefresh] Stopping Timer" epgrefreshtimer.clear() def prepareRefresh(self): print "[EPGRefresh] About to start refreshing EPG" # Keep service self.previousService = self.session.nav.getCurrentlyPlayingServiceReference( ) # Maybe read in configuration try: self.readConfiguration() except Exception, e: print "[EPGRefresh] Error occured while reading in configuration:", e # This will hold services which are not explicitely in our list additionalServices = [] additionalBouquets = [] # See if we are supposed to read in autotimer services if config.plugins.epgrefresh.inherit_autotimer.value: removeInstance = False try: # Import Instance from Plugins.Extensions.AutoTimer.plugin import autotimer if autotimer is None: removeInstance = True # Create an instance from Plugins.Extensions.AutoTimer.AutoTimer import AutoTimer autotimer = AutoTimer() # Read in configuration autotimer.readXml() except Exception, e: print "[EPGRefresh] Could not inherit AutoTimer Services:", e else: # Fetch services for timer in autotimer.getEnabledTimerList(): additionalServices.extend( [EPGRefreshService(x, None) for x in timer.services]) additionalBouquets.extend( [EPGRefreshService(x, None) for x in timer.bouquets]) finally:
def timerList(self): print("timerList") try: from Plugins.Extensions.AutoTimer.plugin import autotimer if not autotimer: from Plugins.Extensions.AutoTimer.AutoTimer import AutoTimer autotimer = AutoTimer() except ImportError: return [] returnList = [] for timer in autotimer.getTimerList(): print("TIMER: ", timer) innerList = [timer.getName(), timer.getMatch()] if timer.hasAfterEvent(): innerList.append(timer.getAfterEvent()) # 2 else: innerList.append("") # 2 #excludes innerList.extend(( timer.getExcludedTitle(), timer.getExcludedShort(), timer.getExcludedDescription(), timer.getExcludedDays(), )) #includes innerList.extend(( timer.getIncludedTitle(), timer.getIncludedShort(), timer.getIncludedDescription(), timer.getIncludedDays(), )) # services innerList.extend(( timer.getServices(), # 11 timer.getBouquets() # 12 )) if timer.hasTimespan(): innerList.extend(( timer.getTimespanBegin(), # 13 timer.getTimespanEnd() # 14 )) else: innerList.extend(("", "")) # 13, 14 if timer.hasDuration(): innerList.append(timer.getDuration()) # 15 else: innerList.append("") # 15 if timer.hasCounter(): innerList.extend(( timer.getCounter(), # 16 timer.getCounterLeft() # 17 )) else: innerList.extend((0, 0)) # 16, 17 innerList.append(timer.getCounterLimit()) # 18 if timer.hasDestination(): innerList.append(timer.destination) # 19 else: innerList.append(resolveFilename(SCOPE_HDD)) # 19 if timer.hasCounterFormatString(): innerList.append(timer.getCounterFormatString()) # 20 else: innerList.append("") # 20 innerList.extend(( timer.getLastBegin(), # 21 timer.getJustplay(), # 22 timer.getAvoidDuplicateDescription() # 23 )) if timer.hasTags(): innerList.append(timer.getTags()) # 24 else: innerList.append("") # 24 print("Enabled", timer.getEnabled()) innerList.append(timer.getEnabled()) # 25 innerList.append("off") # 26 returnList.append(innerList) return returnList
def prepareRefresh(self): print("[EPGRefresh] About to start refreshing EPG") # Maybe read in configuration try: self.readConfiguration() except Exception as e: print("[EPGRefresh] Error occured while reading in configuration:", e) # This will hold services which are not explicitely in our list additionalServices = [] additionalBouquets = [] # See if we are supposed to read in autotimer services if config.plugins.epgrefresh.inherit_autotimer.value: removeInstance = False try: # Import Instance from Plugins.Extensions.AutoTimer.plugin import autotimer if autotimer is None: removeInstance = True # Create an instance from Plugins.Extensions.AutoTimer.AutoTimer import AutoTimer autotimer = AutoTimer() # Read in configuration autotimer.readXml() except Exception as e: print("[EPGRefresh] Could not inherit AutoTimer Services:", e) else: # Fetch services for timer in autotimer.getEnabledTimerList(): additionalServices.extend( [EPGRefreshService(x, None) for x in timer.services]) additionalBouquets.extend( [EPGRefreshService(x, None) for x in timer.bouquets]) finally: # Remove instance if there wasn't one before if removeInstance: autotimer = None scanServices = [] channelIdList = [] self.addServices(self.services[0], scanServices, channelIdList) serviceHandler = eServiceCenter.getInstance() for bouquet in self.services[1].union(additionalBouquets): myref = eServiceReference(bouquet.sref) list = serviceHandler.list(myref) if list is not None: while 1: s = list.getNext() # TODO: I wonder if its sane to assume we get services here (and not just new lists) if s.valid(): additionalServices.append( EPGRefreshService(s.toString(), None)) else: break del additionalBouquets[:] self.addServices(additionalServices, scanServices, channelIdList) del additionalServices[:] # Debug print("[EPGRefresh] Services we're going to scan:", ', '.join([repr(x) for x in scanServices])) self.maybeStopAdapter() # NOTE: start notification is handled in adapter initializer if config.plugins.epgrefresh.adapter.value.startswith("pip"): hidden = config.plugins.epgrefresh.adapter.value == "pip_hidden" refreshAdapter = PipAdapter(self.session, hide=hidden) elif config.plugins.epgrefresh.adapter.value.startswith("record"): refreshAdapter = RecordAdapter(self.session) else: refreshAdapter = MainPictureAdapter(self.session) if (not refreshAdapter.backgroundCapable and Screens.Standby.inStandby) or not refreshAdapter.prepare(): print( "[EPGRefresh] Adapter is not able to run in background or not available, falling back to MainPictureAdapter" ) refreshAdapter = MainPictureAdapter(self.session) refreshAdapter.prepare() self.refreshAdapter = refreshAdapter self.scanServices = scanServices self.refresh()