Exemplo n.º 1
0
    def executeKodiCmd(self, message):
        if self.kodiCmds and 'title' in message:
            match = self.re_kodiCmd.match(message['title'])

            if match:
                cmd = match.group('cmd')

                if cmd in self.kodiCmds:
                    try:
                        cmdObj = self.kodiCmds[cmd]
                        jsonrpc = cmdObj['JSONRPC']

                        if 'body' in message and len(message['body']) > 0:
                            params = message['body'].split('||')

                            # escape bracket '{}' => '{{}}'
                            jsonrpc = jsonrpc.replace('{',
                                                      '{{').replace('}', '}}')
                            # sobstitute custom placeholder '<$var>' => '{var}'
                            jsonrpc = self.re_kodiCmdPlaceholder.sub(
                                '{\\1}', jsonrpc)
                            # format with passed params
                            jsonrpc = jsonrpc.format(params=params)

                        common.log('Executing cmd "%s": %s' % (cmd, jsonrpc))

                        result = common.executeJSONRPC(jsonrpc)

                        common.log('Result for cmd "%s": %s' % (cmd, result))

                        title = common.localise(30104) % cmd
                        body = ''

                        if 'notification' in cmdObj:
                            # same transformation as jsonrpc var
                            body = cmdObj['notification'].replace(
                                '{', '{{').replace('}', '}}')
                            body = self.re_kodiCmdPlaceholder.sub(
                                '{\\1}', body)
                            body = body.format(result=result)

                    except Exception as ex:
                        title = 'ERROR: ' + common.localise(30104) % cmd
                        body = ' '.join(str(arg) for arg in ex.args)
                        common.log(body, xbmc.LOGERROR)
                        common.traceError()

                    common.showNotification(title, body, self.notificationTime,
                                            self.kodiCmdsNotificationIcon)
                    return True

                else:
                    common.log('No "%s" cmd founded!' % cmd, xbmc.LOGERROR)

        return False
Exemplo n.º 2
0
def _checkcryptography():
    ver = None
    try:
        import cryptography
        ver = cryptography.__version__
    except:
        # If the module is not found - no problem
        return
        
    ver_parts = list(map(int, ver.split('.')))
    if len(ver_parts) < 2 or ver_parts[0] < 1 or (ver_parts[0] == 1 and ver_parts[1] < 7):
        log('Python cryptography module version %s is too old, at least version 1.7 needed' % ver)
        xbmcgui.Dialog().ok(ADDONNAME, localise(32040) % ver, localise(32041), localise(32042))
    def executeKodiCmd(self, message):
        if self.kodiCmds and 'title' in message:
            match = self.re_kodiCmd.match(message['title'])

            if match:
                cmd = match.group('cmd')

                if cmd in self.kodiCmds:
                    try:
                        cmdObj = self.kodiCmds[cmd]
                        jsonrpc = cmdObj['JSONRPC']

                        if 'body' in message and len(message['body']) > 0:
                            params = message['body'].split('||')

                            # escape bracket '{}' => '{{}}'
                            jsonrpc = jsonrpc.replace('{', '{{').replace('}', '}}')
                            # sobstitute custom placeholder '<$var>' => '{var}'
                            jsonrpc = self.re_kodiCmdPlaceholder.sub('{\\1}', jsonrpc)
                            # format with passed params
                            jsonrpc = jsonrpc.format(params=params)

                        common.log('Executing cmd "%s": %s' % (cmd, jsonrpc))

                        result = common.executeJSONRPC(jsonrpc)

                        common.log('Result for cmd "%s": %s' % (cmd, result))

                        title = common.localise(30104) % cmd
                        body = ''

                        if 'notification' in cmdObj:
                            # same transformation as jsonrpc var
                            body = cmdObj['notification'].replace('{', '{{').replace('}', '}}')
                            body = self.re_kodiCmdPlaceholder.sub('{\\1}', body)
                            body = body.format(result=result)

                    except Exception as ex:
                        title = 'ERROR: ' + common.localise(30104) % cmd
                        body = ' '.join(str(arg) for arg in ex.args)
                        common.log(body, xbmc.LOGERROR)
                        common.traceError()

                    common.showNotification(title, body, self.notificationTime, self.kodiCmdsNotificationIcon)
                    return True

                else:
                    common.log('No "%s" cmd founded!' % cmd, xbmc.LOGERROR)

        return False
