Ejemplo n.º 1
0
        def Receive(self) -> None:
            #Main Listening Thread to receice eiscp messages

            uResponses: str
            uResponse: str
            aResponses: List
            aActionTrigger: List[cBaseTrigger]

            #Loop until closed by external flag
            try:
                while not self.bStopThreadEvent:
                    if self.oSocket is not None:
                        ready: Tuple = select.select([self.oSocket], [], [],
                                                     1.0)
                        # the first element of the returned list is a list of readable sockets
                        if ready[0]:
                            byResponses = self.oSocket.recv(self.iBufferSize)
                            # there could be more than one response, so we need to split them
                            uResponses = ToUnicode(byResponses)
                            aResponses = uResponses.split("[EOL]")
                            for uResponse in aResponses:
                                # Todo: find proper encoding
                                if not uResponse == u'' and not uResponse == u'ORCA.ORCA Connecting...':
                                    if True:
                                        # If the returned Command is a response to the send message
                                        if uResponse.startswith(
                                                u'RemoteGhost.'):
                                            self.ShowDebug(
                                                uMsg=u'Returned Message:' +
                                                uResponse)
                                            #todo: parse the command from return
                                            # We do not need to wait for an response anymore
                                            StartWait(0)
                                            # we got our response, all other responses are for somebody else
                                            self.uMsg = u''
                                        else:
                                            # we have a notification issued by the device, so lets have a look, if we have a trigger assigned to it
                                            aActionTrigger = self.GetTrigger(
                                                uResponse)
                                            if len(aActionTrigger) > 0:
                                                for oActionTrigger in aActionTrigger:
                                                    self.CallTrigger(
                                                        oActionTrigger,
                                                        uResponse)
                                            else:
                                                self.ShowDebug(
                                                    uMsg=u'Discard message:' +
                                                    uResponse)

            except Exception as e:
                self.ShowError(uMsg=u'Error Receiving Response:', oException=e)
                self.bIsConnected = False
            try:
                if not self.oSocket is None:
                    self.ShowDebug(uMsg=u'Closing socket in Thread')
                    self.oSocket.close()
            except Exception as e:
                self.ShowError(uMsg=u'Error closing socket in Thread',
                               oException=e)
Ejemplo n.º 2
0
    def ParseFile(self, oFileName, iStartLine=0):
        """ parses a single file """

        i = 0

        if oFileName.string.endswith("__init__.py"):
            return self.oPages

        if iStartLine == 0:
            Logger.debug("Reading File:" + oFileName.string)
        try:
            if oFileName.Exists():
                uContent = ToUnicode(LoadFile(oFileName))
                aContent = uContent.split("\n")
                bFound = False
                for i, uLine in enumerate(aContent):
                    if i > iStartLine:
                        uLine = uLine.strip()
                        if uLine.startswith(u'WikiDoc:Doc'):
                            bFound = True
                        elif uLine.startswith(u'WikiDoc:End'):
                            bFound = False
                            self.oPages.append(self)
                            break
                        elif uLine.startswith("WikiDoc:Context:"):
                            uParts = uLine.split(":")
                            self.uContext = uParts[-1]
                        elif uLine.startswith("WikiDoc:Page:"):
                            uParts = uLine.split(":")
                            self.uPage = uParts[-1]
                            Logger.debug("Parsed Wikipage:" + self.uPage)
                        elif uLine.startswith("WikiDoc:TOCTitle:"):
                            uParts = uLine.split(":")
                            self.uTOCTitle = uParts[-1]
                        elif "'''" in uLine:
                            pass
                        elif '"""' in uLine:
                            pass
                        else:
                            if bFound:
                                self.uContent.append(uLine)
            else:
                LogError(u'cWikiDoc:Cant find file:' + oFileName.string)

            if len(self.oPages) > 0:
                oPage = cWikiPage()
                oPages = oPage.ParseFile(oFileName, i)
                if len(oPages) > 0:
                    self.oPages.extend(oPages)
            else:
                if iStartLine == 0:
                    Logger.warning("No Wikidoc entry in file:" +
                                   oFileName.string)
            return self.oPages
        except Exception as e:
            LogError(u'WikiDoc:Unexpected error reading file:', e)
            return []
