Exemplo n.º 1
0
    def CheckDeviceDetails(self, oRet):
        if oRet.bFound:
            if self.oReq.uManufacturer != "":
                if self.oReq.uManufacturer != oRet.uFoundManufacturer:
                    oRet.bFound = False

            aModels = ToList(self.oReq.uModels)
            if len(aModels) > 0 and oRet.bFound:
                oRet.bFound = False
                for uModel in aModels:
                    if uModel.startswith("'") or uModel.startswith('"'):
                        uModel = uModel[1:-2]

                    if uModel.endswith("*"):
                        if uModel[:-1] == oRet.uFoundModel[:len(uModel) - 1]:
                            oRet.bFound = True
                            break
                    else:
                        if uModel.startswith("'") or uModel.startswith('"'):
                            uModel = uModel[1:-1]
                        if uModel == oRet.uFoundModel:
                            oRet.bFound = True
                            break

            if self.oReq.uFriendlyName != "" and oRet.bFound:
                oRet.bFound = False
                if self.oReq.uFriendlyName.endswith("*"):
                    if self.oReq.uFriendlyName[:
                                               -1] == oRet.uFoundFriendlyName[:len(
                                                   oRet.uFriendlyName) - 1]:
                        oRet.bFound = True
                else:
                    if self.oReq.uFriendlyName == oRet.uFoundFriendlyName:
                        oRet.bFound = True
Exemplo n.º 2
0
 def CheckDeviceDetails(self, dRet: TypedQueryDict) -> None:
     if dRet.bFound:
         aModels: List[str] = ToList(self.dReq.uModels)
         if len(aModels) > 0:
             dRet.bFound = False
             for uModel in aModels:
                 if uModel.startswith("'") or uModel.startswith('"'):
                     uModel = uModel[1:-2]
                 if MatchWildCard(uValue=dRet.uFoundModel,
                                  uMatchWithWildCard=uModel):
                     dRet.bFound = True
                     break
Exemplo n.º 3
0
    def _Parse_Dict(self, uResponse: Any, uGetVar: str,
                    uParseResultFlags: str) -> Tuple:
        """ parses the result as dict """
        uResult: str = u''
        aResult: List
        if not isinstance(uResponse, dict):
            uResponse = ToDic(uResponse)
        if isinstance(uResponse, dict):
            if "U" in uParseResultFlags:
                aResult = ParseDictAny(vObj=uResponse, uSearchKey=uGetVar)
            else:
                if "E" in uParseResultFlags:
                    dResult = ParseDictAll(vObj=uResponse, uPrefix="")
                    uLocalDestVar = self.uLocalDestVar
                    uGlobalDestVar = self.uGlobalDestVar
                    for uFoundKey, uValue in dResult.items():
                        if uLocalDestVar:
                            self.uLocalDestVar = uLocalDestVar + "%s" % uFoundKey
                        if uGlobalDestVar:
                            self.uGlobalDestVar = uGlobalDestVar + "%s" % uFoundKey
                        self._SetVar(uValue, u'Dictionary value')
                    self.uLocalDestVar = uLocalDestVar
                    self.uGlobalDestVar = uGlobalDestVar
                    aResult = []
                else:
                    aResult = ParseDictKeyTree(vObj=uResponse,
                                               aKeys=ToList(uGetVar))

            if aResult:
                if not "A" in uParseResultFlags:
                    uResult = ToUnicode(aResult[0])
                    self._SetVar(uResult, u'Dictionary value')
                else:
                    iIndex = 0
                    uLocalDestVar = self.uLocalDestVar
                    uGlobalDestVar = self.uGlobalDestVar
                    for uResult in aResult:
                        if uLocalDestVar:
                            self.uLocalDestVar = uLocalDestVar + "[%d]" % iIndex
                        if uGlobalDestVar:
                            self.uGlobalDestVar = uGlobalDestVar + "[%d]" % iIndex
                        self._SetVar(uResult, u'Dictionary value')
                        iIndex += 1
                    self.uLocalDestVar = uLocalDestVar
                    self.uGlobalDestVar = uGlobalDestVar
            else:
                self._SetVar(uResult, u'Dictionary value')
            return uGetVar, uResult
        else:
            self.ShowDebug(u'Warning: can'
                           't parse none dict as dict:' + ToUnicode(uResponse))
        return u'', u''
