示例#1
0
文件: __init__.py 项目: maxo2/mycroft
    def refresh_token(self):
        LOG.debug('Refreshing token')
        if identity_lock.acquire(blocking=False):
            try:
                data = self.send({
                    "path": "auth/token",
                    "headers": {
                        "Authorization": "Bearer " + self.identity.refresh,
                        "Device": self.identity.uuid
                    }
                })
                IdentityManager.save(data, lock=False)
                LOG.debug('Saved credentials')
            except HTTPError as e:
                if e.response.status_code == 401:
                    LOG.error('Could not refresh token, invalid refresh code.')
                else:
                    raise

            finally:
                identity_lock.release()
        else:  # Someone is updating the identity wait for release
            with identity_lock:
                LOG.debug('Refresh is already in progress, waiting until done')
                time.sleep(1.2)
                os.sync()
                self.identity = IdentityManager.load(lock=False)
                LOG.debug('new credentials loaded')
示例#2
0
    def refresh_token(self):
        LOG.debug('Refreshing token')
        if identity_lock.acquire(blocking=False):
            try:
                data = self.send({
                    "path": "auth/token",
                    "headers": {
                        "Authorization": "Bearer " + self.identity.refresh
                    }
                })
                IdentityManager.save(data, lock=False)
                LOG.debug('Saved credentials')
            except HTTPError as e:
                if e.response.status_code == 401:
                    LOG.error('Could not refresh token, invalid refresh code.')
                else:
                    raise

            finally:
                identity_lock.release()
        else:  # Someone is updating the identity wait for release
            with identity_lock:
                LOG.debug('Refresh is already in progress, waiting until done')
                time.sleep(1.2)
                os.sync()
                self.identity = IdentityManager.load(lock=False)
                LOG.debug('new credentials loaded')
示例#3
0
 def _on_connect(self, client, userdata, flags, rc):
     if rc == 0:
         LOG.info("MQTT Client connected successfully to host {}".format(
             self.host))
         self.connected = True
     else:
         LOG.error("MQTT Client could not connect to host {}".format(
             self.host))
示例#4
0
 def _on_message(self, client, userdata, message):
     if message.topic in self.registered_handlers:
         format_message = Message(type='mqtt',
                                  destination=str(message.topic).split('/'),
                                  data=json.loads(str(message.payload)))
         self.registered_handlers[message.topic](format_message)
     else:
         LOG.error(
             "No handler was registered for message on topic {}".format(
                 message.topic))
示例#5
0
def create_client(protocol, settings):
    """Create the appropriate client for a specified protocol

    Args:
        protocol(str): protocol to be used
        settings(dict): skill settings object containing

    Returns:
        Client: Client object
    """
    if protocol == "mqtt":
        return MQTTClient(settings)
    else:
        LOG.error("Protocol {} not supported".format(protocol))
        return None
示例#6
0
    def anime(self, anime_id):
        if anime_id not in self._animes:
            try:

                def do_request():
                    return self._jikan.anime(anime_id)

                anime = self._delay_request(do_request)
                self._animes[anime_id] = anime
            except APIException as e:
                LOG.error(str.format('exception getting anime id:{}',
                                     anime_id))
                LOG.error(e)
                return None
        return self._animes[anime_id]
示例#7
0
    def animelist_watching(self):
        if self._animelist_watching is None or time.time(
        ) - self._animelist_watching_time > 5 * 60:
            try:

                def do_request():
                    return self._jikan.user(username=self._mal_username,
                                            request='animelist',
                                            argument='watching')

                self._animelist_watching = self._delay_request(do_request)
                self._animelist_watching_time = time.time()
            except APIException as e:
                LOG.error('exception getting watchlist')
                LOG.error(e)
        return self._animelist_watching
示例#8
0
文件: __init__.py 项目: maxo2/mycroft
    def delete_skill_metadata(self, uuid):
        """ Delete the current skill metadata from backend

            TODO: Real implementation when method exists on backend
        Args:
            uuid (str): unique id of the skill
        """
        try:
            LOG.debug("Deleting remote metadata for {}".format(skill_gid))
            self.request({
                "method":
                "DELETE",
                "path":
                ("/" + self.identity.uuid + "/skill" + "/{}".format(skill_gid))
            })
        except Exception as e:
            LOG.error("{} cannot delete metadata because this".format(e))