(updater)
Print the available mirrors to the terminal (in a human friendly format).
Print the available mirrors to the terminal (in a human friendly format).
Print the available mirrors to the terminal ( in a human friendly format ) .
def report_available_mirrors(updater):
    """Print the available mirrors to the terminal (in a human friendly format)."""
    if connected_to_terminal() or os.getenv('TRAVIS') == 'true':  # make Travis CI test this code
        # https://docs.travis-ci.com/user/environment-variables/#default-environment-variables
        have_bandwidth = any(c.bandwidth for c in updater.ranked_mirrors)
        have_last_updated = any(c.last_updated is not None for c in updater.ranked_mirrors)
        column_names = ["Rank", "Mirror URL", "Available?", "Updating?"]
        if have_last_updated:
            column_names.append("Last updated")
        if have_bandwidth:
            column_names.append("Bandwidth")
        data = []
        long_mirror_urls = {}
        if os.getenv('TRAVIS') == 'true' and updater.url_char_len < 50:
            updater.url_char_len = 50
        for i, candidate in enumerate(updater.ranked_mirrors, start=1):
            if len(candidate.mirror_url) <= updater.url_char_len:
                stripped_mirror_url = candidate.mirror_url
            else:  # the mirror_url is too long, strip it
                stripped_mirror_url = candidate.mirror_url[:updater.url_char_len - 3]
                stripped_mirror_url = stripped_mirror_url + "..."
                long_mirror_urls[i] = candidate.mirror_url  # store it, output as full afterwards
            row = [i, stripped_mirror_url,
                   "Yes" if candidate.is_available else "No",
                   "Yes" if candidate.is_updating else "No"]
            if have_last_updated:
                row.append("Up to date" if candidate.last_updated == 0 else (
                    "%s behind" % format_timespan(candidate.last_updated, max_units=1)
                    if candidate.last_updated else "Unknown"
                ))
            if have_bandwidth:
                row.append("%s/s" % format_size(round(candidate.bandwidth, 0))
                           if candidate.bandwidth else "Unknown")
            data.append(row)
        output(format_table(data, column_names=column_names))
        if long_mirror_urls:
            output(u"Full URLs which are too long to be shown in above table:")
            for key in long_mirror_urls:
                output(u"%i: %s", key, long_mirror_urls[key])
    else:
        output(u"\n".join(
            candidate.mirror_url for candidate in updater.ranked_mirrors
            if candidate.is_available and not candidate.is_updating
        ))
def report_available_mirrors ( updater ) : if connected_to_terminal ( ) or os . getenv ( 'TRAVIS' ) == 'true' : # make Travis CI test this code # https://docs.travis-ci.com/user/environment-variables/#default-environment-variables have_bandwidth = any ( c . bandwidth for c in updater . ranked_mirrors ) have_last_updated = any ( c . last_updated is not None for c in updater . ranked_mirrors ) column_names = [ "Rank" , "Mirror URL" , "Available?" , "Updating?" ] if have_last_updated : column_names . append ( "Last updated" ) if have_bandwidth : column_names . append ( "Bandwidth" ) data = [ ] long_mirror_urls = { } if os . getenv ( 'TRAVIS' ) == 'true' and updater . url_char_len < 50 : updater . url_char_len = 50 for i , candidate in enumerate ( updater . ranked_mirrors , start = 1 ) : if len ( candidate . mirror_url ) <= updater . url_char_len : stripped_mirror_url = candidate . mirror_url else : # the mirror_url is too long, strip it stripped_mirror_url = candidate . mirror_url [ : updater . url_char_len - 3 ] stripped_mirror_url = stripped_mirror_url + "..." long_mirror_urls [ i ] = candidate . mirror_url # store it, output as full afterwards row = [ i , stripped_mirror_url , "Yes" if candidate . is_available else "No" , "Yes" if candidate . is_updating else "No" ] if have_last_updated : row . append ( "Up to date" if candidate . last_updated == 0 else ( "%s behind" % format_timespan ( candidate . last_updated , max_units = 1 ) if candidate . last_updated else "Unknown" ) ) if have_bandwidth : row . append ( "%s/s" % format_size ( round ( candidate . bandwidth , 0 ) ) if candidate . bandwidth else "Unknown" ) data . append ( row ) output ( format_table ( data , column_names = column_names ) ) if long_mirror_urls : output ( u"Full URLs which are too long to be shown in above table:" ) for key in long_mirror_urls : output ( u"%i: %s" , key , long_mirror_urls [ key ] ) else : output ( u"\n" . join ( candidate . mirror_url for candidate in updater . ranked_mirrors if candidate . is_available and not candidate . is_updating ) )