Ejemplo n.º 3
0
 def ParseFile(self,uFileName,iStartLine=0):
     ''' parses a single file '''
     Logger.debug("Reading File:"+uFileName)
     try:
         if FileExists(uFileName):
             f = open(uFileName, 'r')
             uContent=ToUnicode(f.read())
             f.close()
             aContent=uContent.split("\n")
             bFound = False
             for  i,uLine in enumerate(aContent):
                 if i>iStartLine:
                     uLine=uLine.strip()
                     if uLine.startswith(u'WikiDoc:Doc'):
                         bFound = True
                     elif uLine.startswith(u'WikiDoc:End'):
                         bFound = False
                         self.oPages.append(self)
                         break
                     elif uLine.startswith("WikiDoc:Context:"):
                         uParts=uLine.split(":")
                         self.uContext=uParts[-1]
                     elif uLine.startswith("WikiDoc:Page:"):
                         uParts=uLine.split(":")
                         self.uPage=uParts[-1]
                     elif uLine.startswith("WikiDoc:TOCTitle:"):
                         uParts=uLine.split(":")
                         self.uTOCTitle=uParts[-1]
                     elif "'''" in uLine:
                         if bFound:
                             bFound = False
                             self.oPages.append(self)
                             break
                     else:
                         if bFound:
                             self.uContent.append(uLine)
         else:
             LogError(u'cWikiDoc:Cant find file:'+uFileName)
         if len(self.oPages)>0:
             oPage=cWikiPage()
             oPages=oPage.ParseFile(uFileName,i)
             if len(oPages)>0:
                 self.oPages.extend(oPages)
         return self.oPages
     except Exception as e:
         LogError(u'WikiDoc:Unexpected error reading file:',e)
         return []
Ejemplo n.º 4
0
        def Receive(self):
            #Main Listening Thread to receice eiscp messages

            #Loop until closed by external flag
            try:
                while self.bStopThreadEvent==False:
                    if not self.oSocket==None:
                        ready = select.select([self.oSocket], [], [],1.0)
                        # the first element of the returned list is a list of readable sockets
                        if ready[0]:
                            sResponses = self.oSocket.recv(self.iBufferSize)
                            # there could be more than one response, so we need to split them
                            uResponses = ToUnicode(sResponses)
                            aResponses=uResponses.split("[EOL]")
                            for uResponse in aResponses:
                                # Todo: find proper encoding
                                if not uResponse==u'' and not uResponse==u'ORCA.ORCA Connecting...':
                                    if "RemoteGhost.Pong" in uResponse:
                                        self.bPingAnswer=True
                                    else:
                                         # If the returned Command is a response to the send message
                                        if uResponse.startswith(u'RemoteGhost.'):
                                            self.ShowDebug(u'Returned Message:'+uResponse)
                                            #todo: parse the command from return
                                            # We do not need to wait for an response anymore
                                            oORCA.StartWait(0)
                                            # we got our response, all other responses are for somebody else
                                            self.uMsg=u''
                                        else:
                                            # we have a notification issued by the device, so lets have a look, if we have a trigger assigned to it
                                            oActionTrigger=self.GetTrigger(uResponse)
                                            if not oActionTrigger==None:
                                                self.CallTrigger(oActionTrigger,uResponse)
                                            else:
                                                self.ShowDebug(u'Discard message:'+uResponse)
                
            except Exception as e:
                self.ShowError(u'Error Receiving Response:',e)
                self.bIsConnected=False
            try:
                if not self.oSocket is None:
                    self.ShowDebug(u'Closing socket in Thread')
                    self.oSocket.close()
            except Exception as e:
                self.ShowError(u'Error closing socket in Thread',e)