Exemplo n.º 4
0
    def Parse(self,
              *,
              uResponse: str,
              uGetVar: str,
              uParseResultOption: str,
              uGlobalDestVar: str,
              uLocalDestVar: str = u'',
              uTokenizeString: str = u'',
              uParseResultFlags: str = u'') -> Tuple[str, str]:
        """ The Main Parse Function """
        self.uGlobalDestVar = uGlobalDestVar
        self.uLocalDestVar = uLocalDestVar
        self.uGlobalTokenizeString = uTokenizeString

        if u'L' in uParseResultFlags:
            aTmpGetVar: List = ToList(uGetVar)
            aTmpLocalDestVar: List = ToList(uLocalDestVar)
            aTmpGlobalDestVar: List = ToList(uGlobalDestVar)
            uRet1: str = ''
            uRet2: str = ''
            for iIndex, uGetVar in enumerate(aTmpGetVar):
                if iIndex < len(aTmpLocalDestVar):
                    self.uLocalDestVar = aTmpLocalDestVar[iIndex]
                if iIndex < len(aTmpGlobalDestVar):
                    self.uGlobalDestVar = aTmpGlobalDestVar[iIndex]
                uRet1, uRet2 = self.ParseSingle(
                    uResponse=uResponse,
                    uGetVar=uGetVar,
                    uParseResultOption=uParseResultOption,
                    uTokenizeString=uTokenizeString,
                    uParseResultFlags=uParseResultFlags)
                self.uLocalDestVar = uLocalDestVar
                self.uGlobalTokenizeString = uTokenizeString
            return uRet1, uRet2
        return self.ParseSingle(uResponse=uResponse,
                                uGetVar=uGetVar,
                                uParseResultOption=uParseResultOption,
                                uTokenizeString=uTokenizeString,
                                uParseResultFlags=uParseResultFlags)
Exemplo n.º 5
0
    def _ELV_getroomdevices(self, oSetting: cInterFaceSettings,
                            oAction: cAction, dParams: Dict,
                            bAddRoom: bool) -> List:  #check
        """
        Internal Helper function to get a list of devices of a room

        :param cInterface.cInterFaceSettings oSetting: The setting object
        :param cAction oAction: The action object (unused)
        :param dict dParams: The parameter, needs to include room
        :param boolean bAddRoom: Flag to include the room name as first element
        :return: list: A list of dicts: key:name=room name , rf_address= Rf Address of Room
        """

        aRet: List = []
        i: int = 0
        uRoom: str = ReplaceVars(
            dParams["room"], self.uObjectName + u'/' + oSetting.uConfigName)

        aTmpDestVar: List = ToList(oAction.uGlobalDestVar)
        for uVarName in aTmpDestVar:
            Var_DelArray(uVarName=uVarName + u'[]')

        oRoom: MaxRoom
        dLine: TypedQueryDict

        for oRoom in oSetting.oDevice.rooms:
            if oRoom.name == uRoom:
                if bAddRoom:
                    dLine = TypedQueryDict()
                    dLine.uVarSuffix = "[" + str(i) + "]"
                    uRfAddress: str = str(oRoom.rf_address)
                    dLine.dValue = {
                        "name": oRoom.name,
                        "rf_address": uRfAddress
                    }
                    aRet.append(dLine)
                    i += 1

                for oDevice in oSetting.oDevice.devices_by_room(oRoom):
                    dLine = TypedQueryDict()
                    dLine.uVarSuffix = "[" + str(i) + "]"
                    uRfAddress = str(oDevice.rf_address)
                    dLine.dValue = {
                        "name": oDevice.name,
                        "rf_address": uRfAddress
                    }
                    aRet.append(dLine)
                    i += 1
                break
        return aRet
