<commit_before>from enigma import getDesktop, iPlayableService, eTimer, eServiceReference

from Components.Label import Label
from Components.Pixmap import Pixmap
from Components.ProgressBar import ProgressBar
from Components.ServiceEventTracker import ServiceEventTracker
from Components.ActionMap import NumberActionMap
from Components.config import config
from Components.NimManager import nimmanager

from Screens.Screen import Screen
from Screens.MessageBox import MessageBox

from boxbranding import getImageDistro
from crossepglib import *
from crossepg_locale import _

import os
import sys

from Tools.Directories import resolveFilename, SCOPE_CURRENT_SKIN
try:
	from Tools.Directories import SCOPE_ACTIVE_SKIN
except:
	pass

class CrossEPG_Downloader(Screen):
	LOCK_TIMEOUT_FIXED = 100 	# 100ms for tick - 10 sec
	LOCK_TIMEOUT_ROTOR = 1200 	# 100ms for tick - 120 sec
	
	def __init__(self, session, providers, pcallback = None, noosd = False):
		from Components.Sources.StaticText import StaticText
		from Components.Sources.Progress import Progress
		if (getDesktop(0).size().width() < 800):
			skin = "%s/skins/downloader_sd.xml" % os.path.dirname(sys.modules[__name__].__file__)
			self.isHD = 0
		else:
			skin = "%s/skins/downloader_hd.xml" % os.path.dirname(sys.modules[__name__].__file__)
			self.isHD = 1
		f = open(skin, "r")
		self.skin = f.read()
		f.close()
		Screen.__init__(self, session)

		self.session = session

		self["background"] = Pixmap()
		self["action"] = Label(_("Starting downloader"))
		self["status"] = Label("")
		self["progress"] = ProgressBar()
		self["progress"].hide()
		self["progress_text"] = Progress()
		self["summary_action"] = StaticText(_("Starting downloader"))
		self["summary_status"] = StaticText()
		self["summary_progress"] = Progress()
		self["actions"] = NumberActionMap(["WizardActions", "InputActions"],
		{
			"back": self.quit
		}, -1)

		self.frontend = None
		self.rawchannel = None
		self.retValue = True
		self.provider_index = 0
		self.status = 0
		self.open = False
		self.saved = False
		self.oldService = None

		# make config
		for slot in nimmanager.nim_slots:
			if slot.canBeCompatible("DVB-S"):
				try:
					slot.config.dvbs
					self.legacy = False
				except:
					self.legacy = True
			break

		self.config = CrossEPG_Config()
		self.config.load()
		self.providers = providers
		self.pcallback = pcallback

		self.wrapper = CrossEPG_Wrapper()
		self.wrapper.addCallback(self.wrapperCallback)

		self.hideprogress = eTimer()
		self.hideprogress.callback.append(self["progress"].hide)

		self.pcallbacktimer = eTimer()
		self.pcallbacktimer.callback.append(self.doCallback)

		self.wrappertimer = eTimer()
		self.wrappertimer.callback.append(self.initWrapper)

		if noosd:
			self.wrappertimer.start(100, 1)
		else:
			self.onFirstExecBegin.append(self.firstExec)

	def firstExec(self):
		if self.isHD:
			try:
				png = resolveFilename(SCOPE_ACTIVE_SKIN, "crossepg/background_hd.png")
			except:
				png = resolveFilename(SCOPE_CURRENT_SKIN, "skin_default/crossepg/background_hd.png")
			if png == None or not os.path.exists(png):
				png = "%s/images/background_hd.png" % os.path.dirname(sys.modules[__name__].__file__)
		else:
			try:
				png = resolveFilename(SCOPE_ACTIVE_SKIN, "crossepg/background.png")
			except:
				png = resolveFilename(SCOPE_CURRENT_SKIN, "skin_default/crossepg/background.png")
			if png == None or not os.path.exists(png):
				png = "%s/images/background.png" % os.path.dirname(sys.modules[__name__].__file__)
		self["background"].instance.setPixmapFromFile(png)
		self.wrappertimer.start(100, 1)

	def initWrapper(self):
		if len(self.providers) == 0:
			self.closeAndCallback(True)
		else:
			if getImageDistro() != "openvix":
				self.wrapper.init(CrossEPG_Wrapper.CMD_DOWNLOADER, self.config.db_root)
			else:
				self.wrapper.init(CrossEPG_Wrapper.CMD_DOWNLOADER, config.misc.epgcachepath.value + 'crossepg')

	def download(self):
		if self.config.getChannelProtocol(self.providers[self.provider_index]) != "script":
			if not self.open:
				self.wrapper.open()
				self.open = True
				self.saved = False
		else:
			if self.open:
				self.wrapper.save()
				self.saved = True
				self.provider_index -= 1
				return

		transponder = self.config.getTransponder(self.providers[self.provider_index])
		if transponder:
			self.doTune(transponder)
		else:
			self.wrapper.download(self.providers[self.provider_index])
			
	def error(self, message):
		print "[CrossEPG_Downloader] Error: %s" % message
		self.session.open(MessageBox, _("CrossEPG error: %s") % (message), type = MessageBox.TYPE_INFO, timeout = 20)
		self.retValue = False
		self.quit()
		
	def doTune(self, transponder):
		nimList = []
		for nim in nimmanager.nim_slots:
			if not nim.isCompatible("DVB-S"):
				continue
			if not self.legacy:
				config = nim.config.dvbs
			else:
				config = nim.config
			
			config_mode = config.configMode.value

			if config_mode == 'advanced':
				try:
					if config.Nims[nim.slot].advanced.unicableconnected is not None and config.Nims[nim.slot].advanced.unicableconnected.value == True:
						continue # do not load FBC links, only root tuners
				except:
					pass
			if config_mode not in ("loopthrough", "satposdepends", "nothing"):
				nimList.append(nim.slot)
		if len(nimList) == 0:
			self.error(_("No DVB-S NIMs founds"))
			print "[CrossEPG_Downloader] No DVB-S NIMs founds."
			return

		resmanager = eDVBResourceManager.getInstance()
		if not resmanager:
			self.error("Cannot retrieve Resource Manager instance")
			print "[CrossEPG_Downloader] Cannot retrieve Resource Manager instance."
			return

		# stop pip if running<commit_msg>change variable name as requeted<commit_after>from enigma import getDesktop, iPlayableService, eTimer, eServiceReference

