Exemplo n.º 1
0
    def CreateDownloadQueueForRepositoryItem(self, uRepType, uRepName):
        """ we need to prevent an endless recursion on dependencies, so we need to track, what we allready have """

        oDownLoadObject = cDownLoadObject()
        uRef = uRepType + uRepName

        if not uRef in self.aQueue:
            self.aQueue.append(uRef)
            aSubList = [
                oEntries for oEntries in oRepository.aRepEntries
                if oEntries.uRepType == uRepType
            ]
            aEntry = [
                oEntries for oEntries in aSubList if oEntries.uName == uRepName
            ]

            if len(aEntry) > 0:
                oEntry = aEntry[0]

                iInstalledVersion = GetInstalledVersion(uRepType, uRepName)

                if (oEntry.iVersion > iInstalledVersion) or self.bForce:
                    for oSource in oEntry.aSources:
                        oDownLoadObject.aPars["Url"] = oSource.uSourceFile
                        oDownLoadObject.aPars["Dest"] = (
                            cFileName(Globals.oPathTmp) +
                            'download.xml').string
                        oDownLoadObject.aPars["Target"] = oSource.uTargetPath
                        oDownLoadObject.aPars["Type"] = uRepType
                        oDownLoadObject.aPars["Name"] = uRepName
                        oDownLoadObject.aPars["Version"] = oEntry.iVersion
                        oDownLoadObject.aPars["Finalize"] = "FILE ZIP"

                        uString = oDownLoadObject.ToString()
                        if uString not in self.aItemQueue:
                            self.aItemQueue.append(uString)

                    for oDependency in oEntry.aDependencies:
                        self.CreateDownloadQueueForRepositoryItem(
                            oDependency.uType, oDependency.uName)
                else:
                    Logger.info(
                        'Skipping download of repository type:%s Resource:%s, Resource version [%d] not newer than installed version [%d]'
                        % (uRepType, uRepName, oEntry.iVersion,
                           iInstalledVersion))

            else:
                LogError("can\'t find Resource in Resourcelist: [%s] %s" %
                         (uRepType, uRepName))
                ShowErrorPopUp(
                    uMessage="can\'t find Resource in Resourcelist: [%s] %s" %
                    (uRepType, uRepName))
Exemplo n.º 2
0
    def ParseXMLBaseNode(self, oXMLNode: Element,
                         oParentScreenPage: cScreenPage, uAnchor: str) -> bool:

        try:
            self.uActionName = GetXMLTextAttribute(oXMLNode=oXMLNode,
                                                   uTag=u'action',
                                                   bMandatory=False,
                                                   vDefault=u'')
            self.uActionNameDoubleTap = GetXMLTextAttribute(
                oXMLNode=oXMLNode,
                uTag=u'actiondoubletap',
                bMandatory=False,
                vDefault=u'')
            self.uActionNameLongTap = GetXMLTextAttribute(
                oXMLNode=oXMLNode,
                uTag=u'actionlongtap',
                bMandatory=False,
                vDefault=u'')
            self.uActionNameDownOnly = GetXMLTextAttribute(
                oXMLNode=oXMLNode,
                uTag=u'actiondownonly',
                bMandatory=False,
                vDefault=u'')
            self.uActionNameUpOnly = GetXMLTextAttribute(oXMLNode=oXMLNode,
                                                         uTag=u'actionuponly',
                                                         bMandatory=False,
                                                         vDefault=u'')
            uActionPars: str = GetXMLTextAttribute(oXMLNode=oXMLNode,
                                                   uTag=u'actionpars',
                                                   bMandatory=False,
                                                   vDefault=u'{}')
            if uActionPars.startswith("$var("):
                uActionPars = ReplaceVars(uActionPars)

            self.dActionPars = ToDic(uActionPars)

            if self.uActionName.startswith("SendCommand "):
                if len(self.dActionPars) == 0:
                    self.dActionPars = {"commandname": self.uActionName[12:]}
                    self.uActionName = "Send"

            if not self.uInterFace == u'':
                Globals.oInterFaces.dUsedInterfaces[self.uInterFace] = True

            return super().ParseXMLBaseNode(oXMLNode, oParentScreenPage,
                                            uAnchor)

        except Exception as e:
            LogError(uMsg=u'Error parsing widget from element (Action):[' +
                     self.uName + "",
                     oException=e)
            return False