Exemplo n.º 6
0
    def Parse(self,uResponse,uGetVar,uParseResultOption,uGlobalDestVar,uLocalDestVar='',uTokenizeString=u''):
        """ The Main Parse Function """
        self.uGlobalDestVar         = uGlobalDestVar
        self.uLocalDestVar          = uLocalDestVar
        self.uGlobalTokenizeString  = uTokenizeString

        if uGetVar.startswith('ORCAMULTI'):
            uTmpGetVar        = ToList(uGetVar[9:])
            uTmpLocalDestVar  = ToList(uLocalDestVar)
            uTmpGlobalDestVar = ToList(uGlobalDestVar)
            uRet1=''
            uRet2=''
            for iIndex, uGetVar in enumerate(uTmpGetVar):
            #for iIndex in range(len(uTmpGetVar)):
            #    uGetVar = uTmpGetVar[iIndex]
                if iIndex < len(uTmpLocalDestVar):
                    self.uLocalDestVar = uTmpLocalDestVar[iIndex]
                if iIndex < len(uTmpGlobalDestVar):
                    self.uGlobalDestVar = uTmpGlobalDestVar[iIndex]
                uRet1,uRet2 = self.ParseSingle(uResponse,uGetVar,uParseResultOption,uTokenizeString)
                self.uLocalDestVar          = uLocalDestVar
                self.uGlobalTokenizeString  = uTokenizeString
            return uRet1,uRet2
        return self.ParseSingle(uResponse,uGetVar,uParseResultOption,uTokenizeString)
Exemplo n.º 7
0
 def CheckDeviceDetails(self, oRet):
     if oRet.bFound:
         aModels = ToList(self.oReq.uModels)
         if len(aModels) > 0:
             oRet.bFound = False
             for uModel in aModels:
                 if uModel.endswith("*"):
                     if uModel[:-1] == oRet.uFoundModel[:len(uModel) - 1]:
                         oRet.bFound = True
                         break
                 else:
                     if uModel.startswith("'") or uModel.startswith('"'):
                         uModel = uModel[1:-1]
                     if uModel == oRet.uFoundModel:
                         oRet.bFound = True
                         break
Exemplo n.º 8
0
    def CheckDeviceDetails(self, dRet: TypedQueryDict) -> None:
        if dRet.bFound:
            if self.dReq.uManufacturer != "":
                if not MatchWildCard(
                        uValue=dRet.uFoundManufacturer,
                        uMatchWithWildCard=self.dReq.uManufacturer):
                    dRet.bFound = False

            aModels = ToList(self.dReq.uModels)
            if len(aModels) > 0 and dRet.bFound:
                dRet.bFound = False
                for uModel in aModels:
                    if uModel.startswith("'") or uModel.startswith('"'):
                        uModel = uModel[1:-2]
                    if MatchWildCard(uValue=dRet.uFoundModel,
                                     uMatchWithWildCard=uModel):
                        dRet.bFound = True
                        break

            if self.dReq.uFriendlyName != "" and dRet.bFound:
                dRet.bFound = False
                if MatchWildCard(uValue=dRet.uFoundFriendlyName,
                                 uMatchWithWildCard=self.dReq.uFriendlyName):
                    dRet.bFound = True