from Components.Label import Label
from Components.Pixmap import Pixmap
from Components.ProgressBar import ProgressBar
from Components.ServiceEventTracker import ServiceEventTracker
from Components.ActionMap import NumberActionMap
from Components.config import config
from Components.NimManager import nimmanager

from Screens.Screen import Screen
from Screens.MessageBox import MessageBox

from boxbranding import getImageDistro
from crossepglib import *
from crossepg_locale import _

import os
import sys

from Tools.Directories import resolveFilename, SCOPE_CURRENT_SKIN
try:
	from Tools.Directories import SCOPE_ACTIVE_SKIN
except:
	pass

class CrossEPG_Downloader(Screen):
	LOCK_TIMEOUT_FIXED = 100 	# 100ms for tick - 10 sec
	LOCK_TIMEOUT_ROTOR = 1200 	# 100ms for tick - 120 sec
	
	def __init__(self, session, providers, pcallback = None, noosd = False):
		from Components.Sources.StaticText import StaticText
		from Components.Sources.Progress import Progress
		if (getDesktop(0).size().width() < 800):
			skin = "%s/skins/downloader_sd.xml" % os.path.dirname(sys.modules[__name__].__file__)
			self.isHD = 0
		else:
			skin = "%s/skins/downloader_hd.xml" % os.path.dirname(sys.modules[__name__].__file__)
			self.isHD = 1
		f = open(skin, "r")
		self.skin = f.read()
		f.close()
		Screen.__init__(self, session)

		self.session = session

		self["background"] = Pixmap()
		self["action"] = Label(_("Starting downloader"))
		self["status"] = Label("")
		self["progress"] = ProgressBar()
		self["progress"].hide()
		self["progress_text"] = Progress()
		self["summary_action"] = StaticText(_("Starting downloader"))
		self["summary_status"] = StaticText()
		self["summary_progress"] = Progress()
		self["actions"] = NumberActionMap(["WizardActions", "InputActions"],
		{
			"back": self.quit
		}, -1)

		self.frontend = None
		self.rawchannel = None
		self.retValue = True
		self.provider_index = 0
		self.status = 0
		self.open = False
		self.saved = False
		self.oldService = None

		# make config
		for slot in nimmanager.nim_slots:
			if slot.canBeCompatible("DVB-S"):
				try:
					slot.config.dvbs
					self.legacy = False
				except:
					self.legacy = True
			break

		self.config = CrossEPG_Config()
		self.config.load()
		self.providers = providers
		self.pcallback = pcallback

		self.wrapper = CrossEPG_Wrapper()
		self.wrapper.addCallback(self.wrapperCallback)

		self.hideprogress = eTimer()
		self.hideprogress.callback.append(self["progress"].hide)

		self.pcallbacktimer = eTimer()
		self.pcallbacktimer.callback.append(self.doCallback)

		self.wrappertimer = eTimer()
		self.wrappertimer.callback.append(self.initWrapper)

		if noosd:
			self.wrappertimer.start(100, 1)
		else:
			self.onFirstExecBegin.append(self.firstExec)

	def firstExec(self):
		if self.isHD:
			try:
				png = resolveFilename(SCOPE_ACTIVE_SKIN, "crossepg/background_hd.png")
			except:
				png = resolveFilename(SCOPE_CURRENT_SKIN, "skin_default/crossepg/background_hd.png")
			if png == None or not os.path.exists(png):
				png = "%s/images/background_hd.png" % os.path.dirname(sys.modules[__name__].__file__)
		else:
			try:
				png = resolveFilename(SCOPE_ACTIVE_SKIN, "crossepg/background.png")
			except:
				png = resolveFilename(SCOPE_CURRENT_SKIN, "skin_default/crossepg/background.png")
			if png == None or not os.path.exists(png):
				png = "%s/images/background.png" % os.path.dirname(sys.modules[__name__].__file__)
		self["background"].instance.setPixmapFromFile(png)
		self.wrappertimer.start(100, 1)

	def initWrapper(self):
		if len(self.providers) == 0:
			self.closeAndCallback(True)
		else:
			if getImageDistro() != "openvix":
				self.wrapper.init(CrossEPG_Wrapper.CMD_DOWNLOADER, self.config.db_root)
			else:
				self.wrapper.init(CrossEPG_Wrapper.CMD_DOWNLOADER, config.misc.epgcachepath.value + 'crossepg')

	def download(self):
		if self.config.getChannelProtocol(self.providers[self.provider_index]) != "script":
			if not self.open:
				self.wrapper.open()
				self.open = True
				self.saved = False
		else:
			if self.open:
				self.wrapper.save()
				self.saved = True
				self.provider_index -= 1
				return

		transponder = self.config.getTransponder(self.providers[self.provider_index])
		if transponder:
			self.doTune(transponder)
		else:
			self.wrapper.download(self.providers[self.provider_index])
			
	def error(self, message):
		print "[CrossEPG_Downloader] Error: %s" % message
		self.session.open(MessageBox, _("CrossEPG error: %s") % (message), type = MessageBox.TYPE_INFO, timeout = 20)
		self.retValue = False
		self.quit()
		
	def doTune(self, transponder):
		nimList = []
		for nim in nimmanager.nim_slots:
			if not nim.isCompatible("DVB-S"):
				continue
			if not self.legacy:
				nimconfig = nim.config.dvbs
			else:
				nimconfig = nim.config
			
			config_mode = nimconfig.configMode.value

			if config_mode == 'advanced':
				try:
					if config.Nims[nim.slot].advanced.unicableconnected is not None and config.Nims[nim.slot].advanced.unicableconnected.value == True:
						continue # do not load FBC links, only root tuners
				except:
					pass
			if config_mode not in ("loopthrough", "satposdepends", "nothing"):
				nimList.append(nim.slot)
		if len(nimList) == 0:
			self.error(_("No DVB-S NIMs founds"))
			print "[CrossEPG_Downloader] No DVB-S NIMs founds."
			return

		resmanager = eDVBResourceManager.getInstance()
		if not resmanager:
			self.error("Cannot retrieve Resource Manager instance")
			print "[CrossEPG_Downloader] Cannot retrieve Resource Manager instance."
			return

		# stop pip if running
{'fraction_non_alphanumeric': 0.11445677055819686, 'fraction_numerical': 0.007043493572812115, 'mean_word_length': 4.2466512702078525, 'pattern_counts': {'":': 6, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3421383', 'n_tokens_mistral': 4376, 'n_tokens_neox': 3756, 'n_words': 811}