示例#1
0
 def _extract_progress(self, index, count, filename):
     if index == -1:
         logger.progress_begin(None, True)
         logger.progress_update(0.0, "Reading index...")
         return
     progress = index / float(count)
     if index == 0:
         logger.progress_end()
         logger.progress_begin(None, False)
     elif index == (count - 1):
         logger.progress_end()
     else:
         logger.progress_update(progress, "{} / {}".format(index, count))
示例#2
0
    def _download_progress(self, url, context, data):
        spinning = data["size"] is None
        if data["downloaded"] == 0:
            # If what we're trying to download already exists, we don't have
            # to redownload it.
            suffix, directory = self._get_archive_unpack_info(context, data["filename"])
            urlfile = path.join(directory, ".craftr_downloadurl")
            if path.isfile(urlfile):
                with open(urlfile) as fp:
                    if fp.read().strip() == url:
                        raise self.DownloadAlreadyExists(directory)

            logger.progress_begin("Downloading {}".format(url), spinning)
        if spinning:
            # TODO: Bytes to human readable
            logger.progress_update(None, data["downloaded"])
        else:
            progress = data["downloaded"] / data["size"]
            logger.progress_update(progress, "{}%".format(int(progress * 100)))
        if data["completed"]:
            logger.progress_end()