ó
'šMc           @   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 e ƒ  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 RS(   t   zips    %prog [OPTIONS] PACKAGE_NAMES...s   Zip individual packagesc      
   C   s  t  t |  ƒ j ƒ  |  j d k rG |  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 ƒd  S(   NR   s   --unzipt   actiont
   store_truet   destt   unzipt   helps!   Unzip (rather than zip) a packages   --zipt   store_falset   defaults!   Zip (rather than unzip) a packages   --no-pyct   no_pycsD   Do not include .pyc files in zip files (useful on Google App Engine)s   -ls   --listt   lists1   List the packages available, and their zip statuss   --sort-filest
   sort_filessC   With --list, sort packages according to how many files they contains   --patht   appendt   pathss>   Restrict operations to the given paths (may include wildcards)s   -ns
   --simulates/   Do not actually perform the zip/unzip operation(   t   superR   t   __init__t   namet   parsert
   add_optiont   True(   t   self(    (    s4   /usr/lib/python2.7/dist-packages/pip/commands/zip.pyR      sJ    	
								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(    (    s4   /usr/lib/python2.7/dist-packages/pip/commands/zip.pyR   :   s2    				c         C   sF  | j  |  _ | j |  _ | j r1 |  j | | ƒ S| sF 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 ƒ qS Wd  } xJ | D]B \ } } | j r&|  j | | ƒ } qü |  j | | | j ƒ } qü W| S(   Ns2   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   R   t   simulateR   R   t   find_packageR   R    R   t   isdirR   t   Nonet   unzip_packaget   zip_packageR   (   R   t   optionst   argst   packagest   argt   module_namet   filenamet   last_status(    (    s4   /usr/lib/python2.7/dist-packages/pip/commands/zip.pyt   runX   s2    		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 | 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 ƒ  | sY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   notifyR.   t   indentt   ZipFilet   namelistR(   t   sept   readR*   t   existst   makedirst   endswitht   opent   writet   closeR   t   infot   unlinkt   remove_filename_from_ptht   writestr(   R   R8   R9   t   zip_filenamet   package_pathR   t   to_saveR   t   contentR
   t   f(    (    s4   /usr/lib/python2.7/dist-packages/pip/commands/zip.pyR2   t   sV    "	 
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 %sR=   t   /t    s   .pycs   Removing old directory %s(   R   RC   R    RD   RK   R   R.   t   shutilt   moveRO   R@   RE   RR   R    t   walkt   lowerR   t   FalseR   R*   t   lent   lstripRG   RM   RN   R   t   add_filename_to_pth(   R   R8   R9   R   t   orig_filenamet   dest_filenameR   t   dirpatht   dirnamest	   filenamesRW   t   fnst   is_dirt   fnt   fullR
   (    (    s4   /usr/lib/python2.7/dist-packages/pip/commands/zip.pyR3   ¦   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_filesRL   t	   readlinesRN   t   stripR   RO   R    R.   R    RP   t
   writelinesRB   (   R   R9   t   pthRW   t   linest   lt	   new_linest   line(    (    s4   /usr/lib/python2.7/dist-packages/pip/commands/zip.pyRQ   Ò   s$    
+			c         C   s  t  j j | ƒ } t  j j | | d ƒ } | |  j ƒ  k rW 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   R>   R*   R   R   RB   R    R.   RI   RL   Rm   RN   RK   R   Ro   (   R   R9   R   R
   RW   Rq   (    (    s4   /usr/lib/python2.7/dist-packages/pip/commands/zip.pyRa   è   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   RI   R0   t   listdirRK   R*   (   R   R   R9   (    (    s4   /usr/lib/python2.7/dist-packages/pip/commands/zip.pyRl   û   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(   NRk   s   __init__.pys!   No package with the name %s found(   R   R    R   R*   RI   R0   R@   RA   RE   RH   t   KeyErrorRN   R   (   R   t   packageR   Rj   R   (    (    s4   /usr/lib/python2.7/dist-packages/pip/commands/zip.pyR/     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   \RX   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(    (    s4   /usr/lib/python2.7/dist-packages/pip/commands/zip.pyt   <lambda>D  s    s   Unzipped packages:s   %s  (%i files)s   No unzipped packages.(   s   .pths	   .egg-infos	   .egg-link(   R   t   sortedR   R    R   RI   t   basenamet   rstripRG   R?   R@   RA   R>   R   RC   R    t   replaceRK   RD   Ru   t   splitextR]   RO   R*   R0   R   t   count_packageR   t   sort(   R   R4   R5   R   R|   t   zippedt   unzippedR9   t   extRj   t   count(    (    s4   /usr/lib/python2.7/dist-packages/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\   R]   RK   R_   (   R   R   t   totalRd   Re   Rf   RW   (    (    s4   /usr/lib/python2.7/dist-packages/pip/commands/zip.pyR€   Q  s    !(   t   __name__t
   __module__R   t   usaget   summaryR   R   R;   R2   R3   RQ   Ra   Rl   R/   R   R€   (    (    (    s4   /usr/lib/python2.7/dist-packages/pip/commands/zip.pyR      s   	(			2	,					;(   R   R#   R%   R    RZ   R@   t   pip.utilR    R   R   t   pip.logR   t   pip.exceptionsR   t   pip.basecommandR   R   (    (    (    s4   /usr/lib/python2.7/dist-packages/pip/commands/zip.pyt   <module>   s   ÿ N