Ejemplo n.º 5
0
def GetLocalIPV4():

    GetLocalIPV6()

    uMyIP = u''
    uMyGateway = u''
    uMySubNet = u''

    # Fast but not safe
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    try:
        # Not necessary successfull
        s.connect(('10.255.255.255', 0))
        IP = s.getsockname()[0]
    except:
        IP = GetLocalIPV4_FallBack()
    finally:
        s.close()
    uMyIP = ToUnicode(IP)
    tTmp = uMyIP.split('.')
    uMyGateway = tTmp[0] + '.' + tTmp[1] + '.' + tTmp[2] + '.1'
    uMySubNet = tTmp[0] + '.' + tTmp[1] + '.' + '0' + '.255'
    return uMyIP, uMyGateway, uMySubNet
Ejemplo n.º 6
0
        def Receive(self):
            #Main Listening Thread to receive json messages

            #Loop until closed by external flag
            try:
                while self.bStopThreadEvent==False:
                    if not self.oSocket==None:
                        ready = select.select([self.oSocket], [], [],1.0)
                        # the first element of the returned list is a list of readable sockets
                        if ready[0]:
                            self.bHandled=False
                            sResponses = self.oSocket.recv(self.iBufferSize)
                            uResponses = ToUnicode(sResponses)
                            # there could be more than one response, so we need to split them
                            # unfortunately, there is no end char in a json respone
                            aResponses=uResponses.split('}{')
                            if not len(aResponses)==1:
                                i=0
                                while i<len(aResponses):
                                    if i==0:
                                        aResponses[i]+='}'
                                    else:
                                        aResponses[i]=u'{'+aResponses[i]
                                    i+=1
                            uID=0
                            for uResponse in aResponses:
                                if not uResponse==u'':
                                    if '"result":"pong"' in uResponse:
                                        self.bPingAnswer=True
                                    else:
                                        
                                        # Get the Command and the payload
                                        # If the returned Command is a response to the send message
                                        uCommand,uID=self.oInterFace.ParseResult_JsonHeader(uResponse)
                                        if uID==self.uID:
                                        
                                            uCmd,uRetVal=self.oInterFace.ParseResult(self.oCodesetCode,uResponse,self)

                                            self.ShowDebug(u'Parsed Respones:'+uRetVal)
                                        
                                            if not self.uRetVar==u'' and not uRetVal==u'':
                                                SetVar(self.uRetVar,uRetVal)
                                            # We do not need to wait for an response anymore
                                            oORCA.StartWait(0)
                                            self.bHandled=True


                                        if self.bHandled==False:
                                            # we have a notification issued by the device, so lets have a look, if we have a trigger assigned to it
                                            oActionTrigger=self.GetTrigger(uCommand)
                                            if not oActionTrigger==None:
                                                self.CallTrigger(oActionTrigger,uResponse)
                                            else:
                                                self.ShowDebug(u'Discard message:'+uCommand +':'+uResponse)
                            #print "LEAVE PARSE"
                            fSleep(0.01)
                
            except Exception as e:
                if self.bIsConnected:
                    self.ShowError(u'Error Receiving Response:',e)
                self.bIsConnected=False
            try:
                if not self.oSocket==None:
                    self.ShowDebug(u'Closing socket in Thread')
                    self.oSocket.close()
            except Exception as e:
                self.ShowError(u'Error closing socket in Thread',e)
