B
    ãUvgr  ã               @   sª   d dl mZ d dlZd dlZd dlmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZ d d	lmZ d d
lmZmZ d dlmZ e e¡ZG dd„ deƒZdS )é    )Úabsolute_importN)Ú
cmdoptions)ÚRequirementCommand)ÚRequirementPreparer)ÚRequirementSet)ÚRequirementTracker)ÚResolver)Úcheck_path_owner)Ú
ensure_dirÚnormalize_path)ÚTempDirectoryc                   s4   e Zd ZdZdZdZdZ‡ fdd„Zdd„ Z‡  Z	S )	ÚDownloadCommandaL  
    Download packages from:

    - PyPI (and other indexes) using requirement specifiers.
    - VCS project urls.
    - Local project directories.
    - Local or remote source archives.

    pip also supports downloading from "requirements files", which provide
    an easy way to specify a whole environment to be downloaded.
    Údownloada  
      %prog [options] <requirement specifier> [package-index-options] ...
      %prog [options] -r <requirements file> [package-index-options] ...
      %prog [options] <vcs project url> ...
      %prog [options] <local project path> ...
      %prog [options] <archive url/path> ...zDownload packages.c          
      s`  t t| ƒj||Ž | j}| t ¡ ¡ | t ¡ ¡ | t ¡ ¡ | t 	¡ ¡ | t 
¡ ¡ | t ¡ ¡ | t ¡ ¡ | t ¡ ¡ | t ¡ ¡ | t ¡ ¡ | t ¡ ¡ | t ¡ ¡ | t ¡ ¡ | t ¡ ¡ |jddddddtjdd | t ¡ ¡ | t ¡ ¡ | t ¡ ¡ | t ¡ ¡ t tj| j¡}| j d	|¡ | j d	|¡ d S )
Nz-dz--destz--destination-dirz--destination-directoryÚdownload_dirÚdirzDownload packages into <dir>.)ÚdestÚmetavarÚdefaultÚhelpr   )Úsuperr   Ú__init__Úcmd_optsÚ
add_optionr   ÚconstraintsÚrequirementsÚ	build_dirÚno_depsÚglobal_optionsÚ	no_binaryÚonly_binaryÚprefer_binaryÚsrcÚpreÚno_cleanÚrequire_hashesÚprogress_barÚno_build_isolationÚosÚcurdirÚplatformÚpython_versionÚimplementationÚabiÚmake_option_groupÚindex_groupÚparserÚinsert_option_group)ÚselfÚargsÚkwr   Ú
index_opts)Ú	__class__© ú@/tmp/pip-install-r_9ig3yj/pip/pip/_internal/commands/download.pyr   *   s>    zDownloadCommand.__init__c             C   s  d|_ g |_|jr|jg}nd }t |¡ tj |j¡|_t	|j
ƒ|_
t|j
ƒ |  |¡*}| j|||j||j|jd}|jp„|j }|jr¬t|jƒs¬t d|j¡ d |_tƒ Ê}t|j|dd®}t|jd}	|  |	||||| jd ¡ t|j|j|j
d |j|j|d}
t |
||d dd	d|j!dd|j"d
}| #|	¡ d $dd„ |	j%D ƒ¡}|r^t &d|¡ |jsn|	 '¡  W d Q R X W d Q R X W d Q R X |	S )NT)ÚoptionsÚsessionr)   Úpython_versionsr,   r+   zÝThe directory '%s' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.r   )ÚdeleteÚkind)r$   )r   Úsrc_dirr   Úwheel_download_dirr%   Úbuild_isolationÚreq_trackerFzto-satisfy-only)ÚpreparerÚfinderr9   Úwheel_cacheÚuse_user_siteÚupgrade_strategyÚforce_reinstallÚignore_dependenciesÚignore_requires_pythonÚignore_installedÚisolatedú c             S   s   g | ]
}|j ‘qS r6   )Úname)Ú.0Úreqr6   r6   r7   ú
<listcomp>¥   s    z'DownloadCommand.run.<locals>.<listcomp>zSuccessfully downloaded %s)(rI   Ú	editablesr*   r   Úcheck_dist_restrictionr'   ÚpathÚabspathr=   r   r   r
   Ú_build_sessionÚ_build_package_finderr)   r,   r+   r#   r   Ú	cache_dirr	   ÚloggerÚwarningr   r   r   r$   Úpopulate_requirement_setrL   r   r%   r?   r   rG   Úisolated_modeÚresolveÚjoinÚsuccessfully_downloadedÚinfoÚcleanup_files)r1   r8   r2   r:   r9   rB   Úbuild_deleter@   Ú	directoryÚrequirement_setrA   ÚresolverÚ
downloadedr6   r6   r7   ÚrunS   s€    







&zDownloadCommand.run)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__rL   ÚusageÚsummaryr   re   Ú__classcell__r6   r6   )r5   r7   r      s   )r   )Ú
__future__r   Úloggingr'   Zpip._internal.clir   Úpip._internal.cli.base_commandr   Ú pip._internal.operations.preparer   Zpip._internal.reqr   Úpip._internal.req.req_trackerr   Úpip._internal.resolver   Úpip._internal.utils.filesystemr	   Úpip._internal.utils.miscr
   r   Úpip._internal.utils.temp_dirr   Ú	getLoggerrf   rW   r   r6   r6   r6   r7   Ú<module>   s   
