î
½1kdå9  ã               @   s®   d  d l  Z  d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l m Z m Z m	 Z	 d  d l
 m Z d  d l m Z d  d l m Z Gd d „  d e ƒ Z d S)é    N)Údisplay_pathÚ
backup_dirÚrmtree)Úlogger)ÚInstallationError)ÚCommandc                   s²   e  Z d  Z d Z d Z d Z d Z ‡  f d d †  Z d d „  Z d	 d
 „  Z	 d d „  Z
 d d „  Z d d „  Z d d „  Z d d „  Z d d „  Z d d „  Z d d „  Z ‡  S)Ú
ZipCommandzZip individual packages.Úzipz#
     %prog [options] <package> ...z$DEPRECATED. Zip individual packages.c          
      s9  t  t |  ƒ j | | Ž  |  j d k rM |  j j d d d d d d d ƒn( |  j j d	 d d
 d d d d d d ƒ|  j j d d d d d d d ƒ|  j j d d d d d d d d ƒ|  j j d d d d d d d ƒ|  j j d d d d d d d ƒ|  j j d d d d d d ƒ|  j j d |  j ƒ d  S) Nr	   z--unzipÚactionÚ
store_trueÚdestÚunzipÚhelpz"Unzip (rather than zip) a package.z--zipÚstore_falseÚdefaultTz"Zip (rather than unzip) a package.z--no-pycÚno_pyczEDo not include .pyc files in zip files (useful on Google App Engine).z-lz--listÚlistz2List the packages available, and their zip status.z--sort-filesÚ
sort_fileszDWith --list, sort packages according to how many files they contain.z--pathÚappendÚpathsz?Restrict operations to the given paths (may include wildcards).z-nz
--simulatez0Do not actually perform the zip/unzip operation.r   )Úsuperr   Ú__init__ÚnameÚcmd_optsÚ
add_optionÚparserÚinsert_option_group)ÚselfÚargsÚkw)Ú	__class__© ú?/var/www/pythonscrapper/code/venv/build/pip/pip/commands/zip.pyr      sL    	
								zZipCommand.__init__c             C   sp  |  j  s t j Sg  } t ƒ  } xý t j D]ò } t j j t j j | ƒ ƒ } xË |  j  D]� } t j j t j j | ƒ ƒ } d | k rÇ t j t	 j
 | d ƒ | ƒ rô | j | ƒ | j | ƒ Pqô qW | j | ƒ rW | j | ƒ | j | ƒ PqW qW Wt j d | d j |  j  ƒ f ƒ q) WxJ |  j  D]? } | | k r)d | k r)| j | ƒ t j d | ƒ q)q)W| S)z:All the entries of sys.path, possibly restricted by --pathÚ*z,Skipping path %s because it doesn't match %sz, zDAdding path %s because it doesn't match anything already on sys.path)Úselect_pathsÚsysÚpathÚsetÚosÚnormcaseÚabspathÚreÚsearchÚfnmatchÚ	translater   ÚaddÚ
startswithr   ÚdebugÚjoin)r   ÚresultÚ	match_anyr&   Úmatchr!   r!   r"   r   >   s2    				zZipCommand.pathsc             C   sV  t  j d d ƒ | j |  _ | j |  _ | j rA |  j | | ƒ S| sV t d ƒ ‚ n  g  } x  | D]˜ } |  j | ƒ \ } } | j r² t	 j
 j | ƒ r² t d | | f ƒ ‚ n6 | j rè t	 j
 j | ƒ rè t d | | f ƒ ‚ n  | j | | f ƒ qc Wd  } xJ | D]B \ } } | j r6|  j | | ƒ } q|  j | | | j ƒ } qW| S)Nz1.7z_DEPRECATION: 'pip zip' and 'pip unzip` are deprecated, and will be removed in a future release.z2You must give at least one package to zip or unzipz;The module %s (in %s) is not a zip file; cannot be unzippedz:The module %s (in %s) is not a directory; cannot be zipped)r   Ú