Ejemplo n.º 7
0
        def Receive(self):
            #Main Listening Thread to receive json messages

            #Loop until closed by external flag
            try:
                while not self.bStopThreadEvent:
                    if self.oSocket is not None:
                        ready = select.select([self.oSocket], [], [], 1.0)
                        # the first element of the returned list is a list of readable sockets
                        if ready[0]:
                            self.bHandled = False
                            sResponses = self.oSocket.recv(self.iBufferSize)
                            uResponses = ToUnicode(sResponses)
                            # there could be more than one response, so we need to split them
                            # unfortunately, there is no end char in a json respone
                            aResponses = uResponses.split('}{')
                            if not len(aResponses) == 1:
                                i = 0
                                while i < len(aResponses):
                                    if i == 0:
                                        aResponses[i] += '}'
                                    else:
                                        aResponses[i] = u'{' + aResponses[i]
                                    i += 1
                            uID = 0
                            for uResponse in aResponses:
                                if not uResponse == u'':
                                    if '"result":"pong"' in uResponse:
                                        pass
                                    else:

                                        # Get the Command and the payload
                                        # If the returned Command is a response to the send message
                                        uCommand, uID = self.oInterFace.ParseResult_JsonHeader(
                                            uResponse)
                                        if uID == self.uID:

                                            uCmd, uRetVal = self.oInterFace.ParseResult(
                                                self.oAction, uResponse, self)

                                            self.ShowDebug(
                                                u'Parsed Respones:' + uRetVal)

                                            if not self.uRetVar == u'' and not uRetVal == u'':
                                                SetVar(uVarName=self.uRetVar,
                                                       oVarValue=uRetVal)
                                            # We do not need to wait for an response anymore
                                            StartWait(0)
                                            self.bHandled = True

                                        if not self.bHandled:
                                            # we have a notification issued by the device, so lets have a look, if we have a trigger assigned to it
                                            oActionTrigger = self.GetTrigger(
                                                uCommand)
                                            if oActionTrigger is not None:
                                                self.CallTrigger(
                                                    oActionTrigger, uResponse)
                                            else:
                                                self.ShowDebug(
                                                    u'Discard message:' +
                                                    uCommand + ':' + uResponse)
                            #print "LEAVE PARSE"
                            fSleep(0.01)

            except Exception as e:
                if self.bIsConnected:
                    self.ShowError(u'Error Receiving Response:', e)
                self.bIsConnected = False
            try:
                if self.oSocket is not None:
                    self.ShowDebug(u'Closing socket in Thread')
                    self.oSocket.close()
            except Exception as e:
                self.ShowError(u'Error closing socket in Thread', e)
