Print progress when downloading files.
542294
private static int printProgress(String str, long received,
      long advertisedSize, int lastPrinted) {
    if (advertisedSize == 0)
      return 0;
    int currentPercent = (int) ((received * 100) / advertisedSize);
    if (currentPercent != lastPrinted)
      FLOG.info("Downloading: " + str + ", completed: " + currentPercent);
    return currentPercent;
  }
372270
def __on_download_progress_update(self, blocknum, blocksize, totalsize):
        
        if not self.__show_download_progress:
            return

        readsofar = blocknum * blocksize
        if totalsize > 0:
            s = "\r%s / %s" % (size(readsofar), size(totalsize))
            sys.stdout.write(s)
            if readsofar >= totalsize:  # near the end
                sys.stderr.write("\r")
        else:  # total size is unknown
            sys.stdout.write("\rread %s" % (size(readsofar)))
1193945
def notify_progress(self):
        '''  '''
        _total = 0
        for _session in self._sessions.values():
            _total += _session.bytes_transferred

        if AsperaSession.PROGRESS_MSGS_SEND_ALL:
            self._run_progress_callbacks(_total)
        else:
            # dont call progress callback unless total has changed
            if self._total_bytes_transferred != _total:
                self._total_bytes_transferred = _total
                self._run_progress_callbacks(_total)