Exemplo n.º 9
0
    def SendCommand(self,
                    oAction: cAction,
                    oSetting: cInterFaceSettings,
                    uRetVar: str,
                    bNoLogOut: bool = False) -> eReturnCode:
        super().SendCommand(oAction=oAction,
                            oSetting=oSetting,
                            uRetVar=uRetVar,
                            bNoLogOut=bNoLogOut)

        iTryCount: int = 0
        eRet: eReturnCode = eReturnCode.Error

        uRetVar = ReplaceVars(uRetVar)
        oSetting.uRetVar = uRetVar

        if uRetVar != "":
            oAction.uGlobalDestVar = uRetVar

        dCmd: Dict = ToDic(oAction.uCmd)
        uCmd: str = dCmd["method"]
        dParams: Dict = dCmd["params"]

        while iTryCount < self.iMaxTryCount:
            iTryCount += 1
            oSetting.Connect()
            if oSetting.bIsConnected:
                try:
                    self.ShowDebug(uMsg="Sending elv max command: %s" % uCmd)
                    oFunc: Callable = self.dInterfaceFunctions.get(uCmd)
                    aResult: List = []
                    if oFunc is not None:
                        aResult = oFunc(oSetting=oSetting,
                                        oAction=oAction,
                                        dParams=dParams)
                    else:
                        self.ShowError(uMsg="Function not implemented: %s" %
                                       uCmd)

                    for dLine in aResult:
                        uGlobalDestVarSave: str = oAction.uGlobalDestVar
                        uLocalDestVarSave: str = oAction.uLocalDestVar

                        if u'L' in oAction.uParseResultFlags:
                            aTmpGlobalDestVar: List = ToList(
                                oAction.uGlobalDestVar)
                            aTmpLocalDestVar: List = ToList(
                                oAction.uLocalDestVar)
                            oAction.uGlobalDestVar = "".join(
                                '"' + e + dLine.uVarSuffix + '",'
                                for e in aTmpGlobalDestVar)[:-1]
                            oAction.uLocalDestVar = "".join(
                                '"' + e + dLine.uVarSuffix + '",'
                                for e in aTmpLocalDestVar)[:-1]
                        else:
                            oAction.uGlobalDestVar = oAction.uGlobalDestVar + dLine.uVarSuffix
                            oAction.uLocalDestVar = oAction.uLocalDestVar + dLine.uVarSuffix

                        uCmd, uRetVal = self.ParseResult(
                            oAction, dLine.dValue, oSetting)
                        oAction.uGlobalDestVar = uGlobalDestVarSave
                        oAction.uLocalDestVar = uLocalDestVarSave

                    eRet = eReturnCode.Success
                    break
                except Exception as e:
                    self.ShowError(uMsg=u'can\'t Send Message',
                                   uParConfigName=oSetting.uConfigName,
                                   oException=e)
                    eRet = eReturnCode.Error
            else:
                oSetting.bIsConnected = False

        self.CloseSettingConnection(oSetting=oSetting, bNoLogOut=bNoLogOut)
        return eRet