deprecatedr   r$   Úsimulater   r   Úfind_packager   r(   r&   Úisdirr   Úunzip_packageÚzip_packager   )r   Úoptionsr   ÚpackagesÚargÚmodule_nameÚfilenameÚlast_statusr!   r!   r"   Úrun\   s4    		zZipCommand.runc             C   sÚ  t  j j | ƒ } t  j j | ƒ rP t j | ƒ rP t d | | | f ƒ ‚ n  t  j j | ƒ } | |  j ƒ  k r£ t j	 d t
 | ƒ t
 | ƒ t
 | ƒ f ƒ n  t j d | t
 | ƒ f ƒ |  j rÚ t j d ƒ d  St j d 7_ zÚt j | ƒ } g  } x| j ƒ  D]} | j } | j | t  j j ƒ rþ| j | ƒ }	 t  j j | | ƒ }
 t  j j t  j j |
 ƒ ƒ s”t  j t  j j |
 ƒ ƒ n  |	 rÕ|
 j t  j j ƒ rÕt  j j |
 ƒ sût  j |
 ƒ qûqt |
 d ƒ } | j |	 ƒ | j ƒ  q| j | | j | ƒ f ƒ qW| j ƒ  | sbt j d t
 | ƒ ƒ t  j | ƒ |  j | ƒ n` t j d | t
 | ƒ f ƒ t j | d	 ƒ } x$ | D] \ } }	 | j | |	 ƒ q˜W| j ƒ  Wd  t j d 8_ Xd  S)
Nz3Module %s (in %s) isn't located in a zip file in %sz/Unpacking %s into %s, but %s is not on sys.pathzUnzipping %s (in %s)z3Skipping remaining operations because of --simulateé   ÚwbzRemoving now-empty zip file %sz(Removing entries in %s/ from zip file %sÚw) r(   r&   ÚdirnameÚisfileÚzipfileÚ
is_zipfiler   r   r   Úwarnr   Únotifyr7   ÚindentÚZipFileÚinfolistr@   r0   ÚsepÚreadr2   ÚexistsÚmakedirsÚendswithÚopenÚwriteÚcloser   ÚinfoÚunlinkÚremove_filename_from_pthÚwritestr)r   r?   r@   Úzip_filenameÚpackage_pathr	   Úto_saverW   r   Úcontentr   Úfr!   r!   r"   r:   {   sX    "		 
zZipCommand.unzip_packagec             C   sN  | } t  j d | t | ƒ f ƒ t  j d 7_ | j d ƒ rJ | } n
 | d } zã| | k r¥ t | ƒ } t  j d | | f ƒ |  j s¥ t j | | ƒ q¥ n  yvt  j	 d t | ƒ ƒ |  j sít
 j | d ƒ } | j | d d	 ƒ xï t j | ƒ D]Þ \ } } }	 | r)d
 d „  |	 Dƒ }	 n  x° | d f |	 d f g D]– \ }
 } x‡ |
 D] } t j j | | ƒ } t j j | | t | ƒ d  … j t j j ƒ | ƒ } | rÄ| j | d d	 ƒ qU| j | | ƒ qUWqBWqþ W| j ƒ  n  t  j	 d t | ƒ ƒ |  j st | ƒ n  Wn ‚  Yn X|  j | ƒ Wd  t  j d 8_ Xd  S)NzZip %s (in %s)rC   z.eggz.zipzMoving %s aside to %szCreating zip file in %srE   ú/Ú c             S   s+   g  |  ]! } | j  ƒ  j d  ƒ s | ‘ q S)z.pyc)ÚlowerrS   )Ú.0r_   r!   r!   r"   ú
<listcomp>Ä   s   	 z*ZipCommand.zip_package.<locals>.<listcomp>TFzRemoving old directory %s)r   rK   r   rL   rS   r   r7   ÚshutilÚmoverW   rH   rM   rZ   r(   Úwalkr&   r2   ÚlenÚlstriprO   rU   rV   r   Úadd_filename_to_pth)r   r?   r@   r   Úorig_filenameÚdest_filenamer	   ÚdirpathÚdirnamesÚ	filenamesÚfnsÚis_dirÚfnÚfullr   r!   r!   r"   r;   ®   sF    	
		%7	zZipCommand.zip_packagec                s  xý |  j  ƒ  D]ï } t | d ƒ } | j ƒ  } | j ƒ  ‡  f d d †  | Dƒ } | | k r t j d t ˆ  ƒ t | ƒ f ƒ d d „  | Dƒ sÆ t j d t | ƒ ƒ |  j sø t j	 | ƒ qø n2 |  j sø t | d ƒ } | j
 | ƒ | j ƒ  n  d  Sq Wt j d t ˆ  ƒ ƒ d  S)	NÚrc                s(   g  |  ] } | j  ƒ  ˆ  k r | ‘ q Sr!   )Ústrip)rc   Úl)r@   r!   r"   rd   à   s   	 z7ZipCommand.remove_filename_from_pth.<locals>.<listcomp>z*Removing reference to %s from .pth file %sc             S   s   g  |  ] } | r | ‘ q Sr!   r!   )rc   Úliner!   r!   r"   rd   ä   s   	 z %s file would be empty: deletingrD   z.Cannot find a reference to %s in any .pth file)Ú	pth_filesrT   Ú	readlinesrV   r   rW   r   r7   r(   rX   Ú
writelinesrJ   )r   r@   Úpthr_   ÚlinesÚ	new_linesr!   )r@   r"   rY   Ú   s$    
			z#ZipCommand.remove_filename_from_pthc             C   sþ   t  j j | ƒ } | d } | |  j ƒ  k rH t j d t | ƒ ƒ n  |  j sú t  j j | ƒ rÄ t	 | ƒ } | j
 ƒ  } | j ƒ  | r° | d j d ƒ r° | d d 7<n  | j | d ƒ n | d g } t	 | d ƒ } | j | ƒ | j ƒ  n  d  S)Nz.pthz.Adding .pth file %s, but it is not on sys.pathé   Ú
rD   éÿÿÿÿr€   )r(   r&   rF   r   r   rJ   r   r7   rQ   rT   ry   rV   rS   r   rz   )r   r@   r&   r   r_   r|   r!   r!   r"   rj   ð   s     
	
zZipCommand.add_filename_to_pthc             c   s‡   x€ |  j  ƒ  D]r } t j j | ƒ s t j j | ƒ r? q n  x= t j | ƒ D], } | j d ƒ rO t j j | | ƒ VqO qO Wq Wd  S)Nz.pth)r   r(   r&   rQ   r9   ÚlistdirrS   r2   )r   r&   r@   r!   r!   r"   rx     s    &zZipCommand.pth_filesc             C   sæ   xÏ |  j  ƒ  D]Á } t j j | | ƒ } t j j | ƒ rD | | f St j j | ƒ r t j | ƒ r t j | d ƒ } y  | j	 t j j | d ƒ ƒ Wn t
 k
 r¬ Yn X| j ƒ  | | f S| j ƒ  q q Wt d | ƒ ‚ d  S)Nrt   z__init__.pyz!No package with the name %s found)r   r(   r&   r2   rQ   r9   rH   rI   rM   rP   ÚKeyErrorrV   r   )r   Úpackager&   rs   r	   r!   r!   r"   r8     s    
" 

zZipCommand.find_packagec             C   sD  | r t  d ƒ ‚ n  x(t |  j ƒ  ƒ D]} t j j | ƒ sF q( n  t j j | j t j j ƒ ƒ } t j j	 | ƒ rÆ t
 j | ƒ rÆ t j j | ƒ |  j ƒ  k r( t j d t | ƒ ƒ q( q( n  | d k r | d k r | j d d ƒ j d ƒ r q( n  t j d t | ƒ ƒ t j d	 7_ g  } g  } z÷xð t t j | ƒ ƒ D]Ù } t j j | ƒ d
 j ƒ  } | d k rqKn  | d k r¨t j d t | ƒ ƒ qKn  t j j | | ƒ }	 t j j |	 ƒ rî| j | |  j |	 ƒ f ƒ qKt
 j |	 ƒ r| j | ƒ qKt j d t | ƒ ƒ qKW| r‚t j d ƒ t j d	 7_ z" x | D] } t j | ƒ qTWWd  t j d	 8_ Xn t j d ƒ | r| j r·| j d d d „  ƒ n  t j d ƒ t j d	 7_ z2 x+ | D]# \ } }
 t j d | |
 f ƒ qÝWWd  t j d	 8_ Xn t j d ƒ Wd  t j d	 8_ Xq( Wd  S)Nz'You cannot give an argument with --listzZipped egg: %szsite-packageszdist-packagesú\r`   z