Exemplo n.º 3
0
    def PlaySound(self,
                  *,
                  uSoundName: str,
                  vSoundVolume: Union[float, str] = -1.0) -> bool:
        """ plays a given sound with a given volume """
        iSoundVolume: int
        fVolume: float
        vVolume: Union[str, float]
        dSound: Optional[Dict[str, Union[cFileName, int]]]
        oFnSound: cFileName

        if self.bMute:
            return True

        try:
            dSound = self.aSounds.get(uSoundName)
            vVolume = vSoundVolume
            if dSound is not None:
                oFnSound = dSound["oFnSound"]
                iSoundVolume = dSound["iSoundVolume"]
            else:
                oFnSound = cFileName('').ImportFullPath(uFnFullName=uSoundName)
                iSoundVolume = 100

            if oFnSound and not oFnSound.IsEmpty():
                oSound = self.dSoundObjects.get(oFnSound.string)
                # temporary disabled
                if oSound is None or True:
                    oSound = SoundLoader.load(oFnSound.string)
                    self.dSoundObjects[oFnSound.string] = oSound
                if oSound:
                    if oSound.state != 'stop':
                        oSound.stop()

                    if isinstance(vSoundVolume, str):
                        if vSoundVolume != u'':
                            vVolume = ToFloat(vSoundVolume)

                    if not vVolume == -1.0 and not vVolume == u'':
                        fVolume = cast(float, vVolume) * (iSoundVolume / 100.0)
                    else:
                        fVolume = iSoundVolume * 1.0

                    fVolume = fVolume / 100.0
                    oSound.volume = fVolume

                    if fVolume > 0:
                        oSound.play()
            return True
        except Exception as e:
            LogError(uMsg=u'Playing sound failed:' + uSoundName, oException=e)
            return False
Exemplo n.º 4
0
    def Unzip(self, oPath:cPath) -> bool:
        """
        Unzips a zip file  to a path
        If the output location does not yet exist, it creates it

        :param cPath oPath:
        :return: True if successful
        """

        oZip:Union[ZipFile,None]=None
        uEach:str
        uRoot:str
        uName:str
        oFn:cFileName
        # oFn:cPath

        try:

            Logger.debug(u'Extracting file [%s] to path [%s]' % (self.string, oPath.string))

            oZip = ZipFile(self.string, 'r')
            if not oPath.IsDir():
                oPath.Create()
            for uEach in oZip.namelist():
                # each=ToUnicode(each)

                Logger.debug(u'Extracting ' + ToUnicode(basename(uEach)) + ' ...')
                # Check to see if the item was written to the zip file with an
                # archive name that includes a parent directory. If it does, create
                # the parent folder in the output workspace and then write the file,
                # otherwise, just write the file to the workspace.
                #
                if not uEach.endswith('/'):
                    uRoot, uName = split(uEach)
                    oFolder = cPath(oPath) + uRoot
                    if not oFolder.IsDir():
                        oFolder.Create()
                    oFn = cFileName(oFolder) + uName
                    uFn = oFn.string
                    Logger.debug(u'... Writing to ' + uFn)
                    oFile = open(uFn, 'wb')
                    oFile.write(oZip.read(uEach))
                    oFile.close()
            oZip.close()
            return True
        except Exception as e:
            LogError(uMsg=u'Unzip: Fatal Error unzipping file',oException=e)
            try:
                oZip.close()
            except Exception:
                pass
            return False
Exemplo n.º 5
0
 def LoadLanguage(self, uLanguageFileName=u'', uContext=''):
     """ Loads the languages files """
     try:
         if uLanguageFileName:
             Logger.info(u'TheScreen: Loading Language File [%s]' % (uLanguageFileName))
             Globals.oLanguage.LoadXmlFile(uLanguageFileName)
         else:
             Logger.info(u'TheScreen: Loading Language [%s]' % (Globals.uLanguage))
             Globals.oLanguage.LoadXmlFile("APP")
             self.LoadLocales()
     except Exception as e:
         uMsg=LogError(u'TheScreen: LoadLanguage: can\'t load Language:',e)
         ShowErrorPopUp(uMessage=uMsg)
