Exemplo n.º 1
0
    def restoreFiles(self):
        if path.exists(ATFN):
            check_tar = False
            lines = popen('tar -tf %s' % ATFN).readlines()
            for line in lines:
                pos = line.find('tmp/.autotimeredit')
                if pos != -1:
                    check_tar = True
                    break
            if check_tar:
                lines = popen('tar xvf %s -C /' % ATFN).readlines()

                from Plugins.Extensions.AutoTimer.plugin import autotimer
                if autotimer is not None:
                    try:
                        # Force config reload
                        autotimer.configMtime = -1
                        autotimer.readXml()
                    except Exception:
                        # TODO: proper error handling
                        pass

                remove(ATFN)
                return (True, "AutoTimer-settings were restored successfully")
            else:
                return (
                    False,
                    "Error, %s was not created with AutoTimerWebEditor..." %
                    ATFN)
        else:
            return (False,
                    "Error, %s does not exists, restore is not possible..." %
                    ATFN)
Exemplo n.º 2
0
    def restoreFiles(self, param):
        backupFilename = param
        if path.exists(backupFilename):
            if 'tmp/.autotimeredit' in check_output(
                ['tar', '-tf', backupFilename]):
                call(['tar', '-xvf', backupFilename, '-C', '/'])

                from Plugins.Extensions.AutoTimer.plugin import autotimer
                if autotimer is not None:
                    try:
                        # Force config reload
                        autotimer.configMtime = -1
                        autotimer.readXml()
                    except Exception:
                        # TODO: proper error handling
                        pass

                remove(backupFilename)
                return (True, "AutoTimer-settings were restored successfully")
            else:
                return (
                    False,
                    "Error, %s was not created with AutoTimerWebEditor..." %
                    backupFilename)
        else:
            return (False,
                    "Error, %s does not exists, restore is not possible..." %
                    backupFilename)
Exemplo n.º 3
0
	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
Exemplo n.º 4
0
	def restoreFiles(self, param):
		backupFilename = param
		if path.exists(backupFilename):
			check_tar = False
			lines = popen('tar -tf %s' % backupFilename).readlines()
			for line in lines:
				pos = line.find('tmp/.autotimeredit')
				if pos != -1:
					check_tar = True
					break
			if check_tar:
				lines = popen('tar xvf %s -C /' % backupFilename).readlines()

				from Plugins.Extensions.AutoTimer.plugin import autotimer
				if autotimer is not None:
					try:
						# Force config reload
						autotimer.configMtime = -1
						autotimer.readXml()
					except Exception:
						# TODO: proper error handling
						pass
				
				remove(backupFilename)
				return (True, "AutoTimer-settings were restored successfully")
			else:
				return (False, "Error, %s was not created with AutoTimerWebEditor..." % backupFilename)
		else:
			return (False, "Error, %s does not exists, restore is not possible..." % backupFilename)
Exemplo n.º 5
0
    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
Exemplo n.º 6
0
    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
Exemplo n.º 7
0
 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)
Exemplo n.º 8
0
    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
Exemplo n.º 9
0
    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
Exemplo n.º 10
0
	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
Exemplo n.º 11
0
    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()
Exemplo n.º 12
0
 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.plugin import autotimer
         try:
             if autotimer is not None:
                 autotimer.readXml()
                 return ''.join(autotimer.getXml())
         except Exception:
             return '<?xml version="1.0" encoding="UTF-8" ?><e2simplexmlresult><e2state>false</e2state><e2statetext>AutoTimer Config not found</e2statetext></e2simplexmlresult>'
     except ImportError:
         return '<?xml version="1.0" encoding="UTF-8" ?><e2simplexmlresult><e2state>false</e2state><e2statetext>AutoTimer Plugin not found</e2statetext></e2simplexmlresult>'
Exemplo n.º 13
0
	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.plugin import autotimer
			try:
				if autotimer is not None:
					autotimer.readXml()
					return ''.join(autotimer.getXml())
			except Exception:
				return '<?xml version="1.0" encoding="UTF-8" ?><e2simplexmlresult><e2state>false</e2state><e2statetext>AutoTimer Config not found</e2statetext></e2simplexmlresult>'
		except ImportError:
			return '<?xml version="1.0" encoding="UTF-8" ?><e2simplexmlresult><e2state>false</e2state><e2statetext>AutoTimer Plugin not found</e2statetext></e2simplexmlresult>'
Exemplo n.º 14
0
	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()
Exemplo n.º 15
0
    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)
Exemplo n.º 16
0
    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 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)
Exemplo n.º 18
0
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)
Exemplo n.º 19
0
    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()
Exemplo n.º 20
0
	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

		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[:]

		scanServices = []
		channelIdList = []
		for scanservice in self.services[0].union(additionalServices):
			service = eServiceReference(scanservice.sref)
			if not service.valid() \
				or (service.flags & (eServiceReference.isMarker|eServiceReference.isDirectory)):

				continue

			channelID = '%08x%04x%04x' % (
				service.getUnsignedData(4), # NAMESPACE
				service.getUnsignedData(2), # TSID
				service.getUnsignedData(3), # ONID
			)

			if channelID not in channelIdList:
				scanServices.append(scanservice)
				channelIdList.append(channelID)
		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()
	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)
Exemplo n.º 22
0
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: