Simple wrapper around urlretrieve that uses tqdm to display a progress
    bar of download progress
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)
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
1282799
def main():
    """"""
    # Prepare.
    if os.name == 'nt':
        locale.setlocale(locale.LC_ALL, 'english-us')
    else:
        locale.resetlocale()
    response = requests.get(OPTIONS['<url>'], stream=True)
    content_length = None if OPTIONS['--ignore-length'] else int(response.headers.get('Content-Length'))
    progress_bar = ProgressBarWget(content_length, eta_every=4)
    thread = DownloadThread(response)
    print_every_seconds = 0.25

    # Download.
    thread.start()
    while True:
        progress_bar.numerator = thread.bytes_downloaded
        print(progress_bar, end='\r')
        sys.stdout.flush()

        # For undefined downloads (no content-length), check if thread has stopped. Loop only checks defined downloads.
        if not thread.isAlive():
            progress_bar.force_done = True
            break
        if progress_bar.done:
            break

        time.sleep(print_every_seconds)
    print(progress_bar)
489530
def progress_bar(self, c, broker):
        
        v = broker.get(c)

        if v and isinstance(v, dict) and len(v) > 0 and 'type' in v:
            if v["type"] in self.responses:
                print(self.responses[v["type"]].color + self.responses[v["type"]].intl + Style.RESET_ALL, end="", file=self.stream)
            else:
                print(".", end="", file=self.stream)
        elif c in broker.exceptions:
            self.counts['exception'] += len(broker.exceptions[c])
            print(Fore.RED + "E" + Style.RESET_ALL, end="", file=self.stream)
        return self
338099
function(resp){	

	// Update the bar.
	requests_done++;
	jQuery('#progress-bar').progressbar({ value: requests_done });
	jQuery("#progress-count").empty();
	jQuery("#progress-count").append(requests_done);

	// Count is easy.
	var count = resp.total_documents();
	if( count > max_count ){
	    max_count = count;
	}

	// Now let's try and fiqure out which terms we were looking
	// at...
	var fqs = resp.query_filters();
	//console.log(resp);
	var fprops = fqs[closure_type];

	var axes = [];
	us.each(fprops, function(fval, fkey){
	    axes.push(fkey);
	});	
	var axis1 = axes[0];
	var axis2 = axes[1] || axis1; // the reflexive case

	ll(' Data from: (' + axis1 + ', ' + axis2 + '); ' + count);

	// Structure for the links we've seen, level 1.
	if( typeof(seen_links[axis1]) === 'undefined' ){
	    seen_links[axis1] = {}; }
	if( typeof(seen_links[axis2]) === 'undefined' ){
	    seen_links[axis2] = {}; }
	// Mark the links we've seen, level 2.
	if( typeof(seen_links[axis2][axis1]) === 'undefined' ){
	    seen_links[axis2][axis1] = count; }
	if( typeof(seen_links[axis1][axis2]) === 'undefined' ){
	    seen_links[axis1][axis2] = count; }
    }
568535
def maybe_download_and_extract():
  """"""
  dest_directory = "/tmp/cifar"
  if not os.path.exists(dest_directory):
    os.makedirs(dest_directory)
  filename = DATA_URL.split('/')[-1]
  filepath = os.path.join(dest_directory, filename)
  if not os.path.exists(filepath):
    def _progress(count, block_size, total_size):
      sys.stdout.write('\r>> Downloading %s %.1f%%' % (filename,
          float(count * block_size) / float(total_size) * 100.0))
      sys.stdout.flush()
    filepath, _ = urllib.request.urlretrieve(DATA_URL, filepath, _progress)
    print()
    statinfo = os.stat(filepath)
    print('Successfully downloaded', filename, statinfo.st_size, 'bytes.')
    tarfile.open(filepath, 'r:gz').extractall(dest_directory)
1093938
def _load(self, url):
        
        self._logger.debug('Loading url %s into resource cache' % url)
        retriever = get_resource_retriever(url)
        content_path = os.path.join(self.path, self._hash_path(url))

        try:
            if url in self.metadata:
                headers = retriever.fetch(content_path, last_etag=self.metadata[url]['etag'], progress_bar=self.progress_bars)
                if headers is None:
                    # no update, return what is already loaded
                    self._logger.info('Cached %s is up-to-date. No data download needed' % url)
                    return self.metadata[url]
            else:
                headers = retriever.fetch(content_path, progress_bar=self.progress_bars)
                if headers is None:
                    raise Exception('Fetch of %s failed' % url)

            if 'etag' not in headers:
                # No Etag returned, so generate it
                headers['etag'] = fs_util.calc_file_md5(content_path)

            # Populate metadata from the headers
            self.metadata[url] = headers.copy()
            self.metadata[url]['content'] = content_path
            return self.metadata[url]
        except:
            self._logger.error('Failed getting resource: %s')

            # forcibly flush local entry if found
            if url in self.metadata:
                self.metadata.pop(url)
            raise
        finally:
            if url not in self.metadata:
                self._logger.debug('Cleaning up on failed load of %s' % url)
                # Cleanup on failure
                if content_path is not None and os.path.exists(content_path):
                    os.remove(content_path)