Exemplo n.º 10
0
    def ExecuteActionModifyFile(self, oAction: cAction) -> eReturnCode:
        """
        WikiDoc:Doc
        WikiDoc:Context:ActionsDetails
        WikiDoc:Page:Actions-ModifyFile
        WikiDoc:TOCTitle:modifyfile
        = modifyfile =
        Provides some common file operations like copy, rename, delete. All Operations can only be performed on files within the definition folder, so all pathes must be relative to the definition root folder. For copyfolder the abspath argument gives you access as a source for folder outside the definition folder
        This action will modify the error code (0=success, 1=failure), existfile will not modify the error code

        <div style="overflow:auto; ">
        {| class="wikitable"
        ! align="left" | Attribute
        ! align="left" | Description
        |-
        |string
        |modifyfile
        |-
        |filename
        |Relative path to file name
        |-
        |path
        |Relative path
        |-
        |abspath
        |Absolute path to source folder (copyfolder only)
        |-
        |dstfilename
        |For copy,rename and zip... the destination file name
        |-
        |dstpath
        |For copy,rename... the destination path name
        |-
        |dstvarname
        |for exist the destination var for the result
        |-
        |removepath
        |for zip: the path to remove from the zip directory
        |-
        |skipfiles
        |for zipfolder: filenames to exclude from the zip file (list)
        |-
        |Operator
        |Operator for the command. Use one of the following keywords
        * "copyfile"
        * "copyfolder"
        * "renamefile"
        * "renamefolder"
        * "deletefile"
        * "createfolder"
        * "deletefolder"
        * "existfile"
        * "existfolder"
        * "zipfile"
        * "zipfolder"

        |}</div>

        exist returns "TRUE" or "FALSE"

        A short example:
        <div style="overflow-x: auto;"><syntaxhighlight  lang="xml">
        <action name="" string="modifyfile" filename="definition.ini" operator="copy" dstfilename="definition.old"/>
        </syntaxhighlight></div>
        WikiDoc:End
        """

        oDestFileName: cFileName
        oPath: cPath

        uFileName: str = oAction.dActionPars.get("filename", "")
        uDestFileName: str = oAction.dActionPars.get("dstfilename", "")
        uPath: str = oAction.dActionPars.get("path", "")
        uDestPath: str = oAction.dActionPars.get("dstpath", "")

        uDestVarName: str = oAction.dActionPars.get("dstvarname", "")
        uOperator: str = ReplaceVars(oAction.dActionPars.get("operator", ""))
        uAbsPath: str = ReplaceVars(oAction.dActionPars.get("abspath", ""))
        uRemovePath: str = ReplaceVars(
            oAction.dActionPars.get("removepath", ""))
        aSkipFiles: List[str] = ToList(
            ReplaceVars(oAction.dActionPars.get("skipfiles", '[]')))
        aSkipFiles.append("*.ini")
        aSkipFiles.append("*.pyc")

        self.oEventDispatcher.LogAction(uTxt=u'ModifyFile', oAction=oAction)

        if uFileName.startswith('$var(DEFINITIONPATH'):
            oFileName = cFileName().ImportFullPath(uFnFullName=uFileName)
        else:
            oFileName = cFileName(
                Globals.oDefinitionPathes.oPathDefinition) + uFileName

        if uPath.startswith('$var(DEFINITIONPATH'):
            oPath = cPath(uPath)
        else:
            oPath = cPath(Globals.oDefinitionPathes.oPathDefinition) + uPath

        oAbsPath: cPath = cPath(uAbsPath)

        if uDestFileName.startswith('$var(DEFINITIONPATH'):
            oDestFileName = cFileName().ImportFullPath(
                uFnFullName=uDestFileName)
        else:
            oDestFileName = cFileName(
                Globals.oDefinitionPathes.oPathDefinition) + uDestFileName

        if uDestPath.startswith('$var(DEFINITIONPATH'):
            oDestPath = cPath(uDestPath)
        else:
            oDestPath = cPath(
                Globals.oDefinitionPathes.oPathDefinition) + uDestPath

        if ".." in oFileName.string:
            Logger.warning(
                u'Action: ModifyFile: File must be inside definition folder:' +
                oFileName.string)
            return eReturnCode.Error

        if ".." in oDestFileName.string:
            Logger.warning(
                u'Action: ModifyFile: Destination File must be inside definition folder:'
                + oDestFileName.string)
            return eReturnCode.Error

        if ".." in oPath.string:
            Logger.warning(
                u'Action: ModifyFile: Path must be inside definition folder:' +
                oPath.string)
            return eReturnCode.Error

        if ".." in oDestPath.string:
            Logger.warning(
                u'Action: ModifyFile: Destination Path must be inside definition folder:'
                + oDestPath.string)
            return eReturnCode.Error

        if uOperator == u'copyfile':
            if oFileName.Copy(oNewFile=oDestFileName):
                return eReturnCode.Success
            else:
                return eReturnCode.Error
        elif uOperator == u'renamefile':
            if oFileName.Rename(oNewFileName=oDestFileName):
                return eReturnCode.Success
            else:
                return eReturnCode.Error
        elif uOperator == u'deletefile':
            if oFileName.Delete():
                return eReturnCode.Success
            else:
                return eReturnCode.Error
        elif uOperator == u'existfile':
            if oFileName.Exists():
                SetVar(uVarName=uDestVarName, oVarValue="TRUE")
            else:
                SetVar(uVarName=uDestVarName, oVarValue="FALSE")
            return eReturnCode.Nothing
        elif uOperator == u'copyfolder':
            if oAbsPath.IsEmpty():
                if oPath.Copy(oDest=oDestPath):
                    return eReturnCode.Success
                else:
                    return eReturnCode.Error
            else:
                if oAbsPath.Copy(oDest=oDestPath):
                    return eReturnCode.Success
                else:
                    return eReturnCode.Error
        elif uOperator == u'renamefolder':
            if oPath.Rename(oNewPath=oDestPath):
                return eReturnCode.Success
            else:
                return eReturnCode.Error
        elif uOperator == u'deletefolder':
            if oPath.Delete():
                return eReturnCode.Success
            else:
                return eReturnCode.Error
        elif uOperator == u'createfolder':
            if oPath.Create():
                return eReturnCode.Success
            else:
                return eReturnCode.Error
        elif uOperator == u'existfolder':
            if oPath.Exists():
                SetVar(uVarName=uDestVarName, oVarValue="TRUE")
            else:
                SetVar(uVarName=uDestVarName, oVarValue="FALSE")
            return eReturnCode.Success
        elif uOperator == u'zipfolder':
            oZipFolder: cZipPath = cZipPath(
                ReplaceVars(oAction.dActionPars.get("path", "")))
            oDestFileName = cFileName('').ImportFullPath(
                uFnFullName=ReplaceVars(
                    oAction.dActionPars.get("dstfilename", "")))
            if oZipFolder.ZipFolder(oFnZipDest=oDestFileName,
                                    uRemovePath=uRemovePath,
                                    aSkipFiles=aSkipFiles):
                return eReturnCode.Success
            else:
                return eReturnCode.Error
        elif uOperator == u'zipfile':
            oZipFile: cZipFile = cast(
                cZipFile,
                cZipFile().ImportFullPath(uFnFullName=ReplaceVars(
                    oAction.dActionPars.get("filename", ""))))
            oDestFileName = cFileName('').ImportFullPath(
                uFnFullName=ReplaceVars(
                    oAction.dActionPars.get("dstfilename", "")))
            if oZipFile.ZipFile(oZipDest=oDestFileName,
                                uRemovePath=uRemovePath):
                return eReturnCode.Success
            else:
                return eReturnCode.Error
        else:
            LogError(uMsg=u'Action: ModifyFile: Wrong modifier:' + uOperator)
            return eReturnCode.Error