Exemplo n.º 6
0
def Var_Save(uVarName, uPrefix):
    """ Saves a var to a cookie """
    uValue = GetVar(uVarName=uVarName)

    oFN = CookieName(uVarName, u'var_' + uPrefix)
    try:
        oFile = open(oFN.string, 'w')
        oFile.write(uValue)
        oFile.close()
    except Exception as e:
        LogError(u'Var_Save: can\'t safe var', e)
        return u'Error'
    return
Exemplo n.º 7
0
def Var_Load(uVarName, uDefault, uPrefix):
    """ loads a var from a cookie """
    oFN = CookieName(uVarName, u'var_' + uPrefix)
    uVarValue = uDefault
    if oFN.Exists():
        try:
            oFile = open(oFN.string, 'r')
            uVarValue = oFile.read()
            oFile.close()
        except Exception as e:
            LogError(u'Var_Save: can\'t load var', e)
    SetVar(uVarName=uVarName, oVarValue=uVarValue)
    return uVarValue
Exemplo n.º 8
0
    def ShowError(self, uMsg: str, oException: Any = None) -> str:
        """ Creates a parser error message """
        iErrNo: int = 0

        if oException is not None:
            if hasattr(oException, 'errno'):
                iErrNo = oException.errno
        if iErrNo is None:
            iErrNo = 12345
        uRet = LogError(uMsg=self.uDebugContext + u': ' + uMsg +
                        " (%d) " % iErrNo,
                        oException=oException)
        return uRet
Exemplo n.º 9
0
    def SetPageEffectDirection(self,*,uDirection:str='fade') -> bool:
        """ Sets the Page effect direction (in case , the effect has an direction) """
        self.uCurrentEffectDirection = uDirection

        try:
            if ToUnicode(type(self.oRootSM.transition)).endswith(u'SlideTransition\'>') or True:
                if uDirection!=u'':
                    self.oRootSM.transition.direction=uDirection
            return True
        except Exception as e:
            uMsg:str=LogError(uMsg=u'TheScreen: Can not set page effect direction:' + uDirection ,oException=e)
            ShowErrorPopUp(uMessage=uMsg)
            return False
Exemplo n.º 10
0
    def _LoadXmlFile(self,oFnFile):
        """ Loads all strings for the language from a specific files"""
        if not oFnFile.Exists():
            Logger.debug (u'Language: String File does not exist:'+oFnFile.string)
            return
        if oFnFile.string in self.aLoadedFiles:
            Logger.debug (u'Language: Skip duplicate language file loading:'+oFnFile.string)
            return

        oDef = None
        try:
            sET_Data = CachedFile(oFnFile)
            if Globals.uDefinitionContext:
                oDef = Globals.oDefinitions.get(Globals.uDefinitionContext)
            oET_Root = Orca_FromString(sET_Data,oDef,oFnFile.string)
            self.__LoadXMLNode(oET_Root,self.dIDToString)
        except ParseError as e:
            uMsg=LogError(u'Language: Fatal Error:Load Language XmlFile (xml parse error):'+oFnFile.string,e)
            ShowErrorPopUp(uTitle='Fatal Error',uMessage=uMsg, bAbort=True)
        except Exception as e:
            uMsg=LogError(u'Language: Fatal Error:Load Language XmlFile (2):'+oFnFile.string,e)
            ShowErrorPopUp(uTitle='Fatal Error',uMessage=uMsg, bAbort=True)
Exemplo n.º 11
0
 def NotificationHandler_ScriptEnded(self,*args,**kwargs) -> None:
     oDiscoverScriptStatus:cDiscoverScriptStatus
     uScriptname:str
     try:
         self.oDiscoverListWaitLock.acquire()
         uScriptName                         = kwargs.get("scriptname")
         oDiscoverScriptStatus               = self.dScripts[uScriptName]
         oDiscoverScriptStatus.uScriptStatus = kwargs.get("scriptstatus")
         self.oDiscoverListWaitLock.release()
         self.UpdateResults()
     except Exception as e:
         LogError(uMsg="Error on Script ended message handler",oException=e)
     return
Exemplo n.º 12
0
    def GetActions(self) -> bool:
        if len(self.aActionNames) == 1 and len(self.aCaptions) > 1:
            # noinspection PyUnusedLocal
            self.aActionNames = [self.aActionNames[0] for x in range(len(self.aCaptions))]

        if self.uActionNameLongTap == u"":
            self.uActionNameLongTap = "noaction"

        if len(self.aActionNames) != len(self.aCaptions) and len(self.aCaptions) > 0:
            LogError(uMsg=u'cWidgetDropDown: [%s] Captions do not match Actions: %s' % (self.uName, self.uActionName))
            return False
        else:
            return True