lib/pythonzIn %s:rC   r~   ú.pthú	.egg-infoú	.egg-linkz.pyz Not displaying %s: not a packagezUnknown file: %szZipped packages:zNo zipped packages.Úkeyc             S   s	   |  d S)Nr~   r!   )Úxr!   r!   r"   Ú<lambda>L  s    z!ZipCommand.list.<locals>.<lambda>zUnzipped packages:z%s  (%i files)zNo unzipped packages.)r…   r†   r‡   )r   Úsortedr   r(   r&   rQ   ÚbasenameÚrstriprO   rG   rH   rI   rF   r   rK   r   ÚreplacerS   rL   r�   Úsplitextrb   rW   r2   r9   r   Úcount_packager   Úsort)r   r<   r   r&   rŒ   ÚzippedÚunzippedr@   Úextrs   Úcountr!   r!   r"   r     sf    !!	zZipCommand.listc             C   sP   d } xC t  j | ƒ D]2 \ } } } d d „  | Dƒ } | t | ƒ 7} q W| S)Nr   c             S   s+   g  |  ]! } | j  ƒ  j d  ƒ s | ‘ q S)z.pyc)rb   rS   )rc   r_   r!   r!   r"   rd   \  s   	 z,ZipCommand.count_package.<locals>.<listcomp>)r(   rg   rh   )r   r&   Útotalrm   rn   ro   r!   r!   r"   r�   Y  s
    zZipCommand.count_package)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚusageÚsummaryr   r   rB   r:   r;   rY   rj   rx   r8   r   r�   r!   r!   )r    r"   r      s   *3,;r   )r%   r+   r-   r(   re   rH   Úpip.utilr   r   r   Úpip.logr   Úpip.exceptionsr   Úpip.basecommandr   r   r!   r!   r!   r"   Ú<module>   s   