î
É XÉ  ã               @   sñ   d  Z  d d d d d d d g 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 d d l	 m
 Z
 Gd d „  d e
 ƒ Z d d „  Z e d	 d d „ Z e d d „ Z e d d „ Z e d d „ Z e e e f Z d	 S)z/Utilities for extracting common archive formatsÚunpack_archiveÚunpack_zipfileÚunpack_tarfileÚdefault_filterÚUnrecognizedFormatÚextraction_driversÚunpack_directoryé    N)Úensure_directory)ÚDistutilsErrorc               @   s   e  Z d  Z d Z d S)r   z#Couldn't recognize the archive typeN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__© r   r   úI/home/ubuntu/projects/ifolica/build/setuptools/setuptools/archive_util.pyr      s   c             C   s   | S)z@The default progress/filter callback; returns True for all filesr   )ÚsrcÚdstr   r   r   r      s    c             C   s[   xT | p t  D]6 } y | |  | | ƒ Wn t k
 r> w Yq Xd Sq Wt d |  ƒ ‚ d S)a¡  Unpack `filename` to `extract_dir`, or raise ``UnrecognizedFormat``

    `progress_filter` is a function taking two arguments: a source path
    internal to the archive ('/'-separated), and a filesystem path where it
    will be extracted.  The callback must return the desired extract path
    (which may be the same as the one passed in), or else ``None`` to skip
    that file or directory.  The callback can thus be used to report on the
    progress of the extraction, as well as to filter the items extracted or
    alter their extraction paths.

    `drivers`, if supplied, must be a non-empty sequence of functions with the
    same signature as this function (minus the `drivers` argument), that raise
    ``UnrecognizedFormat`` if they do not support extracting the designated
    archive type.  The `drivers` are tried in sequence until one is found that
    does not raise an error, or until all are exhausted (in which case
    ``UnrecognizedFormat`` is raised).  If you do not supply a sequence of
    drivers, the module's ``extraction_drivers`` constant will be used, which
    means that ``unpack_zipfile`` and ``unpack_tarfile`` will be tried, in that
    order.
    Nz!Not a recognized archive type: %s)r   r   )ÚfilenameÚextract_dirÚprogress_filterZdriversZdriverr   r   r   r   *   s    c             C   sG  t  j j |  ƒ s( t d |  f ƒ ‚ n  i d | f |  6} xt  j |  ƒ D]ô \ } } } | | \ } } xD | D]< }	 | |	 d t  j j | |	 ƒ f | t  j j | |	 ƒ <qq Wx‹ | D]ƒ }
 | |
 } t  j j | |
 ƒ } | | |
 | ƒ } | sü q¸ n  t | ƒ t  j j | |
 ƒ }
 t j |
 | ƒ t j	 |
 | ƒ q¸ WqK Wd S)z‡"Unpack" a directory, using the same interface as for archives

    Raises ``UnrecognizedFormat`` if `filename` is not a directory
    z%s is not a directoryÚ ú/N)
ÚosÚpathÚisdirr   ÚwalkÚjoinr	   ÚshutilÚcopyfileÚcopystat)r   r   r   ÚpathsÚbaseÚdirsÚfilesr   r   ÚdÚfÚnameÚtargetr   r   r   r   S   s"    :

c       
      C   s\  t  j |  ƒ s% t d |  f ƒ ‚ n  t  j |  ƒ } zx| j ƒ  D]} | j } | j d ƒ sD d | j d ƒ k r} qD n  t j	 j
 | | j d ƒ Œ } | | | ƒ } | s¶ qD n  | j d ƒ rÒ t | ƒ nM t | ƒ | j | j ƒ } t | d ƒ } z | j | ƒ Wd | j ƒ  ~ X| j d ?}	 |	 rD t j | |	 ƒ qD qD WWd | j ƒ  Xd S)zòUnpack zip `filename` to `extract_dir`

    Raises ``UnrecognizedFormat`` if `filename` is not a zipfile (as determined
    by ``zipfile.is_zipfile()``).  See ``unpack_archive()`` for an explanation
    of the `progress_filter` argument.
    z%s is not a zip filer   z..ÚwbNé   )ÚzipfileÚ
is_zipfiler   ÚZipFileÚinfolistr   Ú
startswithÚsplitr   r   r   Úendswithr	   ÚreadÚopenÚwriteÚcloseÚexternal_attrÚchmod)
r   r   r   ÚzÚinfor&   r'   Údatar%   Zunix_attributesr   r   r   r   |   s2    	$

c       	      C   sÖ  y t  j |  ƒ } Wn( t  j k
 r= t d |  f ƒ ‚ Yn Xz†d d „  | _ xl| D]d} | j } | j d ƒ rW d | j d ƒ k rW t j	 j
 | | j d ƒ Œ } x| | d k	 r'| j ƒ  sÐ | j ƒ  r'| j } | j ƒ  rt j
 t j | j ƒ | ƒ } t j | ƒ } n  | j | ƒ } q¬ W| d k	 r»| j ƒ  sL| j ƒ  r»| | | ƒ } | r¸| j t j ƒ r†| d d	 … } n  y | j | | ƒ Wqµt  j k
 r±YqµXq¸q»qW qW Wd SWd | j ƒ  Xd S)
zûUnpack tar/tar.gz/tar.bz2 `filename` to `extract_dir`

    Raises ``UnrecognizedFormat`` if `filename` is not a tarfile (as determined
    by ``tarfile.open()``).  See ``unpack_archive()`` for an explanation
    of the `progress_filter` argument.
    z/%s is not a compressed or uncompressed tar filec              W   s   d  S)Nr   )Úargsr   r   r   Ú<lambda>¶   s    z unpack_tarfile.<locals>.<lambda>r   z..Né   Téÿÿÿÿ)Útarfiler2   ÚTarErrorr   Úchownr&   r.   r/   r   r   r   ÚislnkÚissymÚlinknameÚ	posixpathÚdirnameÚnormpathÚ
_getmemberÚisfiler   r0   ÚsepÚ_extract_memberÚExtractErrorr4   )	r   r   r   ÚtarobjÚmemberr&   Z
prelim_dstÚlinkpathZ	final_dstr   r   r   r   ¨   s8    	%'	$)r   Ú__all__r*   r>   r   r   rD   Úpkg_resourcesr	   Údistutils.errorsr
   r   r   r   r   r   r   r   r   r   r   r   Ú<module>   s   <(),*