Exemplo n.º 11
0
    def SendCommand(self, oAction, oSetting, uRetVar, bNoLogOut=False):
        cBaseInterFace.SendCommand(self, oAction, oSetting, uRetVar, bNoLogOut)

        iTryCount = 0
        iRet = 1

        uRetVar = ReplaceVars(uRetVar)
        oSetting.uRetVar = uRetVar

        if uRetVar != "":
            oAction.uGlobalDestVar = uRetVar

        dCmd = ToDic(oAction.uCmd)
        uCmd = dCmd["method"]
        dParams = dCmd["params"]

        while iTryCount < 2:
            iTryCount += 1
            oSetting.Connect()
            if oSetting.bIsConnected:
                try:
                    self.ShowDebug("Sending elv max command: %s" % uCmd)
                    oFunc = self.dInterfaceFunctions.get(uCmd)
                    aResult = []
                    if oFunc is not None:
                        aResult = oFunc(oSetting=oSetting,
                                        oAction=oAction,
                                        dParams=dParams)
                    else:
                        self.ShowError("Function not implemented: %s" % uCmd)

                    for dLine in aResult:

                        uGlobalDestVarSave = oAction.uGlobalDestVar
                        uLocalDestVarSave = oAction.uLocalDestVar

                        if oAction.uGetVar.startswith('ORCAMULTI'):
                            aTmpGlobalDestVar = ToList(oAction.uGlobalDestVar)
                            aTmpLocalDestVar = ToList(oAction.uLocalDestVar)
                            oAction.uGlobalDestVar = "".join(
                                '"' + e + dLine.uVarSuffix + '",'
                                for e in aTmpGlobalDestVar)[:-1]
                            oAction.uLocalDestVar = "".join(
                                '"' + e + dLine.uVarSuffix + '",'
                                for e in aTmpLocalDestVar)[:-1]
                        else:
                            oAction.uGlobalDestVar = oAction.uGlobalDestVar + dLine.uVarSuffix
                            oAction.uLocalDestVar = oAction.uLocalDestVar + dLine.uVarSuffix

                        uCmd, uRetVal = self.ParseResult(
                            oAction, dLine.dValue, oSetting)
                        oAction.uGlobalDestVar = uGlobalDestVarSave
                        oAction.uLocalDestVar = uLocalDestVarSave

                    break
                except Exception as e:
                    self.ShowError(u'can\'t Send Message',
                                   oSetting.uConfigName, e)
                    iRet = 1
            else:
                oSetting.bIsConnected = False

        self.iLastRet = iRet

        if not bNoLogOut:
            if oSetting.aInterFaceIniSettings.iTimeToClose == 0:
                oSetting.Disconnect()
            elif oSetting.aInterFaceIniSettings.iTimeToClose != -1:
                Clock.unschedule(oSetting.FktDisconnect)
                Clock.schedule_once(
                    oSetting.FktDisconnect,
                    oSetting.aInterFaceIniSettings.iTimeToClose)
        return iRet