Path: blob/master/Convolutional Neural Networks/dummy/__pycache__/download.cpython-35.pyc
24409 views
��YU � @ sX d d l Z d d l Z d d l Z d d l Z d d l Z d d � Z d d � Z d S)� Nc C sD t | | � | } d j | � } t j j | � t j j � d S)z}
Function used for printing the download progress.
Used as a call-back function in maybe_download_and_extract().
z
- Download progress: {0:.1%}N)�float�format�sys�stdout�write�flush)�count�
block_size�
total_sizeZpct_complete�msg� r �/output/download.py�_print_download_progress s r c C s | j d � d } t j j | | � } t j j | � s� t j j | � sY t j | � t j j d | d | d t � \ } } t
� t
d � | j d � r� t j
d | d d
� j | � n. | j d � r� t j d
| d d � j | � t
d � n
t
d � d S)a�
Download and extract the data if it doesn't already exist.
Assumes the url is a tar-ball file.
:param url:
Internet URL for the tar-file to download.
Example: "https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz"
:param download_dir:
Directory where the downloaded file is saved.
Example: "data/CIFAR-10/"
:return:
Nothing.
�/� �url�filename�
reporthookz$Download finished. Extracting files.z.zip�file�mode�r�.tar.gz�.tgz�namezr:gzzDone.z9Data has apparently already been downloaded and unpacked.N�����)r r )�split�os�path�join�exists�makedirs�urllib�request�urlretriever �print�endswith�zipfile�ZipFile�
extractall�tarfile�open)r �download_dirr � file_path�_r r r
�maybe_download_and_extract0 s
"
r. )r r �urllib.requestr! r) r&