Exemplo n.º 13
0
    def __init__(self,uFile: Union[str,cPath,cFileName] = u''):

        self.oPath: cPath  = cPath()
        self.uRaw: str
        if isinstance(uFile, str):
            self.uRaw       = uFile
        elif isinstance(uFile, cPath):
            self.oPath  = uFile
            self.uRaw   = u''
        elif isinstance(uFile, cFileName):
            self.oPath  = uFile.oPath
            self.uRaw = uFile.uRaw
        else:
            LogError(uMsg="cFileName, illegal constructor:"+str(type(uFile)))
        self.uFinal: str      = u''
        self.bDirty: bool     = True

        if Logger.level==logging.DEBUG and False:
            if self.uRaw:
                for uChar in u"/\\:":
                    if uChar in self.uRaw:
                        LogError(uMsg="do not pass full strings to a filename (use import):"+str(uFile), bTrackStack=True)
Exemplo n.º 14
0
    def CreatePage(self, uPageName):
        """ Will be used by EventDispatcher in case pages will not be created at startup """

        if uPageName == u'':
            Globals.oTheScreen.oCurrentPage.Create()
            return
        oPage = self.get(uPageName)
        if oPage:
            oPage.Create()
            return
        uMsg = LogError(u'TheScreen: Fatal Error:Page does not exist:' +
                        uPageName)
        ShowErrorPopUp(uTitle="Fatal Error", uMessage=uMsg, bAbort=True)
Exemplo n.º 15
0
 def LoadLocales(self):
     """ Loads the locales """
     Logger.info (u'TheScreen: Loading Locales [%s]' % (Globals.uLocalesName))
     try:
         if not Globals.uLocalesName in Globals.oLanguage.oLocales.oLocalesEntries:
             for  Globals.uLocalesName in Globals.oLanguage.oLocales.oLocalesEntries:
                 Logger.debug (u'TheScreen: Cant\'t find locales, defaulting to [%s]' % (Globals.uLocalesName))
                 oConfig=Globals.oOrcaConfigParser
                 oConfig.set(u'ORCA', u'locales', Globals.uLocalesName)
                 break
     except Exception as e:
         uMsg=LogError(u'TheScreen: LoadLocales: can\'t load Locales',e)
         ShowErrorPopUp(uMessage=uMsg)
Exemplo n.º 16
0
 def NotificationHandler_ScriptFoundItem(self,*args,**kwargs) -> None:
     oDiscoverScriptStatus:cDiscoverScriptStatus
     uScriptname:str
     try:
         self.oDiscoverListWaitLock.acquire()
         uScriptName                         = kwargs.get("scriptname")
         oDiscoverScriptStatus               = self.dScripts[uScriptName]
         oDiscoverScriptStatus.aScriptContentLineText.append(kwargs.get("line"))
         oDiscoverScriptStatus.aScriptContentLineDevice.append(kwargs.get("device"))
         self.oDiscoverListWaitLock.release()
     except Exception as e:
         LogError(uMsg="Error on Script found message handler",oException=e)
     return
Exemplo n.º 17
0
def Var_Load(*, uVarName: str, uDefault: str, uPrefix: str) -> str:
    """ loads a var from a cookie """
    oFN: cFileName = CookieName(uVarName=uVarName, uPrefix=u'var_' + uPrefix)
    uVarValue: str = uDefault
    if oFN.Exists():
        try:
            oFile = open(oFN.string, 'r')
            uVarValue = oFile.read()
            oFile.close()
        except Exception as e:
            LogError(uMsg=u'Var_Save: can\'t load var', oException=e)
    SetVar(uVarName=uVarName, oVarValue=uVarValue)
    return uVarValue
Exemplo n.º 18
0
    def IsZipFile(self):
        """
        Checks if a file is a zipfile

        :rtype: bool
        :return: True  is file is a zipfile
        """

        try:
            return is_zipfile(self.string)
        except Exception as e:
            LogError(u'IsZipFile: Error for:'+self.string, e)
            return False