Exemplo n.º 4
0
def _checkcryptography():
    ver = None
    try:
        import cryptography
        ver = cryptography.__version__
    except:
        # If the module is not found - no problem
        return

    ver_parts = list(map(int, ver.split('.')))
    if len(ver_parts) < 2 or ver_parts[0] < 1 or (ver_parts[0] == 1
                                                  and ver_parts[1] < 7):
        log('Python cryptography module version %s is too old, at least version 1.7 needed'
            % ver)
        xbmcgui.Dialog().ok(ADDONNAME,
                            localise(32040) % ver, localise(32041),
                            localise(32042))
Exemplo n.º 5
0
    def run(self):
        """
        Run or restart service.
        """

        if self.pushbullet:
            common.log('Restarting')
            self.pushbullet.close()

        try:
            if not self.stg_pbAccessToken or not self.stg_pbClientIden:
                raise Exception(common.localise(30100))

            from lib.pushbullet import Pushbullet

            # init pushbullet
            self.pushbullet = Pushbullet(
                access_token=self.stg_pbAccessToken,
                ping_timeout=6,
                last_modified=common.getSetting('last_modified', 0),
                last_modified_callback=self.setLastModified,
                log_callback=common.log)

            # get device info (also if edited by user on Pushbullet panel)
            self._getDevice()

            # setup service and pushbullet (iden, mirroring, filter)
            self._setupService()

            # start listening websocket
            self.pushbullet.realTimeEventStream(
                on_open=self.push2Notification.onOpen,
                on_message=self.push2Notification.onMessage,
                on_error=self.push2Notification.onError,
                on_close=self.push2Notification.onClose)

            common.log('Service started successfully')

        except Exception as ex:
            common.traceError()
            message = ' '.join(str(arg) for arg in ex.args)

            common.log(message, xbmc.LOGERROR)
            common.showNotification(common.localise(30101), message,
                                    self.serviceNotifcationTime)
Exemplo n.º 6
0
    def run(self):
        """
        Run or restart service.
        """

        if self.pushbullet:
            common.log('Restarting')
            self.pushbullet.close()

        try:
            if not self.stg_pbAccessToken or not self.stg_pbClientIden:
                raise Exception(common.localise(30100))

            from lib.pushbullet import Pushbullet

            # init pushbullet
            self.pushbullet = Pushbullet(   access_token=self.stg_pbAccessToken,
                                            ping_timeout=6,
                                            last_modified=common.getSetting('last_modified',0),
                                            last_modified_callback=self.setLastModified,
                                            log_callback=common.log)

            # get device info (also if edited by user on Pushbullet panel)
            self._getDevice()

            # setup service and pushbullet (iden, mirroring, filter)
            self._setupService()

            # start listening websocket
            self.pushbullet.realTimeEventStream(on_open=self.push2Notification.onOpen,
                                                on_message=self.push2Notification.onMessage,
                                                on_error=self.push2Notification.onError,
                                                on_close=self.push2Notification.onClose)

            common.log('Service started successfully')

        except Exception as ex:
            common.traceError()
            message = ' '.join(str(arg) for arg in ex.args)

            common.log(message, xbmc.LOGERROR)
            common.showNotification(common.localise(30101), message, self.serviceNotifcationTime)
Exemplo n.º 7
0
 def onError(self, error):
     common.log(error, xbmc.LOGERROR)
     common.showNotification(common.localise(30101), error,
                             self.notificationTime, self.notificationIcon)
 def onError(self, error):
     common.log(error, xbmc.LOGERROR)
     common.showNotification(common.localise(30101), error, self.notificationTime, self.notificationIcon)