Ejemplo n.º 8
0
def OrcaConfigParser_On_Setting_Change(config, section, key, value):

    uValue = ToUnicode(value)

    if section == "ORCA":
        if   key == u'button_clear_atlas':
            ClearAtlas()
        elif key == u"button_notification":
            uNotification = value.split("_")[-1]
            Globals.oNotifications.SendNotification(uNotification,**{"key":key,"value":value})
        elif key == u'button_discover_rediscover':
            if uValue == u'button_discover_rediscover':
                Globals.oInterFaces.DiscoverAll()
            else:
                Globals.oInterFaces.DiscoverAll(bForce=True)
        elif key == u'button_discover_results':
            from ORCA.utils.Discover import cDiscover_List
            Globals.oApp.oDiscoverList = cDiscover_List()
            Globals.oApp.oDiscoverList.ShowList()
        elif key == u'button_getonline':
            Globals.oTheScreen.AddActionShowPageToQueue(uPageName=u'Page_Settings_Download')
        elif key == u'button_installed_reps':
            Globals.oDownLoadSettings.LoadDirect(uValue, True)
        elif key == u'button_show_installationhint':
            Var_DeleteCookie('SHOWINSTALLATIONHINT', Globals.uDefinitionName)
            Globals.oTheScreen.AddActionToQueue([{'string': 'call', 'actionname': 'Fkt ShowInstallationHint'}])
        elif key == u'button_show_licensefile':
            SetVar(uVarName="SHOWFILE", oVarValue=ReplaceVars("$var(LICENSEFILE)"))
            Globals.oTheScreen.AddActionShowPageToQueue(uPageName=u'Page_ShowFile')
        elif key == u'button_show_credits':
            SetVar(uVarName="SHOWFILE", oVarValue=ReplaceVars("$var(CREDITSFILE)"))
            Globals.oTheScreen.AddActionShowPageToQueue(uPageName=u'Page_ShowFile')
        elif key == u'button_show_logfile':
            SetVar(uVarName="SHOWFILE", oVarValue=ReplaceVars("$var(LOGFILE)"))
            Globals.oTheScreen.AddActionShowPageToQueue(uPageName=u'Page_ShowFile')
        elif key == u'button_show_powerstati':
            Globals.oTheScreen.AddActionShowPageToQueue(uPageName=u'Page_PowerStati')
        elif key == u'button_updateallreps':
            Globals.oDownLoadSettings.UpdateAllInstalledRepositories(True)
        elif key == u'language':
            # Changes the languages, reloads all strings and reloads the settings dialog
            Globals.uLanguage = uValue
            Globals.oApp.InitPathes()
            Globals.oNotifications.SendNotification("on_language_change")
        elif key == u'locales':
            Globals.uLocalesName = uValue
            Globals.oTheScreen.LoadLocales()
        elif key == u'startrepeatdelay':
            Globals.fStartRepeatDelay = float(uValue)
        elif key == u'longpresstime':
            Globals.fLongPressTime = float(uValue)
        elif key == u'contrepeatdelay':
            Globals.fContRepeatDelay = float(uValue)
        elif key == u'clockwithseconds':
            Globals.bClockWithSeconds = (uValue == '1')
        elif key == u'longdate':
            Globals.bLongDate = (uValue == '1')
        elif key == u'longday':
            Globals.bLongDay = (uValue == '1')
        elif key == u'longmonth':
            Globals.bLongMonth = (uValue == '1')
        elif key == u'checkfornetwork':
            Globals.bConfigCheckForNetwork = (uValue == '1')
        elif key == u'vibrate':
            Globals.bVibrate = (uValue == '1')
        elif key == u'interface':
            if uValue == 'select':
                return
            Globals.oTheScreen.uInterFaceToConfig = uValue
            if Globals.oInterFaces.dInterfaces.get(uValue) is None:
                Globals.oInterFaces.LoadInterface(uValue)
            Globals.oTheScreen.AddActionShowPageToQueue(uPageName=u'Page_InterfaceSettings')
            Globals.oOrcaConfigParser.set(u'ORCA', key, u'select')
            Globals.oOrcaConfigParser.write()
        elif key == u'script':
            if uValue == 'select':
                return
            uScript = u''
            Globals.oOrcaConfigParser.set(u'ORCA', key, 'select')
            Globals.oOrcaConfigParser.write()

            tValue = uValue.split(':')
            uValue = tValue[0]
            if len(tValue) > 1:
                uScript = tValue[1]

            # Configure
            if uValue == ReplaceVars('$lvar(516)'):
                Globals.oTheScreen.uScriptToConfig = uScript
                Globals.oTheScreen.AddActionShowPageToQueue(uPageName=u'Page_ScriptSettings')

            # Run
            if uValue == ReplaceVars('$lvar(517)'):
                kwargs = {"caller": "settings"}
                Globals.oScripts.RunScript(uScript,**kwargs)
            Globals.oOrcaConfigParser.set(u'ORCA', key, u'select')
            Globals.oOrcaConfigParser.write()

        elif key == u'definition':
            ShowQuestionPopUp(uTitle='$lvar(599)', uMessage='$lvar(5026)', fktYes=Globals.oApp.on_config_change_change_definition, uStringYes='$lvar(5001)', uStringNo='$lvar(5002)')
        elif key == u'skin':
            Globals.oApp.ReStart()
        elif key == u'rootpath':
            if not Globals.bInit:
                Globals.oApp.close_settings()
                Globals.oApp._app_settings = None
                kivyConfig.write()
                Clock.schedule_once(Globals.oApp.Init_ReadConfig, 0)
            else:
                ShowMessagePopUp(uMessage=u'$lvar(5011)')
        elif key.startswith(u'soundvolume_'):
            uSoundName = key[12:]
            Globals.oSound.SetSoundVolume(uSoundName, ToInt(uValue))
            Globals.oSound.PlaySound(uSoundName)
        elif key == u'button_changedefinitionsetting':
            Globals.uDefinitionToConfigure = uValue[7:]
            Globals.oTheScreen.AddActionShowPageToQueue(uPageName=u'Page_DefinitionSettings')
        else:
            ShowMessagePopUp(uMessage=u'$lvar(5011)')

        # todo: check , if this required anymore
    elif section == Globals.uDefinitionName:
        if key in Globals.oDefinitions.aDefinitionSettingVars:
            SetVar(uVarName = key, oVarValue = value)
        ShowMessagePopUp(uMessage=u'$lvar(5011)')