def ParseFromXMLNode(self, oXMLEntry): """ Parses an xms string into object vars """ self.uName = GetXMLTextValue(oXMLEntry, u'name', True, u'Error') self.uAuthor = GetXMLTextValue(oXMLEntry, u'author', False, u'unknown') self.uVersion = GetXMLTextValue(oXMLEntry, u'version', False, u'0') self.uMinOrcaVersion = GetXMLTextValue(oXMLEntry, u'minorcaversion', False, u'1.1.0') self.bSkip = GetXMLBoolValue(oXMLEntry, u'skip', False, False) self.iVersion = ToIntVersion(self.uVersion) self.iMinOrcaVersion = ToIntVersion(self.uMinOrcaVersion) self.oDescriptions.ParseFromXMLNode(oXMLEntry) oXMLSources = oXMLEntry.find(u'sources') if not oXMLSources is None: for oXMLSource in oXMLSources.findall(u'source'): oSource = cRepSource() oSource.ParseFromXMLNode(oXMLSource) self.aSources.append(oSource) oXMLDependencies = oXMLEntry.find(u'dependencies') if not oXMLDependencies is None: for oXMLDependency in oXMLDependencies.findall(u'dependency'): oRepDependency = cRepDependency() oRepDependency.ParseFromXMLNode(oXMLDependency) self.aDependencies.append(oRepDependency) oXMLSkipFiles = oXMLEntry.find(u'skipfiles') if not oXMLSkipFiles is None: oRepSkipFile = cRepSkipFile() for oXMLSkipFile in oXMLSkipFiles.findall(u'file'): oRepSkipFile.ParseFromXMLNode(oXMLSkipFile) oRepSkipFile.uFile = ReplaceVars(oRepSkipFile.uFile) self.aSkipFiles.append(oRepSkipFile) self.aSkipFileNames.append(oRepSkipFile.uFile)
def ParseFromXMLNode(self, *, oXMLNode: Element) -> None: """ Parses an xml string into object vars """ oXMLEntries: Element try: self.uDescription = GetXMLTextValue(oXMLNode=oXMLNode, uTag=u'description', bMandatory=True, vDefault=u'') self.uVersion = GetXMLTextValue(oXMLNode=oXMLNode, uTag=u'version', bMandatory=False, vDefault=u'unknown') self.uRepType = GetXMLTextValue(oXMLNode=oXMLNode, uTag=u'type', bMandatory=False, vDefault=u'unknown') oXMLEntries = oXMLNode.find(u'entries') if not oXMLEntries is None: for oXMLEntry in oXMLEntries.findall(u'entry'): oRepEntry: cRepEntry = cRepEntry() oRepEntry.ParseFromXMLNode(oXMLEntry=oXMLEntry) if not oRepEntry.bSkip: oRepEntry.uRepType = self.uRepType oRepEntry.uUrl = self.uUrl if oRepEntry.iMinOrcaVersion <= Globals.iVersion: self.aRepEntries.append(oRepEntry) else: Logger.warning( "Skip dependency as it needs a newer ORCA Version, Minimum: %d, Orca: %d" % (oRepEntry.iMinOrcaVersion, Globals.iVersion)) except Exception as e: LogError(uMsg=u'Can\'t parse repository:' + self.uUrl, oException=e)
def ParseFromXMLNode(self, *, oXMLNode: Element) -> None: """ Parses an xms string into object vars """ self.uType = GetXMLTextValue(oXMLNode=oXMLNode, uTag=u'type', bMandatory=True, vDefault=u'') self.uName = GetXMLTextValue(oXMLNode=oXMLNode, uTag=u'name', bMandatory=True, vDefault=u'')
def ParseXMLLocales(self,oXMLLocales): """ reads the locales information from the xml (kodi file) """ self.uName = GetXMLTextAttribute(oXMLLocales,u'name',True,u'') self.uLocale = GetXMLTextAttribute(oXMLLocales,u'locale',False,u'EN') self.uDateShort = GetXMLTextValue(oXMLLocales,u'dateshort',False,u'DD.MM.YYYY') self.uDateLong = GetXMLTextValue(oXMLLocales,u'datelong',False,u'DDDD, D MMMM YYYY') self.uTimeFormat= GetXMLTextValue(oXMLLocales,u'time',False,u'H:mm:ss') oXMLTime=oXMLLocales.find('time') if oXMLTime is not None: self.uTimeSymbolAM=GetXMLTextAttribute(oXMLTime,u'symbolAM',False,u'') self.uTimeSymbolPM=GetXMLTextAttribute(oXMLTime,u'symbolPM',False,u'')
def ParseFromXMLNode(self, *, oXMLNode: Element) -> None: """ Parses an xms string into object vars """ self.uSourceFile = GetXMLTextValue(oXMLNode=oXMLNode, uTag=u'sourcefile', bMandatory=True, vDefault=u'') self.uTargetPath = GetXMLTextValue(oXMLNode=oXMLNode, uTag=u'targetpath', bMandatory=True, vDefault=u'') self.uLocal = AdjustPathToOs(uPath=ReplaceVars( GetXMLTextValue(oXMLNode=oXMLNode, uTag=u'local', bMandatory=False, vDefault=u'')))
def ParseFontFromXMLNode(self, *, oXMLNode: Element) -> int: """ Parses a font definition from an xml node :return: The Number of fonts, defined in the XML :param oXMLNode: An elementree xml node """ uFontStyle: str self.uName = GetXMLTextValue(oXMLNode=oXMLNode, uTag=u'name', bMandatory=True, vDefault=u'NoName') iCount: int = 0 for oXMLSingleFont in oXMLNode.findall(u'file'): iCount += 1 uFontStyle = GetXMLTextAttribute(oXMLNode=oXMLSingleFont, uTag=u'face', bMandatory=True, vDefault=u'') if uFontStyle == u'normal': self.oFnNormal.ImportFullPath(uFnFullName=oXMLSingleFont.text) elif uFontStyle == u'bold': self.oFnBold.ImportFullPath(uFnFullName=oXMLSingleFont.text) elif uFontStyle == u'italic': self.oFnItalic.ImportFullPath(uFnFullName=oXMLSingleFont.text) elif uFontStyle == u'bolditalic': self.oFnBoldItalic.ImportFullPath( uFnFullName=oXMLSingleFont.text) else: ShowErrorPopUp(uMessage=LogError( uMsg=u'FontParser: Invalid Tag:' + uFontStyle)) return iCount
def _Parse_XML(self,uResponse,uGetVar): """ parses the result as xml """ if uResponse == u'': return u'', u'' lGetVars = uGetVar.split(',') uResult = uResponse iIndex = 0 UnSplit(lGetVars) if uGetVar == u'': return u'',u'' oNode = ElementTree(fromstring(uResult)) for uVar in lGetVars: self.ShowDebug(u'Parsing Vartoken:' + uVar + " in:"+uResponse) iIndex = iIndex+1 if iIndex != len(lGetVars): oNode = oNode.find(uVar) if oNode is None: self.ShowError(u'can\'t Find xml Value') return u'',u'' else: uResult = GetXMLTextValue(oNode,uVar,False,u'notfound') self._SetVar(uResult,u'Storing Value') return uVar,uResult return u'',u''
def ParseFontFromXMLNode(self, oXMLFont): """ Parses a font definition from an xml node :rtype: int :return: The Number of fonts, defined in the XML :param Element oXMLFont: An elementree xml node """ self.uName = GetXMLTextValue(oXMLFont, u'name', True, u'NoName') iCount = 0 for oXMLSingleFont in oXMLFont.findall(u'file'): iCount = iCount + 1 uFontStyle = GetXMLTextAttribute(oXMLSingleFont, u'face', True, u'') if uFontStyle == u'normal': self.oFnNormal.ImportFullPath(oXMLSingleFont.text) elif uFontStyle == u'bold': self.oFnBold.ImportFullPath(oXMLSingleFont.text) elif uFontStyle == u'italic': self.oFnItalic.ImportFullPath(oXMLSingleFont.text) elif uFontStyle == u'bolditalic': self.oFnBoldItalic.ImportFullPath(oXMLSingleFont.text) else: uMsg = LogError(u'FontParser: Invalid Tag:' + uFontStyle) ShowErrorPopUp(uMessage=uMsg) return iCount
def ParseFromXMLNode(self, oXMLEntry): """ Parses an xms string into object vars """ oXMLDescriptions = oXMLEntry.findall('description') for oXMLDescription in oXMLDescriptions: uLanguage = GetXMLTextAttribute(oXMLDescription, 'language', False, 'English') self.aDescriptions[uLanguage] = GetXMLTextValue( oXMLDescription, '', False, '')
def InitPageFromXmlNode(self, *, oXMLNode: Element) -> None: """ Reads the page parameter from a Xml Node :param Element oXMLNode: The element tree element, root of the page xml :return: None :rtype: None """ self.uPageName = GetXMLTextAttribute(oXMLNode=oXMLNode, uTag=u'name', bMandatory=True, vDefault=u'') oRef: Element = oXMLNode.find(u'page_parameter') self.uDefaultInterface = GetXMLTextValue(oXMLNode=oRef, uTag=u'interface', bMandatory=False, vDefault=u'') self.uDefaultConfigName = GetXMLTextValue(oXMLNode=oRef, uTag=u'configname', bMandatory=False, vDefault=u'') self.bIsPopUp = GetXMLBoolValue(oXMLNode=oRef, uTag=u'popup', bMandatory=False, bDefault=False) self.bPreventPreInit = GetXMLBoolValue(oXMLNode=oRef, uTag=u'preventpreinit', bMandatory=False, bDefault=False) # ToDo: this is temporary to validate some strange default value changes self.uDefaultInterface = ReplaceVars(self.uDefaultInterface) self.uDefaultConfigName = ReplaceVars(self.uDefaultConfigName) #not used self.uOrientation = GetXMLTextValue( oXMLNode=oRef, uTag=u'orientation', bMandatory=False, vDefault=Globals.uDeviceOrientation) if not self.uDefaultInterface == u'': Globals.oInterFaces.dUsedInterfaces[ReplaceVars( self.uDefaultInterface)] = True
def LoadParameter(self): """ Loads the Parameter from the definition XML File """ Logger.info( u'Load Definition Parameter [%s] %s:' % (self.uAlias, self.oDefinitionPathes.oPathDefinition.string)) oET_Root = self.oET_Root #Get Definition Wide Setting oRef = oET_Root.find('def_parameter') self.iFontSize_Button = GetXMLTextValue(oRef, u'fontsize_button', False, '%h100') self.iFontSize_Text = GetXMLTextValue(oRef, u'fontsize_text', False, '%h100') self.iFontSize_File = GetXMLTextValue(oRef, u'fontsize_file', False, 'd11') # we replace the custom definition vars and reparse the xml again self.sET_Data = ReplaceDefVars(self.sET_Data, self.oDefinitionVars) self.oET_Root = Orca_FromString(self.sET_Data, self, "root2") self.uDefaultFont = GetXMLTextValue( oRef, u'defaultfont', True, Globals.oTheScreen.oSkin.dSkinAttributes['defaultfont']) if not self.uDefaultFont: self.uDefaultFont = Globals.oTheScreen.oSkin.dSkinAttributes[ 'defaultfont'] if self.uName == Globals.uDefinitionName: self.oDefinitions.uDefinitionSupport = GetXMLTextValue( oRef, u'support', False, u'') uInstallationHint = GetXMLTextValue(oRef, u'installationhint', False, u'') if uInstallationHint != '': self.oDefinitions.dInstallationsHints[self.uName] = ( "[b][color=#FFFF00]" + self.uDefPublicTitle + u"[/color][/b]\n\n" + uInstallationHint + u"\n\n") if Globals.uStretchMode == "CENTER" or Globals.uStretchMode == "TOPLEFT": fRatio = float( float(Globals.iAppWidth) / float(Globals.iAppHeight)) / float( float(self.iDefMaxX) / float(self.iDefMaxY)) if fRatio < 1: fShouldHeight = float(Globals.iAppWidth) / ( float(self.iDefMaxX) / float(self.iDefMaxY)) self.fRationY = float(self.iDefMaxY) / fShouldHeight if Globals.uStretchMode == "CENTER": self.iGapY = int((( (Globals.iAppHeight * self.fRationX) - self.iDefMaxY) / self.fRationX) / 2) else: fShouldWidth = float(Globals.iAppHeight) / ( float(self.iDefMaxY) / float(self.iDefMaxX)) self.fRationX = float(self.iDefMaxX) / fShouldWidth if Globals.uStretchMode == "CENTER": self.iGapX = int((( (Globals.iAppWidth * self.fRationY) - self.iDefMaxX) / self.fRationY) / 2) return True
def SendCommand(self) -> None: self.bStopWait = False uUrlFull:str = "http://"+self.uIP+"/web/about" try: self.oReq = UrlRequest(uUrlFull,method="GET",timeout=self.fTimeOut,on_error=self.OnResponse,on_success=self.OnResponse) self.NewWait(0.05) if self.oReq.resp_status is not None: uResult:str = self.oReq.result if "<e2abouts>" in uResult: oXmlRoot:Element = LoadXMLString(uXML=uResult) oXmlAbout:Element = oXmlRoot.find("e2about") uModel:str = GetXMLTextValue(oXMLNode=oXmlAbout, uTag="e2model", bMandatory=False, vDefault="Enigma") uFoundHostName:str = "" try: uFoundHostName = socket.gethostbyaddr(self.uIP)[0] except Exception: # Logger.error("Cant get Hostname:"+oRet.uFoundIP+" "+str(e)) pass dResult:TypedQueryDict = TypedQueryDict() dResult.uIP = self.uIP dResult.iPort = 80 dResult.uModel = uModel dResult.uIPVersion = "IPv4" dResult.uHostName = uFoundHostName self.oCaller.aResults.append(dResult) Globals.oNotifications.SendNotification(uNotification="DISCOVER_SCRIPTFOUND",**{"script":self,"scriptname":self.oCaller.uObjectName,"line":[dResult.uIP,dResult.uHostName, str(dResult.iPort), dResult.uModel],"device":dResult}) self.oCaller.ShowInfo(uMsg=u'Discovered Enigma device (V4) %s' % dResult.uIP) try: uIP = "" aIPs = socket.getaddrinfo(uFoundHostName,None) for tIP in aIPs: uIP = "["+tIP[-1][0]+"]" if ":" in uIP: break if ":" in uIP: dResult:TypedQueryDict = TypedQueryDict() dResult.uIP = uIP dResult.iPort = 80 dResult.uModel = uModel dResult.uIPVersion = "IPv6" dResult.uHostName = uFoundHostName self.oCaller.aResults.append(dResult) Globals.oNotifications.SendNotification(uNotification="DISCOVER_SCRIPTFOUND",**{"script":self,"scriptname":self.oCaller.uObjectName,"line":[dResult.uIP,dResult.uHostName, str(dResult.iPort), dResult.uModel],"device":dResult}) self.oCaller.ShowInfo(uMsg=u'Discovered Enigma device (V6) %s' % dResult.uIP) except Exception: pass except Exception as e: self.oCaller.ShowError(uMsg="Error on send:", oException=e) return
def ParseFromXMLNode(self, *, oXMLEntry: Element) -> None: """ Parses an xms string into object vars """ oXMLDescriptions: List[Element] = oXMLEntry.findall('description') for oXMLDescription in oXMLDescriptions: uLanguage: str = GetXMLTextAttribute(oXMLNode=oXMLDescription, uTag='language', bMandatory=False, vDefault='English') self.dDescriptions[uLanguage] = GetXMLTextValue( oXMLNode=oXMLDescription, uTag='', bMandatory=False, vDefault='')
def CheckToRotate(self): """ Check if we need to rotate the screen """ oDef=Globals.oDefinitions[0] oET_Root=oDef.oET_Root #Get Definition Wide Setting oRef = oET_Root.find('def_parameter') for oListDef in Globals.oDefinitions: oListDef.iDefMaxX = GetXMLIntValue(oRef,u'maxx',True,1) oListDef.iDefMaxY = GetXMLIntValue(oRef,u'maxy',True,1) oListDef.uOrientations = GetXMLTextValue(oRef,u'orientations',False,'landscape') uDefinitionDefaultOrientation = 'landscape' if oDef.iDefMaxX<oDef.iDefMaxY: uDefinitionDefaultOrientation='portrait' if not uDefinitionDefaultOrientation in oDef.uOrientations: ShowErrorPopUp(uMessage='Invalid Definition: Orientation does not match supportet orientations') #check if we need to swap x/y if Globals.uDeviceOrientation in oDef.uOrientations: for oListDef in Globals.oDefinitions: uDefinitionDefaultOrientation = 'landscape' if oListDef.iDefMaxX<oListDef.iDefMaxY: uDefinitionDefaultOrientation='portrait' if Globals.uDeviceOrientation != uDefinitionDefaultOrientation: Logger.debug("Rotating the definition to supported orientation: "+oListDef.uName) #oDef.iDefMaxX,oDef.iDefMaxY = oDef.iDefMaxY,oDef.iDefMaxX oListDef.iDefMaxX,oListDef.iDefMaxY = oListDef.iDefMaxY,oListDef.iDefMaxX self.AdjustRatiosAfterResize() else: Logger.debug("Orientation not supported, rotating screen") Globals.bWaitForRotation=True SetVar(uVarName = u'WAITFORROTATION', oVarValue = '1') if Globals.uDeviceOrientation=='landscape': Globals.oRotation.SetOrientation_Portrait() else: Globals.oRotation.SetOrientation_Landscape() self.iRotateCount +=1 Logger.debug("Rotation adjusted") if Globals.uStretchMode=="RESIZE": if kivy.core.window.Window.fullscreen!=True: fRatio=float(float(Globals.iAppWidth)/float(Globals.iAppHeight))/float(float(oDef.iDefMaxX)/float(oDef.iDefMaxY)) if fRatio<1: fRatio = float(oDef.iDefMaxX) / float(oDef.iDefMaxY) Globals.iAppHeight=int(float(Globals.iAppWidth)/fRatio) elif fRatio>1: fRatio = float(oDef.iDefMaxY) / float(oDef.iDefMaxX) Globals.iAppWidth=int(float(Globals.iAppHeight)/fRatio) kivy.core.window.Window.size=(Globals.iAppWidth,Globals.iAppHeight)
def InitPageFromXmlNode(self, oXMLNode): """ Get Page Definitions """ self.uPageName = GetXMLTextAttribute(oXMLNode, u'name', True, u'') oRef = oXMLNode.find(u'page_parameter') self.uDefaultInterface = GetXMLTextValue(oRef, u'interface', False, u'') self.uDefaultConfigName = GetXMLTextValue(oRef, u'configname', False, u'') self.bIsPopUp = GetXMLBoolValue(oRef, u'popup', False, False) self.bPreventPreInit = GetXMLBoolValue(oRef, u'preventpreinit', False, False) # ToDo: this is temporary to validate some strange default value changes self.uDefaultInterface = ReplaceVars(self.uDefaultInterface) self.uDefaultConfigName = ReplaceVars(self.uDefaultConfigName) #not used self.uOrientation = GetXMLTextValue(oRef, u'orientation', False, Globals.uDeviceOrientation) if not self.uDefaultInterface == u'': Globals.oInterFaces.dUsedInterfaces[ReplaceVars( self.uDefaultInterface)] = True
def ParseServices(self, **kwargs) -> Dict: """ Needs to done first, Reads all services for a specific Enigma box into the script :param kwargs: argument dic, need to have resultvar, interface, configname :return: Dict ret: 0 or 1 : 1=success """ try: uResultVar: str = kwargs['resultvar'] uInterfaceName: str = ReplaceVars(kwargs['interface']) uConfigName: str = ReplaceVars(kwargs['configname']) oInterFace: cBaseInterFace = Globals.oInterFaces.GetInterface( uInterfaceName) oSetting: cBaseInterFaceSettings = oInterFace.GetSettingObjectForConfigName( uConfigName=uConfigName) uContext: str = oSetting.uContext oXmlBouquet: Element self.ShowInfo(uMsg="Parsing Services into " + uContext) if self.dServices.get(uContext) is not None: return {"ret": 1} uXmlContent: str = GetVar(uResultVar) uXmlContent = EscapeUnicode(uXmlContent) iBouquetNum: int = 0 # Order Number of the Channel iBouquetChannelNum: int uBouquetName: str iChannelNum: int = 0 # Absolute Channel num, through all Bouquets uReference: str uChannelName: str oXmlServices: Element if uXmlContent: # oET_Root = fromstring(uXmlContent) # oXmlBouquets = oET_Root.find("e2bouquet") oXmlBouquets: Element = LoadXMLString(uXML=uXmlContent) dChannels: typeChannels = { } # Bouquet independent list of all channels aBouquets: typeBouquetsList = [ ] # List of all bouquets as dBouquetDetails for oXmlBouquet in oXmlBouquets: if oXmlBouquet.tag == 'e2bouquet': # we might get services as well dBouquetDetails: typeBouquetDetails = { } # Element to decribe a single bouquet (number , name, containing channels) dBouquetChannels: typeBouquetChannels = { } # Dict of all channels in a single bouquet, index is Bouquechannelnum iBouquetChannelNum = 0 uBouquetName = GetXMLTextValue(oXMLNode=oXmlBouquet, uTag="e2servicename", bMandatory=False, vDefault="NoName" + str(iBouquetNum)) iBouquetNum += 1 oXmlServices = cast(Element, oXmlBouquet.find("e2servicelist")) for oXmlServiceDetails in oXmlServices: dSingleChannel: typeSingleChannel = { } # details of a channel iChannelNum += 1 # absolute channel num within all bouquets iBouquetChannelNum += 1 # relative channel num in bouquet uReference = GetXMLTextValue( oXMLNode=oXmlServiceDetails, uTag="e2servicereference", bMandatory=True, vDefault="NoName") uChannelName = GetXMLTextValue( oXMLNode=oXmlServiceDetails, uTag="e2servicename", bMandatory=False, vDefault="NoName" + str(iChannelNum)) dSingleChannel["ChannelName"] = uChannelName dSingleChannel["Reference"] = uReference dSingleChannel["ChannelNum"] = iChannelNum dSingleChannel[ "BouquetChannelNum"] = iBouquetChannelNum dBouquetChannels[ iBouquetChannelNum] = dSingleChannel dChannels[iChannelNum] = dSingleChannel # SetVar(uVarName=uDstVarName+"_channelservice["+str(iChannelNum)+"]",uContext=uContext,oVarValue=str(iChannelNum)) dBouquetDetails["Channels"] = dBouquetChannels dBouquetDetails["Name"] = uBouquetName dBouquetDetails["BouquetNum"] = iBouquetNum aBouquets.append(dBouquetDetails) self.dServices[uContext] = {} self.dServices[uContext]["Bouquets"] = aBouquets self.dServices[uContext]["Channels"] = dChannels return {"ret": 1} else: self.ShowError(uMsg="No Services Data in Source Var:" + uResultVar) except Exception as e: self.ShowError(uMsg="Can''t parse services, invalid xml", uParConfigName=self.uConfigName, oException=e) return {"ret": 0}
def __GetUsedDefinitions_Sub(self, uDefinitionName, bImportActions, bImportLanguages, bImportPages, bImportSettings, uParentDefinitionName, uParentDefinitionAlias, aDefinitionVarsFromParent, uAlias): aAdditionalDefVars = {} if not uAlias in self.dDefinitionList_Dict: oDefinitionPathes = cDefinitionPathes(uDefinitionName) SetVar(uVarName="DEFINITIONPATH[%s]" % (uDefinitionName), oVarValue=oDefinitionPathes.oPathDefinition.string) SetVar( uVarName="DEFINITIONPATHSKINELEMENTS[%s]" % (uDefinitionName), oVarValue=oDefinitionPathes.oPathDefinitionSkinElements.string) Globals.dDefinitionPathes[uDefinitionName] = oDefinitionPathes SetDefinitionPathes(uDefinitionName) oFnDefinition = Globals.oDefinitionPathes.oFnDefinition Logger.debug(u'TheScreen: Load Definition XmlFile:' + oFnDefinition) oDefinition = cDefinition(uDefinitionName, self) oDefinition.uParentDefinitionName = uParentDefinitionName oDefinition.bImportActions = bImportActions oDefinition.bImportLanguages = bImportLanguages oDefinition.bImportPages = bImportPages oDefinition.bImportSettings = bImportSettings oDefinition.oDefinitionVarsFromParent = aDefinitionVarsFromParent #we read the definitionvars first with raw funtions sET_Data = CachedFile(Globals.oDefinitionPathes.oFnDefinition) oET_Root = fromstring(sET_Data) oRef = oET_Root.find('def_parameter') # And merge / Replace the existing Vars oDefinition.oDefinitionVars.clear() oDefinition.oDefinitionVars.update( ToOrderedDic( GetXMLTextValue(oRef, u'definitionvars', False, u'{}'))) if len(aDefinitionVarsFromParent) > 0: for uVarName in oDefinition.oDefinitionVars: if uVarName in oDefinition.oDefinitionVarsFromParent: oDefinition.oDefinitionVars[ uVarName] = oDefinition.oDefinitionVarsFromParent[ uVarName] else: Logger.warning( "Importing definition %s from %s: Definition varname not passed: '%s', using default %s" % (oDefinition.uName, uParentDefinitionName, uVarName, oDefinition.oDefinitionVars[uVarName])) for uVarName in aDefinitionVarsFromParent: if not uVarName in oDefinition.oDefinitionVars: oDefinition.oDefinitionVars[ uVarName] = oDefinition.oDefinitionVarsFromParent[ uVarName] aAdditionalDefVars[ uVarName] = oDefinition.oDefinitionVarsFromParent[ uVarName] for uKey in oDefinition.oDefinitionVars: uVar = oDefinition.oDefinitionVars[uKey] if "$cookie(" in uVar: uValue = GetCookieValue(uVar) oDefinition.oDefinitionVars[uKey] = uValue if uAlias == u'': # this works on all python versions for uKey in oDefinition.oDefinitionVars: uAlias = oDefinition.oDefinitionVars[uKey] break if uAlias == '': uAlias = uDefinitionName oDefinition.uDefPublicTitle = uDefinitionName #create a default alias def var uAliasDefVar = "definition_alias_" + uAlias if oDefinition.oDefinitionVars.get(uAliasDefVar) is None: SetDefVar(uVarName=uAliasDefVar, uVarValue=uAlias, dArray=oDefinition.oDefinitionVars) else: oDefinition.uDefPublicTitle = "%s [%s]" % (uAlias, uDefinitionName) oDefinition.uAlias = uAlias if not uAlias in self.dDefinitionList_Dict: # create defvars for import pages aTmpDefinitionVars = copy(oDefinition.oDefinitionVars) for uVar in aTmpDefinitionVars: if not uVar.endswith("_IMPORTPAGES"): if bImportPages: SetDefVar(uVarName=uVar + "_IMPORTPAGES", uVarValue="1", dArray=oDefinition.oDefinitionVars) else: SetDefVar(uVarName=uVar + "_IMPORTPAGES", uVarValue="0", dArray=oDefinition.oDefinitionVars) #and now again with adjusted definitionvars oET_Root = Orca_FromString(sET_Data, oDefinition, "root") oDefinition.oET_Root = oET_Root oDefinition.sET_Data = sET_Data self.AddDefinition(oDefinition) oXMLIncludes = oET_Root.find('definitionimports') if oXMLIncludes is not None: for oXMLInclude in oXMLIncludes.findall('definition'): uDefinitionNameImp = GetXMLTextValue( oXMLInclude, u'', True, '') bImportActionsImp = GetXMLBoolAttribute( oXMLInclude, u'importactions', False, False) bImportLanguagesImp = GetXMLBoolAttribute( oXMLInclude, u'importlanguages', False, False) bImportPagesImp = GetXMLBoolAttribute( oXMLInclude, u'importpages', False, False) bImportSettingsImp = GetXMLBoolAttribute( oXMLInclude, u'importsettings', False, False) uAliasImp = GetXMLTextAttribute( oXMLInclude, u'alias', False, '') aDefinitionVarsImp = cDefinitionVars() aDefinitionVarsImp.update( ToDic( GetXMLTextAttribute(oXMLInclude, u'definitionvars', False, {}))) # Pass Through of additional Definitionvars for uVarName in aAdditionalDefVars: if not uVarName in aDefinitionVarsImp: aDefinitionVarsImp[ uVarName] = aAdditionalDefVars[uVarName] self.__GetUsedDefinitions_Sub( uDefinitionNameImp, bImportActionsImp, bImportLanguagesImp, bImportPagesImp, bImportSettingsImp, oDefinition.uName, oDefinition.uAlias, aDefinitionVarsImp, uAliasImp) else: Logger.debug( u'GetUsedDefinitions: Skipping duplicate xml %s [%s]' % (uAlias, uDefinitionName)) else: Logger.debug( u'GetUsedDefinitions: Skipping duplicate xml %s [%s]' % (uAlias, uDefinitionName))
def ParseServices(self, **kwargs): """ Needs to done first, Reads all services for a specific Enigma box into the script :param kwargs: argument dic, need to have resultvar, interface, configname :return: 0 """ try: uResultVar = kwargs['resultvar'] # uDstVarName = args['retvar'] uInterfaceName = ReplaceVars(kwargs['interface']) uConfigName = ReplaceVars(kwargs['configname']) oInterFace = Globals.oInterFaces.dInterfaces.get(uInterfaceName) oSetting = oInterFace.GetSettingObjectForConfigName(uConfigName) uContext = oSetting.uContext self.ShowInfo("Parsing Services into " + uContext) if self.dServices.get(uContext) is not None: return 0 uXmlContent = GetVar(uResultVar) uXmlContent = EscapeUnicode(uXmlContent) iBouquetNum = 0 # Order Number of the Channel iChannelNum = 0 # Absolute Channel num, through all Bouquets if uXmlContent: # oET_Root = fromstring(uXmlContent) # oXmlBouquets = oET_Root.find("e2bouquet") oXmlBouquets = fromstring(uXmlContent) dChannels = {} # Bouquet independent list of all channels aBouquets = [] # List of all bouquets as dBouquetDetails for oXmlBouquet in oXmlBouquets: if oXmlBouquet.tag == 'e2bouquet': # we might get services as well dBouquetDetails = { } # Element to decribe a single bouquet (number , name, containing channels) dBouquetChannels = { } # Dict of all channels in a single bouquet, index is Bouquechannelnum iBouquetChannelNum = 0 uBouquetName = GetXMLTextValue( oXmlBouquet, "e2servicename", False, "NoName" + str(iBouquetNum)) iBouquetNum += 1 oXmlServices = oXmlBouquet.find("e2servicelist") for oXmlServiceDetails in oXmlServices: dSingleChannel = {} # details of a channel iChannelNum += 1 # absolute channel num within all bouquets iBouquetChannelNum += 1 # relative channel num in bouquet uReference = GetXMLTextValue( oXmlServiceDetails, "e2servicereference", True, "NoName") uChannelName = GetXMLTextValue( oXmlServiceDetails, "e2servicename", False, "NoName" + str(iChannelNum)) dSingleChannel["ChannelName"] = uChannelName dSingleChannel["Reference"] = uReference dSingleChannel["ChannelNum"] = iChannelNum dSingleChannel[ "BouquetChannelNum"] = iBouquetChannelNum dBouquetChannels[ iBouquetChannelNum] = dSingleChannel dChannels[iChannelNum] = dSingleChannel # print uContext,":",uChannelName,":",iChannelNum # SetVar(uVarName=uDstVarName+"_channelservice["+str(iChannelNum)+"]",uContext=uContext,oVarValue=str(iChannelNum)) dBouquetDetails["Channels"] = dBouquetChannels dBouquetDetails["Name"] = uBouquetName dBouquetDetails["BouquetNum"] = iBouquetNum aBouquets.append(dBouquetDetails) self.dServices[uContext] = {} self.dServices[uContext]["Bouquets"] = aBouquets self.dServices[uContext]["Channels"] = dChannels return 1 else: self.ShowError("No Services Data in Source Var:" + uResultVar) except Exception as e: self.ShowError("Can''t parse services, invalid xml", e) return 0
def LoadSkinDescription(self): """ Loads the a skin description """ #AddGlobalVars:we do it here again: Todo: check if it either can be split or out somewhere else Globals.oTheScreen.AddGlobalVars() try: oET_Root = LoadXMLFile(Globals.oFnSkinXml) if oET_Root is not None: Logger.debug(u'TheScreen: Loading Skin Description (pics)') oXMLPics = oET_Root.find('pics') if oXMLPics is not None: for oXMLPic in oXMLPics.findall('pic'): uPicName = GetXMLTextAttribute(oXMLPic, u'name', False, u'') self.dSkinPics[uPicName] = cFileName( '').ImportFullPath( GetXMLTextAttribute(oXMLPic, u'file', False, u'')) Logger.debug(u'TheScreen: Loading Skin Description (colors)') oXMLColors = oET_Root.find('colors') if oXMLColors is not None: for oXMLColor in oXMLColors.findall('color'): uColorName = GetXMLTextAttribute( oXMLColor, u'name', True, u'black') uColor = GetXMLTextValue(oXMLColor, '', True, u'#000000ff') SetVar(uVarName=uColorName, oVarValue=uColor) Logger.debug( u'TheScreen: Loading Skin Description (redirects)') oXMLRedirects = oET_Root.find('redirects') if oXMLRedirects is not None: for oXMLRedirect in oXMLRedirects.findall('redirect'): oFrom = cFileName('').ImportFullPath( GetXMLTextAttribute(oXMLRedirect, u'from', True, u'')) oTo = cFileName('').ImportFullPath( GetXMLTextAttribute(oXMLRedirect, u'to', True, u'')) self.dSkinRedirects[oFrom.string] = oTo Logger.debug( u'TheScreen: Loading Skin Description (attributes)') oXMLAtts = oET_Root.find('attributes') if oXMLAtts is not None: for oXMLAtt in oXMLAtts.findall('attribute'): uAttName = GetXMLTextAttribute(oXMLAtt, u'name', False, u'') uAtt = ReplaceVars( GetXMLTextAttribute(oXMLAtt, u'att', False, u'')) self.dSkinAttributes[uAttName] = uAtt SetVar(uVarName=uAttName, oVarValue=uAtt) if self.dSkinAttributes.get('fontcolor button'): SetVar(uVarName=u'SKIN_FONTCOLOR_BUTTON', oVarValue=self.dSkinAttributes['fontcolor button']) self.dSkinAttributes['fontcolor button'] = GetColorFromHex( self.dSkinAttributes['fontcolor button']) if self.dSkinAttributes.get('fontcolor text'): SetVar(uVarName=u'SKIN_FONTCOLOR_TEXT', oVarValue=self.dSkinAttributes['fontcolor text']) self.dSkinAttributes['fontcolor text'] = GetColorFromHex( self.dSkinAttributes['fontcolor text']) if self.dSkinAttributes.get('fontcolor file'): SetVar(uVarName=u'SKIN_FONTCOLOR_FILE', oVarValue=self.dSkinAttributes['fontcolor file']) self.dSkinAttributes['fontcolor file'] = GetColorFromHex( self.dSkinAttributes['fontcolor file']) oPathSkinAtlas = Globals.oPathSkin + 'atlas' oPathSkinAtlas.Create() Globals.oFnAtlasSkin = cFileName(oPathSkinAtlas) + "skin.atlas" CreateAtlas(Globals.oPathSkin + "pics", Globals.oFnAtlasSkin, u'Create Skin Atlas Files') Globals.oTheScreen.LoadAtlas() Globals.oTheScreen.oFonts.ParseFontFromXMLNode(oET_Root) Globals.oTheScreen.oFonts.ParseIconsFromXMLNode(oET_Root) except Exception as e: uMsg = LogError( u'TheScreen: __LoadSkinDescription: can\'t load SkinDescription', e) ShowErrorPopUp(uMessage=uMsg)
def SendCommand(self): self.bStopWait = False uUrlFull = "http://" + self.uIP + "/web/about" try: self.oReq = UrlRequest(uUrlFull, method="GET", timeout=self.fTimeOut, on_error=self.OnError, on_success=self.OnReceive) self.NewWait(0.05) if self.oReq.resp_status is not None: uResult = self.oReq.result if "<e2abouts>" in uResult: if PY2: oXmlRoot = fromstring( uResult.encode('ascii', 'xmlcharrefreplace')) else: oXmlRoot = fromstring(uResult) oXmlAbout = oXmlRoot.find("e2about") uModel = GetXMLTextValue(oXmlAbout, "e2model", False, "Enigma") uFoundHostName = "" try: uFoundHostName = socket.gethostbyaddr(self.uIP)[0] except Exception as e: # Logger.error("Cant get Hostname:"+oRet.sFoundIP+" "+str(e)) pass cThread_CheckIP.oWaitLock.acquire() self.oCaller.aResults.append({ "ip": self.uIP, "port": 80, "model": uModel, "ipversion": "IPv4", "hostname": uFoundHostName }) try: uIP = "" aIPs = socket.getaddrinfo(uFoundHostName, None) for tIP in aIPs: uIP = "[" + tIP[-1][0] + "]" if ":" in uIP: break if ":" in uIP: self.oCaller.aResults.append({ "ip": uIP, "port": 80, "model": uModel, "ipversion": "IPv6", "hostname": uFoundHostName }) except Exception as e: pass cThread_CheckIP.oWaitLock.release() except Exception as e: self.oCaller.ShowError("Error on send:", e) return
def ParseFromXMLNode(self, oXMLNode): """ Parses an xms string into object vars """ self.uSourceFile = GetXMLTextValue(oXMLNode, u'sourcefile', True, u'') self.uTargetPath = GetXMLTextValue(oXMLNode, u'targetpath', True, u'') self.uLocal = AdjustPathToOs( ReplaceVars(GetXMLTextValue(oXMLNode, u'local', False, u'')))
def ParseFromXMLNode(self, oXMLNode): """ Parses an xms string into object vars """ self.uType = GetXMLTextValue(oXMLNode, u'type', True, u'') self.uName = GetXMLTextValue(oXMLNode, u'name', True, u'')
def ParseMovieList(self, **kwargs) -> Dict: """ Parses all movies :param kwargs: argument dic, need to have resultvar, interface, configname :return: Dict ret: 0 or 1 : 1=success """ try: uResultVar: str = kwargs['resultvar'] uInterfaceName: str = ReplaceVars(kwargs['interface']) uConfigName: str = ReplaceVars(kwargs['configname']) uReturnVar: str = kwargs['retvar'] oInterFace: cBaseInterFace = Globals.oInterFaces.GetInterface( uInterfaceName) oSetting: cBaseInterFaceSettings = oInterFace.GetSettingObjectForConfigName( uConfigName=uConfigName) uContext: str = oSetting.uContext uXmlContent: str iMovieNum: int uMovieReference: str self.ShowInfo(uMsg="Parsing movies into " + uContext) # cache disabled # if self.dMovies.get(uContext) is not None: # return {"ret":1} uXmlContent = GetVar(uResultVar) uXmlContent = EscapeUnicode(uXmlContent) iMovieNum = 0 # Order Number of the Channel if uXmlContent: oXmlMovies: Element = LoadXMLString(uXML=uXmlContent) self.dMovies[uContext] = {} dMovies: typeMovies = {} Var_DelArray("%s_%s[]" % (uReturnVar, 'reference')) Var_DelArray("%s_%s[]" % (uReturnVar, 'title')) Var_DelArray("%s_%s[]" % (uReturnVar, 'description')) Var_DelArray("%s_%s[]" % (uReturnVar, 'descriptionex')) Var_DelArray("%s_%s[]" % (uReturnVar, 'servicename')) Var_DelArray("%s_%s[]" % (uReturnVar, 'url_reference')) Var_DelArray("%s_%s[]" % (uReturnVar, 'time')) Var_DelArray("%s_%s[]" % (uReturnVar, 'date')) Var_DelArray("%s_%s[]" % (uReturnVar, 'date_time')) Var_DelArray("%s_%s[]" % (uReturnVar, 'length')) Var_DelArray("%s_%s[]" % (uReturnVar, 'filename')) Var_DelArray("%s_%s[]" % (uReturnVar, 'url_filename')) Var_DelArray("%s_%s[]" % (uReturnVar, 'index')) for oXmlMovie in oXmlMovies: if oXmlMovie.tag == 'e2movie': # we might get services as well dMovieDetails: typeMoviedetails = { } # Element to describe a single movie (number , name, containing channels) iMovieNum += 1 # absolute channel num within all bouquets uMovieReference = GetXMLTextValue( oXMLNode=oXmlMovie, uTag="e2servicereference", bMandatory=True, vDefault="N/A") dMovieDetails["reference"] = uMovieReference # noinspection Mypy dMovieDetails["url_reference"] = urllib.parse.quote( uMovieReference) dMovieDetails["title"] = GetXMLTextValue( oXMLNode=oXmlMovie, uTag="e2title", bMandatory=False, vDefault="No Title") dMovieDetails["description"] = GetXMLTextValue( oXMLNode=oXmlMovie, uTag="e2description", bMandatory=False, vDefault="") dMovieDetails["descriptionex"] = GetXMLTextValue( oXMLNode=oXmlMovie, uTag="e2descriptionextended", bMandatory=False, vDefault="") dMovieDetails["servicename"] = GetXMLTextValue( oXMLNode=oXmlMovie, uTag="e2servicename", bMandatory=False, vDefault="") dMovieDetails["time"] = GetXMLTextValue( oXMLNode=oXmlMovie, uTag="e2time", bMandatory=False, vDefault="") dMovieDetails["length"] = GetXMLTextValue( oXMLNode=oXmlMovie, uTag="e2length", bMandatory=False, vDefault="0:00") dMovieDetails["filename"] = GetXMLTextValue( oXMLNode=oXmlMovie, uTag="e2filename", bMandatory=False, vDefault="") # noinspection Mypy dMovieDetails["url_filename"] = urllib.parse.quote( dMovieDetails["filename"]) dMovieDetails["index"] = ("000" + str(iMovieNum))[-3] iTime: int = ToInt(dMovieDetails["time"]) oTime: struct_time = datetime.fromtimestamp( iTime, timezone.utc).timetuple() sTime: str = Globals.oLanguage.GetLocalizedTime( bWithSeconds=False, oTime=oTime) sDate: str = Globals.oLanguage.GetLocalizedDate( bLongDate=False, bLongDay=False, bLongMonth=False, oTime=oTime) dMovieDetails["time"] = sTime dMovieDetails["date"] = sDate dMovieDetails["date_time"] = sDate + " " + sTime for uKey in dMovieDetails: uTag = "%s_%s[%s]" % (uReturnVar, uKey, iMovieNum) SetVar(uTag, dMovieDetails[uKey]) self.ShowDebug(uMsg="Got MovieDetail:" + uTag + ":" + dMovieDetails[uKey]) dMovies[uMovieReference] = dMovieDetails self.dMovies[uContext] = dMovies return {"ret": 1} else: self.ShowError(uMsg="No Movies Data in Source Var:" + uResultVar) except Exception as e: self.ShowError(uMsg="Can''t parse movies, invalid xml", uParConfigName=self.uConfigName, oException=e) return {"ret": 0}