Ejemplo n.º 1
0
 def load(self, loader, cache):
     if self.loaded:
         return
     decompressed = wtc.decompress(self.replay_data)
     parsed = osrparse.parse_replay(decompressed, pure_lzma=True)
     self._process_replay_data(parsed.play_data)
     self.loaded = True
Ejemplo n.º 2
0
    def _check_cache(self, replay_info):
        """
        Checks the cache for a replay matching ``replay_info``.

        Parameters
        ----------
        replay_info: :class:`~circleguard.loader.ReplayInfo`
            The replay info to search for a matching replay with.

        Returns
        -------
        str or None
            The replay data in decompressed lzma form if the cache contains the
            replay, or None if not.
        """
        if not self.read_from_cache:
            return None

        replay_id = replay_info.replay_id

        self.log.log(TRACE, "Checking cache for replay info %s", replay_info)
        result = self._cursor.execute(
            "SELECT replay_data FROM replays WHERE "
            "replay_id=?", [replay_id]).fetchone()
        if result:
            self.log.debug("Loading replay for replay info %s from cache",
                           replay_info)
            return wtc.decompress(result[0], decompressed_lzma=True)
        self.log.log(TRACE, "No replay found in cache")
Ejemplo n.º 3
0
 def load(self, loader, cache):
     if self.loaded:
         return
     decompressed = wtc.decompress(self.replay_data)
     replay_data = circleparse.parse_replay(decompressed,
                                            pure_lzma=True).play_data
     self._process_replay_data(replay_data)
     self.loaded = True
Ejemplo n.º 4
0
    def check_cache(self, map_id, user_id):
        """
        Checks if a replay exists on the given map_id by the given user_id, and returns the decompressed wtc (equivelant to an lzma) string if so.

        Args:
            String map_id: The map_id to check in combination with the user_id.
            String user_id: The user_id to check in combination with the user_id.

        Returns:
            The lzma bytes that would have been returned by decoding the base64 api response, or None if it wasn't cached.
        """

        result = self.cursor.execute("SELECT replay_data FROM replays WHERE map_id=? AND user_id=?", [map_id, user_id]).fetchone()
        return wtc.decompress(result[0]) if result else None
Ejemplo n.º 5
0
    def check_cache(self, replay_info):
        """
        Checks the cache for a replay matching ``replay_info``, returning its
        (uncompressed) replay data if it finds a match, and ``None`` otherwise.

        Parameters
        ----------
        replay_info: :class:`~circleguard.loader.ReplayInfo`
            The replay info to search for a matching replay with.

        Returns
        -------
        str or None
            The replay data in decompressed lzma form if the cache contains the
            replay, or None if not.
        """

        map_id = replay_info.map_id
        user_id = replay_info.user_id
        mods = replay_info.mods
        replay_id = replay_info.replay_id

        self.log.log(
            TRACE,
            "Checking cache for a replay on map %d by user %d with mods %s with replay id %d",
            map_id, user_id, mods, replay_id)
        result = self.cursor.execute(
            "SELECT replay_data FROM replays WHERE replay_id=?",
            [replay_id]).fetchone()
        if result:
            self.log.debug(
                "Loading replay on map %d by user %d with mods %s with replay id %d from cache",
                map_id, user_id, mods, replay_id)
            return wtc.decompress(result[0], decompressed_lzma=True)
        self.log.log(TRACE, "No replay found in cache")
        return None