1218701
def _chunk_iter_progress(it, log, prefix):
    """"""
    n_variants = 0
    before_all = time.time()
    before_chunk = before_all
    for chunk, chunk_length, chrom, pos in it:
        after_chunk = time.time()
        elapsed_chunk = after_chunk - before_chunk
        elapsed = after_chunk - before_all
        n_variants += chunk_length
        chrom = text_type(chrom, 'utf8')
        message = (
            '%s %s rows in %.2fs; chunk in %.2fs (%s rows/s)' %
            (prefix, n_variants, elapsed, elapsed_chunk,
             int(chunk_length // elapsed_chunk))
        )
        if chrom:
            message += '; %s:%s' % (chrom, pos)
        print(message, file=log)
        log.flush()
        yield chunk, chunk_length, chrom, pos
        before_chunk = after_chunk
    after_all = time.time()
    elapsed = after_all - before_all
    print('%s all done (%s rows/s)' %
          (prefix, int(n_variants // elapsed)), file=log)
    log.flush()
881704
def download_report_hook(count, block_size, total_size):
  
  percent = int(count * block_size * 100 / total_size)
  print("\r%d%%" % percent + " completed", end="\r")
1089563
def handle_log_data(self, m):
        ''''''
        if self.download_file is None:
            return
        # lose some data
        # import random
        # if random.uniform(0,1) < 0.05:
        #    print('dropping ', str(m))
        #    return
        if m.ofs != self.download_ofs:
            self.download_file.seek(m.ofs)
            self.download_ofs = m.ofs
        if m.count != 0:
            data = m.data[:m.count]
            s = ''.join(str(chr(x)) for x in data)
            self.download_file.write(s)
            self.download_set.add(m.ofs // 90)
            self.download_ofs += m.count
        self.download_last_timestamp = time.time()
        if m.count == 0 or (m.count < 90 and len(self.download_set) == 1 + (m.ofs // 90)):
            dt = time.time() - self.download_start
            self.download_file.close()
            size = os.path.getsize(self.download_filename)
            speed = size / (1000.0 * dt)
            print("Finished downloading %s (%u bytes %u seconds, %.1f kbyte/sec %u retries)" % (
                self.download_filename,
                size,
                dt, speed,
                self.retries))
            self.download_file = None
            self.download_filename = None
            self.download_set = set()
417642
def download_file_with_progress_bar(url):
    
    request = requests.get(url, stream=True)
    if request.status_code == 404:
        msg = ('there was a 404 error trying to reach {} \nThis probably '
               'means the requested version does not exist.'.format(url))
        logger.error(msg)
        sys.exit()
    total_size = int(request.headers["Content-Length"])
    chunk_size = 1024
    bars = int(total_size / chunk_size)
    bytes_io = io.BytesIO()
    pbar = tqdm(request.iter_content(chunk_size=chunk_size), total=bars,
                unit="kb", leave=False)
    for chunk in pbar:
        bytes_io.write(chunk)
    return bytes_io
377609
def progress(self):
        
        now = time()
        if now - self.last_progress_t > 1:
            self.last_progress_t = now
            if self.status:
                self.uplink.status(self.status)
                self.status = None
            self.__spill_counters()
            self.uplink.progress(self.progress_value)
            self.uplink.flush()
1075133
def _check_if_downloaded(self):
        
        if not os.path.isfile(self.path + self.file_name):
            print("")
            self.msg.template(78)
            print("| Download '{0}' file [ {1}FAILED{2} ]".format(
                self.file_name, self.meta.color["RED"],
                self.meta.color["ENDC"]))
            self.msg.template(78)
            print("")
            if not self.msg.answer() in ["y", "Y"]:
                raise SystemExit()
983172
def check_presence_download(filename, backup_url):
    """"""
    import os
    filename = str(filename) #  Throws error for Path on 3.5
    if not os.path.exists(filename):
        from .readwrite import download_progress
        dr = os.path.dirname(filename)
        try:
            os.makedirs(dr)
        except FileExistsError:
            pass  # ignore if dir already exists
        from urllib.request import urlretrieve
        urlretrieve(backup_url, filename, reporthook=download_progress)
855410
def download_url_with_progress(url, stream, disable_progress):
        
        resp = requests.get(url, timeout=float(os.environ.get('PIP_TIMEOUT', 2)), stream=True)
        resp.raw.decode_content = True

        progress = tqdm(unit="B", unit_scale=True, total=int(resp.headers.get('Content-Length', 0)), disable=disable_progress)
        for chunk in resp.iter_content(chunk_size=1024):
            if chunk:
                progress.update(len(chunk))
                stream.write(chunk)

        progress.close()
988807
def show_progress(self, message=None):
        """'"""
        if self.in_progress_hanging:
            if message is None:
                sys.stdout.write('.')
                sys.stdout.flush()
            else:
                if self.last_message:
                    padding = ' ' * max(0, len(self.last_message)-len(message))
                else:
                    padding = ''
                sys.stdout.write('\r%s%s%s%s' % (' '*self.indent, self.in_progress, message, padding))
                sys.stdout.flush()
                self.last_message = message
80588
def ytdl_progress_hook(self, d):
        """"""
        if d['status'] == 'downloading':
            self.play_empty()

            if "elapsed" in d:
                if d["elapsed"] > self.current_download_elapsed + 4:
                    self.current_download_elapsed = d["elapsed"]

                    current_download = 0
                    current_download_total = 0
                    current_download_eta = 0
                    if "total_bytes" in d and d["total_bytes"] > 0:
                        current_download_total = d["total_bytes"]
                    elif "total_bytes_estimate" in d and d["total_bytes_estimate"] > 0:
                        current_download_total = d["total_bytes_estimate"]
                    if "downloaded_bytes" in d and d["downloaded_bytes"] > 0:
                        current_download = d["downloaded_bytes"]
                    if "eta" in d and d["eta"] > 0:
                        current_download_eta = d["eta"]

                    if current_download_total > 0:
                        percent = round(100 * (current_download / current_download_total))
                        if percent > 100:
                            percent = 100
                        elif percent < 0:
                            percent = 0

                        seconds = str(round(current_download_eta)) if current_download_eta > 0 else ""
                        eta = " ({} {} remaining)".format(seconds, "seconds" if seconds != 1 else "second")

                        downloading = "Downloading song: {}%{}".format(percent, eta)
                        if self.prev_time != downloading:
                            self.timelog.debug(downloading)
                            self.prev_time = downloading
        if d['status'] == 'error':
            self.statuslog.error("Error downloading song")
        elif d['status'] == 'finished':
            self.statuslog.info("Downloaded song")
            downloading = "Downloading song: {}%".format(100)
            if self.prev_time != downloading:
                self.timelog.debug(downloading)
                self.prev_time = downloading

            if "elapsed" in d:
                download_time = "{} {}".format(d["elapsed"] if d["elapsed"] > 0 else "<1",
                                               "seconds" if d["elapsed"] != 1 else "second")
                self.logger.debug("Downloaded song in {}".format(download_time))

            # Create an FFmpeg player
            future = asyncio.run_coroutine_threadsafe(self.create_ffmpeg_player(d['filename']), client.loop)
            try:
                future.result()
            except Exception as e:
                logger.exception(e)
                return
900516
def print_progress_bar(text, done, total, width):
    
    if total > 0:
        n = int(float(width) * float(done) / float(total))
        sys.stdout.write("\r{0} [{1}{2}] ({3}/{4})".format(text, '#' * n, ' ' * (width - n), done, total))
        sys.stdout.flush()
1258090
private void printProgressBar() {

    double x;

    this.out.print("\r");
    this.out.print(PROGRESS_BAR_END_CHAR);

    for (int i = 1; i <= this.length; i++) {

      if (!Double.isNaN(this.progress)) {

        x = (double) i / this.length;
        this.out.print(this.progress >= x ? PROGRESS_BAR_CHAR : PROGRESS_BACKGROUND_CHAR);

      } else { // Double.isNaN(progress)

        this.out.print(PROGRESS_BAR_INDETERMINANT_CHAR);

      }

    }

    this.out.print(PROGRESS_BAR_END_CHAR);

    if (this.maximum > 0) {
      this.out.printf(" (%d/%d)", value, maximum);
    }

    this.out.print(" ");
    this.out.print(status);

  }
768398
def download_file(url, local_filename):
    
    local_filename = os.path.abspath(local_filename)
    path = os.path.dirname(local_filename)
    if not os.path.isdir(path):
        os.makedirs(path)

    with tqdm(unit='B', unit_scale=True) as progress:
        def report(chunk, chunksize, total):
            progress.total = total
            progress.update(chunksize)
        return urlretrieve(url, local_filename, reporthook=report)
168708
def get_progress(self):
        """"""
        progress = self.json_response.get("progress", None)
        self.logger.info("%s\t%s" % (self.request_method, self.request_url))
        return progress