Exemplo n.º 19
0
    def StatusControl(self, uStatus: str, uStream: str) -> Tuple[int, str]:
        """ Controls the video stream """
        try:
            if uStatus == u'play':
                self.oObject.source = self.NormalizeStream(uStream)
                self.oObject.state = 'play'
                return 0, ''
            if uStatus == u'stop':
                self.oObject.state = 'stop'
                return 0, ''
            if uStatus == u'pause':
                self.oObject.state = 'pause'
                return 0, ''
            if uStatus == u'getvolume':
                return 0, ToUnicode(self.oObject.volume)
            if uStatus == u'volume_down':
                self.oObject.volume = max(0.0, self.oObject.volume - 0.05)
                return 0, ToUnicode(self.oObject.volume)
            if uStatus == u'volume_up':
                self.oObject.volume = min(1.0, self.oObject.volume + 0.05)
                return 0, ToUnicode(self.oObject.volume)
            if uStatus == u'repeat_toggle':
                self.bRepeat = not self.bRepeat
                return 0, ToUnicode(self.bRepeat)
            if uStatus == u'repeat_on':
                self.bRepeat = True
                return 0, ToUnicode(self.bRepeat)
            if uStatus == u'repeat_off':
                self.bRepeat = False
                return 0, ToUnicode(self.bRepeat)
            if uStatus == u'mute_on':
                if self.oObject.volume != 0:
                    self.fOldVolume = self.oObject.volume
                    self.oObject.volume = 0
                return 0, ToUnicode(self.oObject.volume)
            if uStatus == u'mute_off':
                if self.fOldVolume != -1:
                    self.oObject.volume = self.fOldVolume
                return 0, ToUnicode(self.oObject.volume)
            if uStatus == u'mute_toggle':
                if self.oObject.volume != 0:
                    self.fOldVolume = self.oObject.volume
                    self.oObject.volume = 0
                elif self.fOldVolume != -1:
                    self.oObject.volume = self.fOldVolume
                return 0, ToUnicode(self.oObject.volume)
        except Exception as e:
            LogError(uMsg=u'Widget:Video:Error on Statuscontrol:' + uStatus,
                     oException=e)

        return 0, ''
Exemplo n.º 20
0
    def Discover(self):

        oSocket = None
        try:
            self.bStopWait = False

            oSocket = self.SendDiscover()
            if oSocket:
                # Parse all results
                while True:
                    #we do not wait too long
                    ready = select.select([oSocket], [], [], self.fTimeOut)
                    if ready[0]:
                        # Get a response
                        sData, tSenderAddr = oSocket.recvfrom(1024)
                        oRet = self.GetDeviceDetails(sData=sData,
                                                     tSenderAddr=tSenderAddr)
                        self.CheckDeviceDetails(oRet=oRet)
                        if oRet.bFound:
                            Logger.info(
                                u'Bingo: Discovered device %s:%s:%s at %s:' %
                                (oRet.uFoundManufacturer, oRet.uFoundModel,
                                 oRet.uFoundFriendlyName, oRet.sFoundIP))
                            try:
                                if oRet.uIPVersion == "IPv4":
                                    oRet.uFoundHostName = socket.gethostbyaddr(
                                        oRet.sFoundIP)[0]
                                elif oRet.uIPVersion == "IPv6":
                                    #todo: Does not work for unknown reasons
                                    oRet.uFoundHostName = socket.gethostbyaddr(
                                        oRet.sFoundIP)[0]
                            except Exception as e:
                                # Logger.error("Cant get Hostname:"+oRet.sFoundIP+" "+str(e))
                                pass
                            cThread_Discover_UPNP.oWaitLock.acquire()
                            self.oCaller.aResults.append(oRet)
                            cThread_Discover_UPNP.oWaitLock.release()
                            if self.bOnlyOnce:
                                oSocket.close()
                                return
                    else:
                        break
                oSocket.close()
            # Logger.warning(u'No device found device %s:%s:%s' %(self.oReq.uManufacturer,self.oReq.uModels,self.oReq.uFriendlyName))
            return

        except Exception as e:
            LogError(u'Error on discover uPnP (%s)' % (self.uIPVersion), e)
            if oSocket:
                oSocket.close()
            return
