def Save_As_iTach(self, oSet): uFilename = Globals.oPathCodesets.string + "/iTach/" + self.oCodesetName.text oFilename = cFileName().ImportFullPath( uFilename.replace("_XXXXX_", "_iTach_")) try: oRoot = Element("codeset") for oFunction in oSet: oCodesetCode = SubElement(oRoot, "action") oCodesetCode.set("string", "codeset") oCodesetCode.set("name", oFunction.Function) oCodesetCode.set("type", oFunction.uType) uString = oFunction.Code1.replace( "sendir,1:1,", "sendir,$cvar(CONFIG_MODULE):$cvar(CONFIG_CONNECTOR),") uString = uString.replace("\n", "") uString = uString.replace("\r", "") oCodesetCode.set("cmd", uString) uFinal = XMLPrettify(oRoot) uFinal = uFinal.replace('<?xml version="1.0"?>', '<?xml version="1.0" encoding="UTF-8"?>') oFile = open(oFilename.string, 'w') oFile.write(uFinal) oFile.close() #oTree = ElementTree(oRoot) #oTree.write(uFilename, encoding="UTF-8",xml_declaration='<?xml version="1.0" encoding="UTF-8"?>') except Exception as e: uMsg = LogError(u'IRDB: Error Writing iTach codeset file', e) ShowErrorPopUp(uMessage=uMsg)
def AddWidgetFromXmlNode(self, *, oXMLNode: Element, uAnchor: str) -> Union[bool, cWidgetBase]: # Parse a specific Widget from an xml definition oTmpWidget: cWidgetBase = cWidgetBase() #First get the widget type to know which widget to create oTmpWidget.GetWidgetTypeFromXmlNode(oXMLNode) #call the widget creation function if oTmpWidget.eWidgetType != eWidgetType.ERROR: try: return self.dFktsCreateWidget[oTmpWidget.eWidgetType][0]( oXMLNode=oXMLNode, uAnchor=uAnchor, oClass=self.dFktsCreateWidget[oTmpWidget.eWidgetType][1]) except Exception as e: LogError(uMsg="can't create widget:" + XMLPrettify(oElem=oXMLNode), oException=e) else: Ret: Union[Dict, None] = Globals.oNotifications.SendNotification( uNotification="UNKNOWNWIDGET", **{ "SCREENPAGE": self, "XMLNODE": oXMLNode, "ANCHOR": uAnchor, "WIDGET": oTmpWidget }) if Ret is None: Logger.error("Unknown Widget Type %s : Page: %s" % (oTmpWidget.uTypeString, self.uPageName)) return False return False
def ConvertItach2CCF(self) -> None: #todo : remove when we know, it is not used anymore oXMLCode: Element uFile: str uCmd: str uRepeat: str uFileName: str uFinal: str aFiles: List[str] = Globals.oPathCodesets.GetFolderList() aFiles2: List[str] = [] for uFile in aFiles: if uFile.startswith("CODESET_iTach_"): aFiles2.append(uFile) for uFile in aFiles2: oFile: cFileName = cFileName(Globals.oPathCodesets) + uFile oXMLCodeset: Element = LoadXMLFile(oFile=oFile) oXMLCodes: List[Element] = oXMLCodeset.findall('code') for oXMLCode in oXMLCodes: uCmd = GetXMLTextAttribute(oXMLNode=oXMLCode, uTag="cmd", bMandatory=False, vDefault="") if uCmd.startswith("sendir,"): uRepeat, uCmd = ITach2CCF(uCmd) oXMLCode.set("cmd_ccf", uCmd) oXMLCode.set("repeatcount", uRepeat) del oXMLCode.attrib["cmd"] uFileName = oFile.string.replace("_iTach_", "_infrared_ccf_") uFinal = ToUnicode(XMLPrettify(oElem=oXMLCodeset)) uFinal = uFinal.replace(u'<?xml version="1.0"?>', u'<?xml version="1.0" encoding="UTF-8"?>') with codecs.open(uFileName, 'w', 'utf-8') as oOutfile: oOutfile.write(uFinal)
def ConvertItach2CCF(self): #todo : remove when we know, it is not used anymore from ORCA.utils.XML import GetXMLTextAttribute import codecs aFiles = Globals.oPathCodesets.GetFolderList() aFiles2 = [] for uFile in aFiles: if uFile.startswith("CODESET_iTach_"): aFiles2.append(uFile) for uFile in aFiles2: oFile = cFileName(Globals.oPathCodesets) + uFile oXMLCodeset = ElementTree(file=oFile.string).getroot() oXMLCodes = oXMLCodeset.findall('code') for oXMLCode in oXMLCodes: uCmd = GetXMLTextAttribute(oXMLCode, "cmd", False, "") if uCmd.startswith("sendir,"): uRepeat, uCmd = ITach2CCF(uCmd) oXMLCode.set("cmd_ccf", uCmd) oXMLCode.set("repeatcount", uRepeat) del oXMLCode.attrib["cmd"] uFileName = oFile.string.replace("_iTach_", "_infrared_ccf_") uFinal = ToUnicode(XMLPrettify(oXMLCodeset)) uFinal = uFinal.replace(u'<?xml version="1.0"?>', u'<?xml version="1.0" encoding="UTF-8"?>') with codecs.open(uFileName, 'w', 'utf-8') as outfile: outfile.write(uFinal)
def _AddWidgetFromXmlNode(self, oXMLNode, uAnchor): # Parse a spefific Widget from an xml definition oTmpWidget = cWidgetBase() #First get the widget type to know which widget to create oTmpWidget.GetWidgetTypeFromXmlNode(oXMLNode) #call the widget creation function if oTmpWidget.iWidgetType != -1: try: return self.dFktsCreateWidget[oTmpWidget.iWidgetType][0]( oXMLNode=oXMLNode, uAnchor=uAnchor, oClass=self.dFktsCreateWidget[oTmpWidget.iWidgetType][1]) except Exception as e: LogError("can't create widget:" + XMLPrettify(oXMLNode), e) else: Ret = Globals.oNotifications.SendNotification( "UNKNOWNWIDGET", **{ "SCREENPAGE": self, "XMLNODE": oXMLNode, "ANCHOR": uAnchor, "WIDGET": oTmpWidget }) if Ret is None: Logger.error("Unknown Widget Type %s : Page: %s" % (oTmpWidget.uTypeString, self.uPageName)) return False return False
def Save_As_CCF(self, oSet): uFilename = Globals.oPathCodesets.string + "/infrared_ccf/" + self.oCodesetName.text oFn = cFileName().ImportFullPath( uFilename.replace("_XXXXX_", "_infrared_ccf_")) try: oRoot = Element("codeset") oRootToUse = oRoot for oFunction in oSet: if oFunction.Code1 == 'NEWCHILD': oCodesetCode = SubElement(oRootToUse, "action") oCodesetCode.set("name", oFunction.Function) oRootToUse = oCodesetCode elif oFunction.Code1 == 'LEAVECHILD': oRootToUse = oRoot else: oCodesetCode = SubElement(oRootToUse, "action") oCodesetCode.set("name", oFunction.Function) if oFunction.uType != "alias": if oFunction.string != u'': oCodesetCode.set("string", oFunction.string) if oFunction.uType != u'': oCodesetCode.set("type", oFunction.uType) if oFunction.uType == "cmd" and not "REPEAT" in oFunction.Code1: uRepeat, uString = ITach2CCF(oFunction.Code1) uString = uString.replace("\n", "") uString = uString.replace("\r", "") oCodesetCode.set("cmd_ccf", uString) oCodesetCode.set("repeatcount", uRepeat) else: if oFunction.Code1 != '': oCodesetCode.set("cmd", oFunction.Code1) uFinal = XMLPrettify(oRoot) uFinal = uFinal.replace('<?xml version="1.0"? >', '<?xml version="1.0" encoding="UTF-8"?>') uFinal = uFinal.replace( '{&REPEAT&:{&REPEATCMD&:&key_&,&REPEATVAR&:&$cvar(CHANNELNUM)&}}', '{"REPEAT":{"REPEATCMD":"key_","REPEATVAR":"$cvar(CHANNELNUM)"}}' ) oFile = open(oFn.string, 'w') oFile.write(uFinal) oFile.close() #oTree = ElementTree(oRoot) #oTree.write(uFilename, encoding="UTF-8",xml_declaration='<?xml version="1.0" encoding="UTF-8"?>') except Exception as e: uMsg = LogError(u'IRDB: Error Writing CCF codeset file', e) ShowErrorPopUp(uMessage=uMsg)
def SaveRepositoryXML(self,uType:str,uDescription:str) -> None: """ Saves the main repository directory xml """ oVal:Element uContent:str uRoot:str oPath:cPath= Globals.oPathTmp + "RepManager" oPath.Create() oPath=oPath+"repositories" oPath.Create() oPath=oPath+uType oPath.Create() oFnXml:cFileName=cFileName(oPath) +'repository.xml' oXMLRoot:Element = Element('repository') oVal = SubElement(oXMLRoot,'version') oVal.text = '1.00' oVal = SubElement(oXMLRoot,'type') oVal.text = uType oVal = SubElement(oXMLRoot,'description') oVal.text = uDescription oXMLEntries:Element = SubElement(oXMLRoot,'entries') for oEntry in self.aRepManagerEntries: Logger.debug ('Saving Repository-Entry [%s]' % oEntry.oFnEntry.string) oEntry.oRepEntry.WriteToXMLNode(oXMLNode=oXMLEntries) for oSource in oEntry.oRepEntry.aSources: bZipParentDir:bool = cPath.CheckIsDir(uCheckName=oSource.uLocal) # Create according Zip if bZipParentDir: uUpper:str = os.path.basename(oSource.uSourceFile) uFinalPath:str = uType oDest:cFileName = cFileName().ImportFullPath(uFnFullName='%s/RepManager/repositories/%s/%s' % (Globals.oPathTmp.string, uFinalPath, uUpper)) uUpper1:str = os.path.split(os.path.abspath(oSource.uLocal))[0] uRoot = AdjustPathToOs(uPath=ReplaceVars(uUpper1)+'/') self.aZipFiles.append({'filename':oSource.uLocal,'dstfilename':oDest.string, 'removepath':uRoot, 'skipfiles':ToUnicode(oEntry.oRepEntry.aSkipFileNames)}) else: uDest:str = AdjustPathToOs(uPath='%s/RepManager/repositories/%s/%s.zip' % (Globals.oPathTmp.string, uType, os.path.splitext(os.path.basename(oSource.uLocal))[0])) uRoot = AdjustPathToOs(uPath=Globals.oPathRoot.string + "/" + oSource.uTargetPath) self.aZipFiles.append({'filename':oSource.uLocal,'dstfilename':uDest, 'removepath':uRoot}) oFSFile = open(oFnXml.string, 'w') uContent = XMLPrettify(oElem=oXMLRoot) uContent = ReplaceVars(uContent) oFSFile.write(EscapeUnicode(uContent)) oFSFile.close()