Ejemplo n.º 1
0
    def get_cached_files(self):
        """
        Returns cached files

        Returns:
            list: list of cached files
        """
        dl = Download(self.context.paths.cache)

        return dl.get_cached_files()
Ejemplo n.º 2
0
    def purge_cached_files(self):
        """
        Purge all cached files

        Returns:
            list: list of cached files
        """
        dl = Download(self.context.paths.cache)
        dl.purge_files(force_all=True)

        return dl.get_cached_files()
Ejemplo n.º 3
0
    def get_latest_cleep(self):
        """
        Return latest cleep release

        Returns:
            tuple: cleep release files and release version::
                (
                    [{
                        name (string): release name
                        url (string): file url
                        size (int): filesize
                        timestamp (int): timestamp of release
                    }],
                    string: release name (usually version)
                )
        """
        # get releases infos from github
        release = self.github.get_latest_release()
        self.logger.debug("Cleep release: %s" % release)

        # check if release exists
        if not release:
            # no release found, surely rate limit reached on github api
            # fallback to cached releases
            download = Download(self.context.paths.cache)
            cached_releases = download.get_cached_files()
            self.logger.debug("Cached releases: %s" % cached_releases)

            if len(cached_releases) > 0:
                # sort to keep recent one
                cached_releases_sorted = sorted(cached_releases,
                                                key=itemgetter("timestamp"))
                cached_releases_sorted.reverse()
                for cached_release in cached_releases_sorted:
                    if cached_release["filename"].startswith("cleep_"):
                        # and return it
                        return [{
                            "name": cached_release["filename"],
                            "url": "file://%s" % cached_release["filepath"],
                            "size": cached_release["filesize"],
                            "timestamp": cached_release["timestamp"],
                        }], cached_release["filename"].replace("cleep_",
                                                               "").replace(
                                                                   ".zip", "")

                # no cleep cached
                return None, None

            else:
                # no file cached
                return None, None
        else:
            return self.github.get_release_assets_infos(
                release), release["name"]
Ejemplo n.º 4
0
    def delete_cached_file(self, filename):
        """
        Delete specified cached file

        Args:
            filename (string): file path

        Returns:
            list: list of cached files
        """
        dl = Download(self.context.paths.cache)
        dl.delete_cached_file(filename)

        return dl.get_cached_files()