Exemplo n.º 21
0
    def ChangeDir(self, oPath):
        """
        Changes to a remote ftp directory

        :param cPath oPath: the remote path to create
        :return: True/False
        """
        try:
            self.oFTP.cwd(oPath.unixstring)
            return True
        except Exception as e:
            LogError('can\'t change directory (%s) ...' % (oPath.unixstring),
                     e)
        return False
Exemplo n.º 22
0
def GetXMLTextAttribute(*, oXMLNode: Element, uTag: str, bMandatory: bool,
                        vDefault: Any) -> str:
    """ Returns a string from a xml attribute"""
    if oXMLNode is None:
        return vDefault
    oObj: str = oXMLNode.get(uTag)
    if oObj is None:
        if bMandatory:
            ShowErrorPopUp(uMessage=LogError(uMsg=u'XML Error: Attribut [' +
                                             uTag + '] missing'),
                           bAbort=True)
        return vDefault
    # oObj=ToUnicode(oObj)
    return oObj
Exemplo n.º 23
0
 def On_Save(self, instance):
     """ saves the Codeset file """
     try:
         oRoot = ElementTree(fromstring(self.oXMLText.text))
         oFilename = cFileName(
             Globals.oPathCodesets) + oDBSelector.oCodesetName.text
         oRoot.write(
             oFilename.string,
             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)
     self.oPopup.dismiss()
Exemplo n.º 24
0
def Orca_FromString(sET_Data, oDef, sFileName="Unknown"):
    """  reads xml from a string and sets the definition context vars """
    try:
        if oDef is None:
            return fromstring(sET_Data)
        else:
            oET_Root = fromstring(
                ReplaceDefVars(sET_Data, oDef.oDefinitionVars))

        oET_Root.set('definitioncontext', oDef.uName)
        oET_Root.set('definitionalias', oDef.uAlias)
        oET_Root.set('replacementvars', oDef.oDefinitionVars)

        for e in oET_Root:
            e.set('definitioncontext', oDef.uName)
            e.set('definitionalias', oDef.uAlias)
            e.set('replacementvars', oDef.oDefinitionVars)
            e.set('linefilename', sFileName)
        return oET_Root
    except Exception as e:
        LogError('FromString:Invalid XML:' + sFileName, e)
        LogError(ReplaceDefVars(sET_Data, oDef.oDefinitionVars))
    return None
Exemplo n.º 25
0
def SystemIsOnline():
    """
    verifies, if the system has a network connection by system APIs (not by ping)
    returns true, if OS doesn't support it
    """
    try:
        Logger.debug("Checking Android network connectivity")
        Hardware = GetAndroidModule("Hardware")
        bRet = Hardware.checkNetwork()
        detach()
        return bRet
    except Exception as e:
        LogError('SystemIsOnline:', e)
        return True
Exemplo n.º 26
0
def Ping(uHostname: str) -> bool:
    """ executes an ping statement (Windows Version) """

    try:
        #response = os.system(u"ping -c 1 -w 1 " + uHostname)
        uCmd: str = u"ping -w 500 -c 1 " + uHostname
        Logger.debug('Ping: Sending Command :' + uCmd)
        response = os.system(uCmd)
        Logger.debug('Ping returned :' + str(response))
    except Exception as e:
        LogError(uMsg='Ping: Error on Ping:', oException=e)
        return True

    return response == 0
