ó
è¾bc           @   s§   d  Z  d Z d d l Z d d l Z d d l Z d d l m Z d d l m Z m	 Z	 d d l
 m Z d d d „  ƒ  YZ e j d	 „ Z d
 „  Z d d d d „ Z d S(   ss   distutils.filelist

Provides the FileList class, used for poking about the filesystem
and building lists of files.
s   $Id$iÿÿÿÿN(   t   convert_path(   t   DistutilsTemplateErrort   DistutilsInternalError(   t   logt   FileListc           B   s˜   e  Z d  Z d d d „ Z d „  Z e j d „ Z d „  Z	 d „  Z
 d „  Z d „  Z d „  Z d	 „  Z d
 „  Z d d d d „ Z d d d d „ Z RS(   sÑ  A list of files built by on exploring the filesystem and filtered by
    applying various patterns to what we find there.

    Instance attributes:
      dir
        directory from which files will be taken -- only used if
        'allfiles' not supplied to constructor
      files
        list of filenames currently being built/filtered/manipulated
      allfiles
        complete list of files under consideration (ie. without any
        filtering applied)
    c         C   s   d  |  _ g  |  _ d  S(   N(   t   Nonet   allfilest   files(   t   selft   warnt   debug_print(    (    s(   /usr/lib/python2.7/distutils/filelist.pyt   __init__   s    	c         C   s   | |  _  d  S(   N(   R   (   R   R   (    (    s(   /usr/lib/python2.7/distutils/filelist.pyt   set_allfiles$   s    c         C   s   t  | ƒ |  _ d  S(   N(   t   findallR   (   R   t   dir(    (    s(   /usr/lib/python2.7/distutils/filelist.pyR   '   s    c         C   s"   d d l  m } | r | GHn  d S(   s~   Print 'msg' to stdout if the global DEBUG (taken from the
        DISTUTILS_DEBUG environment variable) flag is true.
        iÿÿÿÿ(   t   DEBUGN(   t   distutils.debugR   (   R   t   msgR   (    (    s(   /usr/lib/python2.7/distutils/filelist.pyR
   *   s    c         C   s   |  j  j | ƒ d  S(   N(   R   t   append(   R   t   item(    (    s(   /usr/lib/python2.7/distutils/filelist.pyR   4   s    c         C   s   |  j  j | ƒ d  S(   N(   R   t   extend(   R   t   items(    (    s(   /usr/lib/python2.7/distutils/filelist.pyR   7   s    c         C   s\   t  t j j |  j ƒ } | j ƒ  g  |  _ x* | D]" } |  j j t j j | Œ  ƒ q2 Wd  S(   N(   t   mapt   ost   patht   splitR   t   sortR   t   join(   R   t   sortable_filest
   sort_tuple(    (    s(   /usr/lib/python2.7/distutils/filelist.pyR   :   s
    
	c         C   sY   xR t  t |  j ƒ d d d ƒ D]1 } |  j | |  j | d k r  |  j | =q  q  Wd  S(   Ni   i    iÿÿÿÿ(   t   ranget   lenR   (   R   t   i(    (    s(   /usr/lib/python2.7/distutils/filelist.pyt   remove_duplicatesE   s    &c         C   s  | j  ƒ  } | d } d  } } } | d k rh t | ƒ d k  rR t d | ‚ n  t t | d ƒ } n¢ | d k r¼ t | ƒ d k  r– t d | ‚ n  t | d ƒ } t t | d ƒ } nN | d k rý t | ƒ d k rê t d | ‚ n  t | d ƒ } n t d | ‚ | | | | f S(   Ni    t   includet   excludes   global-includes   global-excludei   s&   '%s' expects <pattern1> <pattern2> ...i   s   recursive-includes   recursive-excludei   s,   '%s' expects <dir> <pattern1> <pattern2> ...t   graftt   prunes#   '%s' expects a single <dir_pattern>s   unknown action '%s'(   R"   R#   s   global-includes   global-exclude(   s   recursive-includes   recursive-exclude(   R$   R%   (   R   R   R   R   R   R    (   R   t   linet   wordst   actiont   patternsR   t   dir_pattern(    (    s(   /usr/lib/python2.7/distutils/filelist.pyt   _parse_template_lineN   s,    
	c         C   s&  |  j  | ƒ \ } } } } | d k r} |  j d d j | ƒ ƒ xÞ| D]. } |  j | d d ƒsH t j d | ƒ qH qH Wn¥| d k rß |  j d d j | ƒ ƒ x|| D]. } |  j | d d ƒsª t j d	 | ƒ qª qª WnC| d
 k rE|  j d d j | ƒ ƒ x| D]2 } |  j | d d ƒst j d d | ƒ qqWnÝ| d k r§|  j d d j | ƒ ƒ x´| D]. } |  j | d d ƒsrt j d | ƒ qrqrWn{| d k r|  j d | d j | ƒ f ƒ xL| D]5 } |  j | d | ƒsÚt j d d | | ƒ qÚqÚWn| d k r|  j d | d j | ƒ f ƒ xÝ | D]1 } |  j | d | ƒsIt j d | | ƒ qIqIWn¡ | d k rÉ|  j d | ƒ |  j d  d | ƒs"t j d | ƒ q"nY | d k r|  j d | ƒ |  j d  d | ƒs"t j d d | ƒ q"n t d  | ‚ d  S(!   NR"   s   include t    t   anchori   s%   warning: no files found matching '%s'R#   s   exclude s9   warning: no previously-included files found matching '%s's   global-includes   global-include i    s&   warning: no files found matching '%s' s   anywhere in distributions   global-excludes   global-exclude sR   warning: no previously-included files matching '%s' found anywhere in distributions   recursive-includes   recursive-include %s %st   prefixs   under directory '%s's   recursive-excludes   recursive-exclude %s %ssN   warning: no previously-included files matching '%s' found under directory '%s'R$   s   graft s+   warning: no directories found matching '%s'R%   s   prune s)   no previously-included directories found s   matching '%s's'   this cannot happen: invalid action '%s'(	   R+   R
   R   t   include_patternR   R	   t   exclude_patternR   R   (   R   R&   R(   R)   R   R*   t   pattern(    (    s(   /usr/lib/python2.7/distutils/filelist.pyt   process_template_linep   sh    										i   i    c         C   sœ   d } t  | | | | ƒ } |  j d | j ƒ |  j d k rK |  j ƒ  n  xJ |  j D]? } | j | ƒ rU |  j d | ƒ |  j j | ƒ d } qU qU W| S(   s‚  Select strings (presumably filenames) from 'self.files' that
        match 'pattern', a Unix-style wildcard (glob) pattern.

        Patterns are not quite the same as implemented by the 'fnmatch'
        module: '*' and '?'  match non-special characters, where "special"
        is platform-dependent: slash on Unix; colon, slash, and backslash on
        DOS/Windows; and colon on Mac OS.

        If 'anchor' is true (the default), then the pattern match is more
        stringent: "*.py" will match "foo.py" but not "foo/bar.py".  If
        'anchor' is false, both of these will match.

        If 'prefix' is supplied, then only filenames starting with 'prefix'
        (itself a pattern) and ending with 'pattern', with anything in between
        them, will match.  'anchor' is ignored in this case.

        If 'is_regex' is true, 'anchor' and 'prefix' are ignored, and
        'pattern' is assumed to be either a string containing a regex or a
        regex object -- no translation is done, the regex is just compiled
        and used as-is.

        Selected strings will be added to self.files.

        Return 1 if files are found.
        i    s%   include_pattern: applying regex r'%s's    adding i   N(	   t   translate_patternR
   R1   R   R   R   t   searchR   R   (   R   R1   R-   R.   t   is_regext   files_foundt
   pattern_ret   name(    (    s(   /usr/lib/python2.7/distutils/filelist.pyR/   »   s    	c         C   sž   d } t  | | | | ƒ } |  j d | j ƒ xh t t |  j ƒ d d d ƒ D]G } | j |  j | ƒ rO |  j d |  j | ƒ |  j | =d } qO qO W| S(   sü   Remove strings (presumably filenames) from 'files' that match
        'pattern'.

        Other parameters are the same as for 'include_pattern()', above.
        The list 'self.files' is modified in place. Return 1 if files are
        found.
        i    s%   exclude_pattern: applying regex r'%s'i   iÿÿÿÿs
    removing (   R3   R
   R1   R   R   R   R4   (   R   R1   R-   R.   R5   R6   R7   R    (    (    s(   /usr/lib/python2.7/distutils/filelist.pyR0   è   s    	&
N(   t   __name__t
   __module__t   __doc__R   R   R   R   t   curdirR   R
   R   R   R   R!   R+   R2   R/   R0   (    (    (    s(   /usr/lib/python2.7/distutils/filelist.pyR      s   		
						"	K-c         C   s  d d l  m } m } m } m } g  } |  g } | j } | j } x» | r | ƒ  }  t j |  ƒ }	 x– |	 D]Ž }
 |  t j	 k r˜ t j
 j |  |
 ƒ } n |
 } t j  | ƒ } | | } | | ƒ rÓ | j | ƒ qk | | ƒ rk | | ƒ rk | | ƒ qk qk WqF W| S(   s^   Find all files under 'dir' and return the list of full filenames
    (relative to 'dir').
    iÿÿÿÿ(   t   ST_MODEt   S_ISREGt   S_ISDIRt   S_ISLNK(   t   statR=   R>   R?   R@   t   popR   R   t   listdirR<   R   R   (   R   R=   R>   R?   R@   t   listt   stackRB   t   pusht   namesR8   t   fullnameRA   t   mode(    (    s(   /usr/lib/python2.7/distutils/filelist.pyR      s&    "					
c         C   sS   t  j |  ƒ } t j } t j d k r0 d } n  d | } t j d | | ƒ } | S(   sç   Translate a shell-like glob pattern to a regular expression.

    Return a string containing the regex.  Differs from
    'fnmatch.translate()' in that '*' does not match "special characters"
    (which are platform-specific).
    s   \s   \\\\s   \1[^%s]s   ((?<!\\)(\\\\)*)\.(   t   fnmatcht	   translateR   t   sept   ret   sub(   R1   R7   RL   t   escaped(    (    s(   /usr/lib/python2.7/distutils/filelist.pyt
   glob_to_re   s    		
i   i    c         C   sÔ   | r) t  |  t ƒ r" t j |  ƒ S|  Sn  |  r> t |  ƒ } n d } | d k	 r´ t d ƒ } t | ƒ t | ƒ  } t j } t j d k r” d } n  d | j	 | d | f ƒ } n | rÇ d | } n  t j | ƒ S(   s  Translate a shell-like wildcard pattern to a compiled regular
    expression.

    Return the compiled regex.  If 'is_regex' true,
    then 'pattern' is directly compiled to a regex (if it's a string)
    or just returned as-is (assumes it's a regex object).
    t    s   \s   \\t   ^s   .*N(
   t
   isinstancet   strRM   t   compileRP   R   R   R   RL   R   (   R1   R-   R.   R5   R7   t   empty_patternt	   prefix_reRL   (    (    s(   /usr/lib/python2.7/distutils/filelist.pyR3   8  s"    		 (    (   R;   t   __revision__R   RM   RJ   t   distutils.utilR    t   distutils.errorsR   R   t	   distutilsR   R   R<   R   RP   R   R3   (    (    (    s(   /usr/lib/python2.7/distutils/filelist.pyt   <module>   s   ñ 	