ó
^\kdc           @   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 d e f d „  ƒ  YZ d S(   iÿÿÿÿN(   t   display_patht
   backup_dirt   rmtree(   t   logger(   t   InstallationError(   t   Commandt
   ZipCommandc           B   sƒ   e  Z d  Z d Z d Z d Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z RS(   s   Zip individual packages.t   zips#   
     %prog [options] <package> ...s$   DEPRECATED. Zip individual packages.c      
   O   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 t 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   s   --unzipt   actiont
   store_truet   destt   unzipt   helps"   Unzip (rather than zip) a package.s   --zipt   store_falset   defaults"   Zip (rather than unzip) a package.s   --no-pyct   no_pycsE   Do not include .pyc files in zip files (useful on Google App Engine).s   -ls   --listt   lists2   List the packages available, and their zip status.s   --sort-filest
   sort_filessD   With --list, sort packages according to how many files they contain.s   --patht   appendt   pathss?   Restrict operations to the given paths (may include wildcards).s   -ns
   --simulates0   Do not actually perform the zip/unzip operation.i    (	   t   superR   t   __init__t   namet   cmd_optst
   add_optiont   Truet   parsert   insert_option_group(   t   selft   argst   kw(    (    s7   /var/www/testScraper/venv/build/pip/pip/commands/zip.pyR      sL    	
								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(   s:   All the entries of sys.path, possibly restricted by --patht   *s,   Skipping path %s because it doesn't match %ss   , sD   Adding path %s because it doesn't match anything already on sys.path(   t   select_pathst   syst   patht   sett   ost   normcaset   abspatht   ret   searcht   fnmatcht	   translateR   t   addt
   startswithR   t   debugt   join(   R   t   resultt	   match_anyR"   t   match(    (    s7   /var/www/testScraper/venv/build/pip/pip/commands/zip.pyR   >   s2    				c         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(   Ns   1.7s_   DEPRECATION: 'pip zip' and 'pip unzip` are deprecated, and will be removed in a future release.s2   You must give at least one package to zip or unzips;   The module %s (in %s) is not a zip file; cannot be unzippeds:   The module %s (in %s) is not a directory; cannot be zipped(   R   t
   deprecatedR   R    t   simulateR   R   t   find_packageR   R$   R"   t   isdirR   t   Nonet   unzip_packaget   zip_packageR   (   R   t   optionsR   t   packagest   argt   module_namet   filenamet   last_status(    (    s7   /var/www/testScraper/venv/build/pip/pip/commands/zip.pyt   run\   s4    		c         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(
   Ns3   Module %s (in %s) isn't located in a zip file in %ss/   Unpacking %s into %s, but %s is not on sys.paths   Unzipping %s (in %s)s3   Skipping remaining operations because of --simulatei   t   wbs   Removing now-empty zip file %ss(   Removing entries in %s/ from zip file %st   w(    R$   R"   t   dirnamet   isfilet   zipfilet
   is_zipfileR   R   R   t   warnR    t   notifyR3   t   indentt   ZipFilet   infolistR=   R,   t   sept   readR.   t   existst   makedirst   endswitht   opent   writet   closeR   t   infot   unlinkt   remove_filename_from_ptht   writestr(   R   R<   R=   t   zip_filenamet   package_pathR   t   to_saveRS   R   t   contentR
   t   f(    (    s7   /var/www/testScraper/venv/build/pip/pip/commands/zip.pyR7   {   sX    "		 
c         C   sb  | } 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  y‹t  j	 d t | ƒ ƒ |  j st
 j | d ƒ } | j | d d	 ƒ xt j | ƒ D]ó \ } } }	 | rDg  |	 D]! }
 |
 j ƒ  j d
 ƒ s|
 ^ q}	 n  xª | t f |	 t f g D]� \ } } x� | D]y } t j j | | ƒ } t j j | | t | ƒ j t j j ƒ | ƒ } | rÙ| j | d d	 ƒ qp| j | | ƒ qpWq]Wqþ W| j ƒ  n  t  j	 d t | ƒ ƒ |  j s/t | ƒ n  Wn
 ‚  n X|  j | ƒ Wd  t  j d 8_ Xd  S(   Ns   Zip %s (in %s)i   s   .eggs   .zips   Moving %s aside to %ss   Creating zip file in %sRA   t   /t    s   .pycs   Removing old directory %s(   R   RG   R    RH   RO   R   R3   t   shutilt   moveRS   RD   RI   RV   R$   t   walkt   lowerR   t   FalseR"   R.   t   lent   lstripRK   RQ   RR   R   t   add_filename_to_pth(   R   R<   R=   R   t   orig_filenamet   dest_filenameR   t   dirpatht   dirnamest	   filenamesR[   t   fnst   is_dirt   fnt   fullR
   (    (    s7   /var/www/testScraper/venv/build/pip/pip/commands/zip.pyR8   ®   sH    	
		$%1	c         C   s9  x|  j  ƒ  D]} t | d ƒ } | j ƒ  } | j ƒ  g  | D] } | j ƒ  | k r? | ^ q? } | | k r t j d t | ƒ t | ƒ f ƒ g  | D] } | r™ | ^ q™ 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(   Nt   rs*   Removing reference to %s from .pth file %ss    %s file would be empty: deletingR@   s.   Cannot find a reference to %s in any .pth file(   t	   pth_filesRP   t	   readlinesRR   t   stripR   RS   R    R3   R$   RT   t
   writelinesRF   (   R   R=   t   pthR[   t   linest   lt	   new_linest   line(    (    s7   /var/www/testScraper/venv/build/pip/pip/commands/zip.pyRU   Ú   s$    
+			c         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 c d 7<n  | j | d ƒ n | d g } t	 | d ƒ } | j | ƒ | j ƒ  n  d  S(   Ns   .pths.   Adding .pth file %s, but it is not on sys.pathiÿÿÿÿs   
R@   (   R$   R"   RB   R   R   RF   R    R3   RM   RP   Rq   RR   RO   R   Rs   (   R   R=   R"   R
   R[   Ru   (    (    s7   /var/www/testScraper/venv/build/pip/pip/commands/zip.pyRe   ð   s     
	
c         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(   Ns   .pth(   R   R$   R"   RM   R5   t   listdirRO   R.   (   R   R"   R=   (    (    s7   /var/www/testScraper/venv/build/pip/pip/commands/zip.pyRp     s    &c         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« n X| j ƒ  | | f S| j ƒ  q q Wt d | ƒ ‚ d  S(   NRo   s   __init__.pys!   No package with the name %s found(   R   R$   R"   R.   RM   R5   RD   RE   RI   RL   t   KeyErrorRR   R   (   R   t   packageR"   Rn   R   (    (    s7   /var/www/testScraper/venv/build/pip/pip/commands/zip.pyR4     s    
" 

c      
   C   sA  | 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 „  ƒ 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(   Ns'   You cannot give an argument with --lists   Zipped egg: %ss   site-packagess   dist-packagess   \R\   s
   lib/pythons   In %s:i   i   s   .pths	   .egg-infos	   .egg-links   .pys    Not displaying %s: not a packages   Unknown file: %ss   Zipped packages:s   No zipped packages.t   keyc         S   s	   |  d S(   Ni   (    (   t   x(    (    s7   /var/www/testScraper/venv/build/pip/pip/commands/zip.pyt   <lambda>L  s    s   Unzipped packages:s   %s  (%i files)s   No unzipped packages.(   s   .pths	   .egg-infos	   .egg-link(   R   t   sortedR   R$   R"   RM   t   basenamet   rstripRK   RC   RD   RE   RB   R   RG   R    t   replaceRO   RH   Ry   t   splitextRa   RS   R.   R5   R   t   count_packageR   t   sort(   R   R9   R   R"   R€   t   zippedt   unzippedR=   t   extRn   t   count(    (    s7   /var/www/testScraper/venv/build/pip/pip/commands/zip.pyR     sf    !!	c         C   sk   d } x^ t  j | ƒ D]M \ } } } g  | D]! } | j ƒ  j d ƒ s, | ^ q, } | t | ƒ 7} q W| S(   Ni    s   .pyc(   R$   R`   Ra   RO   Rc   (   R   R"   t   totalRh   Ri   Rj   R[   (    (    s7   /var/www/testScraper/venv/build/pip/pip/commands/zip.pyR„   Y  s    !(   t   __name__t
   __module__t   __doc__R   t   usaget   summaryR   R   R?   R7   R8   RU   Re   Rp   R4   R   R„   (    (    (    s7   /var/www/testScraper/venv/build/pip/pip/commands/zip.pyR      s   	*			3	,					;(   R!   R'   R)   R$   R^   RD   t   pip.utilR    R   R   t   pip.logR   t   pip.exceptionsR   t   pip.basecommandR   R   (    (    (    s7   /var/www/testScraper/venv/build/pip/pip/commands/zip.pyt   <module>   s   