Exemplo n.º 27
0
    def ShowList(self):
        """ Shows the discover results """
        try:
            # create the popup
            oScrollContentSingle:GridLayout
            oContent:GridLayout
            oScrollview:ScrollView
            uDiscoverScriptName:str
            aDiscoverScripts:List[str]
            uDiscoverScriptName:str
            oThread:cThread_Discover

            self.iHashStarted   = Globals.oNotifications.RegisterNotification(uNotification="DISCOVER_SCRIPTSTARTED",   fNotifyFunction=self.NotificationHandler_ScriptStarted,   uDescription="Notification list discovery started")
            self.iHashEnded     = Globals.oNotifications.RegisterNotification(uNotification="DISCOVER_SCRIPTENDED",     fNotifyFunction=self.NotificationHandler_ScriptEnded,     uDescription="Notification list discovery ended")
            self.iHashFound     = Globals.oNotifications.RegisterNotification(uNotification="DISCOVER_SCRIPTFOUND",     fNotifyFunction=self.NotificationHandler_ScriptFoundItem, uDescription="Notification list discovery found item")

            oContent               = GridLayout(cols=1, spacing='5dp')
            oScrollview            = ScrollView( do_scroll_x=False)
            self.oPopup:Popup      = Popup(content=oContent, title=ReplaceVars('$lvar(5028)'), size_hint=(0.9, 0.9),  auto_dismiss=False)

            #we need to open the popup first to get the metrics
            self.oPopup.open()
            #Add some space on top
            oContent.add_widget(Widget(size_hint_y=None, height=dp(2)))
            aDiscoverScripts = Globals.oScripts.GetScriptListForScriptType("DEVICE_DISCOVER")
            for uDiscoverScriptName in aDiscoverScripts:
                # if uDiscoverScriptName == u"discover_eiscp" or uDiscoverScriptName == u"discover_kira" or uDiscoverScriptName == u"discover_elvmax" or uDiscoverScriptName == u"discover_enigma" or uDiscoverScriptName==u"discover_upnp":
                #if uDiscoverScriptName == u"discover_kira":
                if True:
                    oScrollContentSingle= GridLayout(size_hint=(None, None),size=(self.oPopup.width, dp(10)))
                    oScrollContentSingle.bind(minimum_height=oScrollContentSingle.setter('height'))
                    oThread = cThread_Discover(uScriptName=uDiscoverScriptName,dParKwArgs={'createlist':1,'oGrid':oScrollContentSingle})
                    self.aThreads.append(oThread)
                    self.aThreads[-1].start()

            # finally, add a cancel button to return on the previous panel
            oScrollview.add_widget(self.oScrollContent)
            oContent.add_widget(oScrollview)
            oContent.add_widget(SettingSpacer())

            oBtn: Button = Button(text=ReplaceVars('$lvar(5000)'), size=(self.oPopup.width, dp(50)),size_hint=(1, None))
            oBtn.bind(on_release=self.On_Cancel)
            oContent.add_widget(oBtn)

            #resize the Scrollcontent to fit to all childs. Needs to be done, after the popup has been shown
            Clock.schedule_once(self.SetScrollSize, 0)
            self.oTimerUpdate = Clock.schedule_interval(self.UpdateResults, 2)
        except Exception as e:
            LogError(uMsg="Critical error string discover scripts",oException=e)
Exemplo n.º 28
0
 def NotificationHandler_ScriptStarted(self,*args,**kwargs) -> None:
     try:
         self.oDiscoverListWaitLock.acquire()
         oDiscoverScriptStatus:cDiscoverScriptStatus = cDiscoverScriptStatus()
         oDiscoverScriptStatus.uScriptName   = kwargs.get("scriptname")
         oDiscoverScriptStatus.uScriptTitle  = kwargs.get("scripttitle")
         oDiscoverScriptStatus.uScriptStatus = kwargs.get("scriptstatus")
         oDiscoverScriptStatus.oScript       = kwargs.get("script")
         oDiscoverScriptStatus.oGrid         = kwargs.get("grid")
         self.dScripts[oDiscoverScriptStatus.uScriptName] = oDiscoverScriptStatus
         self.oDiscoverListWaitLock.release()
         self.UpdateResults()
     except Exception as e:
         LogError(uMsg="Error on Script started message handler",oException=e)
     return
Exemplo n.º 29
0
def WriteXMLFile(*, oFile: cFileName, oElem: Element) -> bool:
    """
    Save an Element node to an xml file

    :param cFileName oFile: xml file to save
    :param Element oElem: XML Element to save
    :return: Element tree element
    """
    try:
        oET = ET(oElem)
        oET.write(oFile.string, encoding="UTF-8", xml_declaration=True)
        return True
    except Exception as e:
        LogError(uMsg='Can' 't write XML File:' + oFile.string, oException=e)
        return False
Exemplo n.º 30
0
 def Connect(self, uServer):
     """ connects to an ftp server """
     if not self.bEncrypt:  # Use standard FTP
         self.oFTP = ftplib.FTP()
     else:  # Use sftp
         self.oFTP = ftplib.FTP_TLS()
     try:
         self.oFTP.connect(uServer)
         if self.bEncrypt:
             self.oFTP.prot_p()
         return True
     except Exception as e:
         uMsg = LogError('FTP: Could not connect to (%s)' % (uServer), e)
         ShowErrorPopUp(uMessage=uMsg)
     return False