454539
def cli_progress(addr, offset, size):
    """"""
    width = 25
    done = offset * width // size
    print("\r0x{:08x} {:7d} [{}{}] {:3d}% "
          .format(addr, size, '=' * done, ' ' * (width - done),
                  offset * 100 // size), end="")
    try:
        sys.stdout.flush()
    except OSError:
        pass # Ignore Windows CLI "WinError 87" on Python 3.6
    if offset == size:
        print("")
241439
def progress_string(self):
        """"""

        if not self.last_result:
            return self._status_string()

        def location_string(hostname, pid):
            if hostname == os.uname()[1]:
                return "pid={}".format(pid)
            else:
                return "{} pid={}".format(hostname, pid)

        pieces = [
            "{}".format(self._status_string()), "[{}]".format(
                self.resources.summary_string()), "[{}]".format(
                    location_string(
                        self.last_result.get(HOSTNAME),
                        self.last_result.get(PID))), "{} s".format(
                            int(self.last_result.get(TIME_TOTAL_S)))
        ]

        if self.last_result.get(TRAINING_ITERATION) is not None:
            pieces.append("{} iter".format(
                self.last_result[TRAINING_ITERATION]))

        if self.last_result.get(TIMESTEPS_TOTAL) is not None:
            pieces.append("{} ts".format(self.last_result[TIMESTEPS_TOTAL]))

        if self.last_result.get(EPISODE_REWARD_MEAN) is not None:
            pieces.append("{} rew".format(
                format(self.last_result[EPISODE_REWARD_MEAN], ".3g")))

        if self.last_result.get(MEAN_LOSS) is not None:
            pieces.append("{} loss".format(
                format(self.last_result[MEAN_LOSS], ".3g")))

        if self.last_result.get(MEAN_ACCURACY) is not None:
            pieces.append("{} acc".format(
                format(self.last_result[MEAN_ACCURACY], ".3g")))

        return ", ".join(pieces)
212194
function download(uri, dest, progressCallback) {
    "use strict";
    progressCallback = progressCallback || function() {};
    var parsedUrl = url.parse(uri, false, true);
    var makeRequest = parsedUrl.protocol === 'https:' ? https.request.bind(https) : http.request.bind(http);
    var serverPort = parsedUrl.port ? parsedUrl.port : parsedUrl.protocol === 'https:' ? 443 : 80;
    var agent = parsedUrl.protocol === 'https:' ? httpsAgent : httpAgent;
    var file = fs.createWriteStream(dest);

    var options = {
        host: parsedUrl.host,
        path: parsedUrl.path,
        agent: agent,
        port: serverPort,
        method: 'GET'
    };

    return new Promise(function (resolve, reject) {

        var req = makeRequest(options, function (response) {
            var size = response.headers['content-length'];
            var progress = 0;

            response.on('data', function(chunk) {
                progress += chunk.length;
                progressCallback(size, progress);
            });

            response.pipe(file);
            file.on('finish', function() {
                resolve({
                    status: response.statusCode
                });
            });
        });

        req.on('error', function(error) {
            file.end();
            rimraf.sync(dest);
            reject(error);
        });

        req.end();
    });
}
566750
function downloadInstaller(requester, isInitialAttempt, updateParams) {
        updateParams = updateParams || _updateParams;
        var currentRequester = requester || "";
        try {
            var ext = path.extname(updateParams.installerName);
            var localInstallerPath = path.resolve(updateDir, Date.now().toString() + ext),
                localInstallerFile = fs.createWriteStream(localInstallerPath),
                requestCompleted = true,
                readTimeOut = 180000;
            progress(request(updateParams.downloadURL, {timeout: readTimeOut}), {})
                .on('progress', function (state) {
                    var target = "retry-download";
                    if (isInitialAttempt) {
                        target = "initial-download";
                    }
                    var info = Math.floor(parseFloat(state.percent) * 100).toString() + '%';
                    var status = {
                        target: target,
                        spans: [{
                            id: "percent",
                            val: info
                        }]
                    };
                    postMessageToBrackets(MessageIds.SHOW_STATUS_INFO, currentRequester, status);
                })
                .on('error', function (err) {
                    console.log("AutoUpdate : Download failed. Error occurred : " + err.toString());
                    requestCompleted = false;
                    localInstallerFile.end();
                    var error = err.code === 'ESOCKETTIMEDOUT' || err.code === 'ENOTFOUND' ?
                                nodeErrorMessages.NETWORK_SLOW_OR_DISCONNECTED :
                                nodeErrorMessages.DOWNLOAD_ERROR;
                    postMessageToBrackets(MessageIds.NOTIFY_DOWNLOAD_FAILURE, currentRequester, error);
                })
                .pipe(localInstallerFile)
                .on('close', function () {
                    if (requestCompleted) {
                        try {
                            fs.renameSync(localInstallerPath, installerPath);
                            postMessageToBrackets(MessageIds.NOTIFY_DOWNLOAD_SUCCESS, currentRequester);
                        } catch (e) {
                            console.log("AutoUpdate : Download failed. Exception occurred : " + e.toString());
                            postMessageToBrackets(MessageIds.NOTIFY_DOWNLOAD_FAILURE,
                                                      currentRequester, nodeErrorMessages.DOWNLOAD_ERROR);
                        }
                    }
                });
        } catch (e) {
            console.log("AutoUpdate : Download failed. Exception occurred : " + e.toString());
            postMessageToBrackets(MessageIds.NOTIFY_DOWNLOAD_FAILURE,
                                  currentRequester, nodeErrorMessages.DOWNLOAD_ERROR);
        }
    }
1019907
def progress_bar(**kwargs):
    
    tqdm_kw = {
        'desc': 'Processing',
        'file': sys.stdout,
        'bar_format': TQDM_BAR_FORMAT,
    }
    tqdm_kw.update(kwargs)
    pbar = tqdm(**tqdm_kw)
    if not pbar.disable:
        pbar.desc = pbar.desc.rstrip(': ')
        pbar.refresh()
    return pbar
1220856
def _downloadfile(self, url, fname):
        '''  '''

        print("The file %s need to be download - Wait\n " %
              (fname.split('/')[-1]))
        urllib.urlretrieve(url, fname, self._report)
        print("\n The download of the file %s has succeded \n " %
              (fname.split('/')[-1]))
427082
def _download_vswhere():
    
    print('downloading from', _get_latest_release_url())
    try:
        from urllib.request import urlopen
        with urlopen(_get_latest_release_url()) as response, open(DOWNLOAD_PATH, 'wb') as outfile:
            shutil.copyfileobj(response, outfile)
    except ImportError:
        # Python 2
        import urllib
        urllib.urlretrieve(_get_latest_release_url(), DOWNLOAD_PATH)
801803
def _get_http(url, temp_file_name, initial_size, file_size, verbose_bool,
              progressbar, ncols=80):
    """"""
    # Actually do the reading
    req = urllib.request.Request(url)
    if initial_size > 0:
        req.headers['Range'] = 'bytes=%s-' % (initial_size,)
    try:
        response = urllib.request.urlopen(req)
    except Exception:
        # There is a problem that may be due to resuming, some
        # servers may not support the "Range" header. Switch
        # back to complete download method
        tqdm.write('Resuming download failed (server '
                   'rejected the request). Attempting to '
                   'restart downloading the entire file.')
        del req.headers['Range']
        response = urllib.request.urlopen(req)
    total_size = int(response.headers.get('Content-Length', '1').strip())
    if initial_size > 0 and file_size == total_size:
        tqdm.write('Resuming download failed (resume file size '
                   'mismatch). Attempting to restart downloading the '
                   'entire file.')
        initial_size = 0
    total_size += initial_size
    if total_size != file_size:
        raise RuntimeError('URL could not be parsed properly')
    mode = 'ab' if initial_size > 0 else 'wb'
    if progressbar is True:
        progress = tqdm(total=total_size, initial=initial_size, desc='file_sizes',
                        ncols=ncols, unit='B', unit_scale=True)

    chunk_size = 8192  # 2 ** 13
    with open(temp_file_name, mode) as local_file:
        while True:
            t0 = time.time()
            chunk = response.read(chunk_size)
            dt = time.time() - t0
            if dt < 0.005:
                chunk_size *= 2
            elif dt > 0.1 and chunk_size > 8192:
                chunk_size = chunk_size // 2
            if not chunk:
                break
            local_file.write(chunk)
            if progressbar is True:
                progress.update(len(chunk))
149214
def get_tqdm_kwargs(**kwargs):
    
    default = dict(
        smoothing=0.5,
        dynamic_ncols=True,
        ascii=True,
        bar_format='{l_bar}{bar}|{n_fmt}/{total_fmt}[{elapsed}<{remaining},{rate_noinv_fmt}]'
    )

    try:
        # Use this env var to override the refresh interval setting
        interval = float(os.environ['TENSORPACK_PROGRESS_REFRESH'])
    except KeyError:
        interval = _pick_tqdm_interval(kwargs.get('file', sys.stderr))

    default['mininterval'] = interval
    default.update(kwargs)
    return default
52020
def check_urls(urls):
    '''
    
    '''
    threads = list()
    progress_bar = None
    progress_counter = 0

    if SHOW_PROGRESS_BAR and len(urls) > 0:

        widgets = [SimpleProgress()]
        progress_bar = ProgressBar(widgets=widgets, maxval=len(urls)).start()

    for u in urls:
        t = Thread(target=async_check_url, args=(u[0], u[1], u[2]))
        t.start()
        threads.append(t)

    for thread in threads:
        if SHOW_PROGRESS_BAR and len(urls) > 0:
            progress_counter = progress_counter + 1
            progress_bar.update(progress_counter)

        thread.join()

    if SHOW_PROGRESS_BAR and len(urls) > 0:
        progress_bar.finish()