def maybe_download_tc(target_dir, tc_url, progress=True):

    def report_progress(count, block_size, total_size):
        percent = (((count * block_size) * 100) // total_size)
        sys.stdout.write(('\rDownloading: %d%%' % percent))
        sys.stdout.flush()
        if (percent >= 100):
            print('\n')
    assert (target_dir is not None)
    target_dir = os.path.abspath(target_dir)
    try:
        os.makedirs(target_dir)
    except OSError as e:
        if (e.errno != errno.EEXIST):
            raise e
    assert os.path.isdir(os.path.dirname(target_dir))
    tc_filename = os.path.basename(tc_url)
    target_file = os.path.join(target_dir, tc_filename)
    is_gzip = False
    if (not os.path.isfile(target_file)):
        print(('Downloading %s ...' % tc_url))
        (_, headers) = urllib.request.urlretrieve(tc_url, target_file, reporthook=(report_progress if progress else None))
        is_gzip = (headers.get('Content-Encoding') == 'gzip')
    else:
        print(('File already exists: %s' % target_file))
    if is_gzip:
        with open(target_file, 'r+b') as frw:
            decompressed = gzip.decompress(frw.read())
            frw.seek(0)
            frw.write(decompressed)
            frw.truncate()
    return target_file
def maybe_download_tc(target_dir, tc_url, progress=True):

    def report_progress(count, block_size, total_size):
        percent = (((count * block_size) * 100) // total_size)
        sys.stdout.write(('\rDownloading: %d%%' % percent))
        sys.stdout.flush()
        if (percent >= 100):
            print('\n')
    assert (target_dir is not None)
    target_dir = os.path.abspath(target_dir)
    try:
        os.makedirs(target_dir)
    except OSError as e:
        if (e.errno != errno.EEXIST):
            raise e
    assert os.path.isdir(os.path.dirname(target_dir))
    tc_filename = os.path.basename(tc_url)
    target_file = os.path.join(target_dir, tc_filename)
    is_gzip = False
    if (not os.path.isfile(target_file)):
        print(('Downloading %s ...' % tc_url))
        (_, headers) = urllib.request.urlretrieve(tc_url, target_file, reporthook=(report_progress if progress else None))
        is_gzip = (headers.get('Content-Encoding') == 'gzip')
    else:
        print(('File already exists: %s' % target_file))
    if is_gzip:
        with open(target_file, 'r+b') as frw:
            decompressed = gzip.decompress(frw.read())
            frw.seek(0)
            frw.write(decompressed)
            frw.truncate()
    return target_file