;
Ñâ"Ic            
   @   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 Gd „  d ƒ Z e j d	 „ Z d
 „  Z d d d d „ Z d S(   us   distutils.filelist

Provides the FileList class, used for poking about the filesystem
and building lists of files.
u@   $Id: filelist.py 65250 2008-07-26 20:09:45Z amaury.forgeotdarc $i    N(   u   convert_path(   u   DistutilsTemplateErroru   DistutilsInternalError(   u   logc             B   sž   |  Ee  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 d S(   uÑ  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(   u   Noneu   allfilesu   files(   u   selfu   warnu   debug_print(    (    u/   /mit/python/lib/python3.0/distutils/filelist.pyu   __init__   s    	c             C   s   | |  _  d  S(   N(   u   allfiles(   u   selfu   allfiles(    (    u/   /mit/python/lib/python3.0/distutils/filelist.pyu   set_allfiles$   s    c             C   s   t  | ƒ |  _ d  S(   N(   u   findallu   allfiles(   u   selfu   dir(    (    u/   /mit/python/lib/python3.0/distutils/filelist.pyu   findall'   s    c             C   s)   d d l  m } | o t | ƒ n d S(   u~   Print 'msg' to stdout if the global DEBUG (taken from the
        DISTUTILS_DEBUG environment variable) flag is true.
        i    (   u   DEBUGN(   u   distutils.debugu   DEBUGu   print(   u   selfu   msgu   DEBUG(    (    u/   /mit/python/lib/python3.0/distutils/filelist.pyu   debug_print*   s    c             C   s   |  j  j | ƒ d  S(   N(   u   filesu   append(   u   selfu   item(    (    u/   /mit/python/lib/python3.0/distutils/filelist.pyu   append4   s    c             C   s   |  j  j | ƒ d  S(   N(   u   filesu   extend(   u   selfu   items(    (    u/   /mit/python/lib/python3.0/distutils/filelist.pyu   extend7   s    c             C   sX   t  t t j j |  j ƒ ƒ } g  |  _ x* | D]" } |  j j t j j | Œ  ƒ q. Wd  S(   N(   u   sortedu   mapu   osu   pathu   splitu   filesu   appendu   join(   u   selfu   sortable_filesu
   sort_tuple(    (    u/   /mit/python/lib/python3.0/distutils/filelist.pyu   sort:   s
    	 c             C   s[   xT t  t |  j ƒ d d d ƒ D]3 } |  j | |  j | d k o |  j | =q  q  Wd  S(   Ni   i    iÿÿÿÿ(   u   rangeu   lenu   files(   u   selfu   i(    (    u/   /mit/python/lib/python3.0/distutils/filelist.pyu   remove_duplicatesD   s      c             C   s@  | j  ƒ  } | d } d  } } } | d k oE t | ƒ d k  o t d | ƒ ‚ n d „  | d	 d  … Dƒ } n» | d k oU t | ƒ d k  o t d | ƒ ‚ n t | d	 ƒ } d „  | d d  … Dƒ } nY | d k o; t | ƒ d k o t d | ƒ ‚ n t | d	 ƒ } n t d | ƒ ‚ | | | | f S(   Ni    u   includeu   excludeu   global-includeu   global-excludei   u&   '%s' expects <pattern1> <pattern2> ...c             S   s!   g  } |  ] } | t  | ƒ q
 S(    (   u   convert_path(   u   .0u   _[1]u   w(    (    u/   /mit/python/lib/python3.0/distutils/filelist.pyu
   <listcomp>X   s    i   u   recursive-includeu   recursive-excludei   u,   '%s' expects <dir> <pattern1> <pattern2> ...c             S   s!   g  } |  ] } | t  | ƒ q
 S(    (   u   convert_path(   u   .0u   _[1]u   w(    (    u/   /mit/python/lib/python3.0/distutils/filelist.pyu
   <listcomp>^   s    u   graftu   pruneu#   '%s' expects a single <dir_pattern>u   unknown action '%s'(   u   includeu   excludeu   global-includeu   global-exclude(   u   recursive-includeu   recursive-exclude(   u   graftu   prune(   u   splitu   Noneu   lenu   DistutilsTemplateErroru   convert_path(   u   selfu   lineu   wordsu   actionu   patternsu   diru   dir_pattern(    (    u/   /mit/python/lib/python3.0/distutils/filelist.pyu   _parse_template_lineM   s,    

c             C   s=  |  j  | ƒ \ } } } } | d k oY |  j d d j | ƒ ƒ xô| D]0 } |  j | d d ƒp t j d | ƒ qI qI Wn¹| d k oY |  j d d j | ƒ ƒ xŽ| D]0 } |  j | d d ƒp t j d	 | ƒ q¯ q¯ WnS| d
 k oY |  j d d j | ƒ ƒ x(| D]0 } |  j | d d ƒp t j d | ƒ qqWní| d k oY |  j d d j | ƒ ƒ xÂ| D]0 } |  j | d d ƒp t j d | ƒ q{q{Wn‡| d k ob |  j d | d j | ƒ f ƒ xV| D]3 } |  j | d | ƒp t j d | | ƒ qçqçWn| d k ob |  j d | d j | ƒ f ƒ xç | D]3 } |  j | d | ƒp t j d | | ƒ qVqVWn© | d k o? |  j d | ƒ |  j d  d | ƒp t j d | ƒ q9n] | d k o? |  j d | ƒ |  j d  d | ƒp t j d | ƒ q9n t d | ƒ ‚ d  S(   Nu   includeu   include u    u   anchori   u%   warning: no files found matching '%s'u   excludeu   exclude u9   warning: no previously-included files found matching '%s'u   global-includeu   global-include i    u>   warning: no files found matching '%s' anywhere in distributionu   global-excludeu   global-exclude uR   warning: no previously-included files matching '%s' found anywhere in distributionu   recursive-includeu   recursive-include %s %su   prefixu:   warning: no files found matching '%s' under directory '%s'u   recursive-excludeu   recursive-exclude %s %suN   warning: no previously-included files matching '%s' found under directory '%s'u   graftu   graft u+   warning: no directories found matching '%s'u   pruneu   prune u6   no previously-included directories found matching '%s'u'   this cannot happen: invalid action '%s'(	   u   _parse_template_lineu   debug_printu   joinu   include_patternu   logu   warnu   exclude_patternu   Noneu   DistutilsInternalError(   u   selfu   lineu   actionu   patternsu   diru   dir_patternu   pattern(    (    u/   /mit/python/lib/python3.0/distutils/filelist.pyu   process_template_linei   sr     	 	 	 		 		 			i   i    c             C   s    d } t | | | | ƒ } |  j d | j ƒ |  j d k o |  j ƒ  n xL |  j D]A } | j | ƒ o+ |  j d | ƒ |  j j	 | ƒ d } qW qW W| S(   u—  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 True if files are found, False otherwise.
        u%   include_pattern: applying regex r'%s'u    adding FNT(   u   Falseu   translate_patternu   debug_printu   patternu   allfilesu   Noneu   findallu   searchu   filesu   appendu   True(   u   selfu   patternu   anchoru   prefixu   is_regexu   files_foundu
   pattern_reu   name(    (    u/   /mit/python/lib/python3.0/distutils/filelist.pyu   include_patternµ   s    	
 c             C   s    d } t | | | | ƒ } |  j d | j ƒ xj t t |  j ƒ d d d ƒ D]I } | j |  j | ƒ o, |  j d |  j | ƒ |  j | =d } qO qO W| S(   u  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 True if files are found, False otherwise.
        u%   exclude_pattern: applying regex r'%s'i   iÿÿÿÿu
    removing FT(	   u   Falseu   translate_patternu   debug_printu   patternu   rangeu   lenu   filesu   searchu   True(   u   selfu   patternu   anchoru   prefixu   is_regexu   files_foundu
   pattern_reu   i(    (    u/   /mit/python/lib/python3.0/distutils/filelist.pyu   exclude_patternß   s    	  
N(   u   __name__u
   __module__u   __doc__u   Noneu   __init__u   set_allfilesu   osu   curdiru   findallu   debug_printu   appendu   extendu   sortu   remove_duplicatesu   _parse_template_lineu   process_template_lineu   include_patternu   exclude_pattern(   u
   __locals__(    (    u/   /mit/python/lib/python3.0/distutils/filelist.pyu   FileList   s   
		
			
				L+u   FileListc             C   s  d d l  m } m } m } m } g  } |  g } | j } | j } xÄ | o¼ | ƒ  }  t j |  ƒ }	 x |	 D]• }
 |  t j	 k o t j
 j |  |
 ƒ } n |
 } t j  | ƒ } | | } | | ƒ o | j | ƒ ql | | ƒ o | | ƒ o | | ƒ ql ql WqF W| S(   u^   Find all files under 'dir' and return the list of full filenames
    (relative to 'dir').
    i    (   u   ST_MODEu   S_ISREGu   S_ISDIRu   S_ISLNK(   u   statu   ST_MODEu   S_ISREGu   S_ISDIRu   S_ISLNKu   popu   appendu   osu   listdiru   curdiru   pathu   join(   u   diru   ST_MODEu   S_ISREGu   S_ISDIRu   S_ISLNKu   listu   stacku   popu   pushu   namesu   nameu   fullnameu   statu   mode(    (    u/   /mit/python/lib/python3.0/distutils/filelist.pyu   findallö   s*    "			 	 
c             C   s(   t  j |  ƒ } t j d d | ƒ } | S(   uæ   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).
    u   (^|[^\\])\.u   \1[^/](   u   fnmatchu	   translateu   reu   sub(   u   patternu
   pattern_re(    (    u/   /mit/python/lib/python3.0/distutils/filelist.pyu
   glob_to_re  s    	i   c             C   s°   | o& t  |  t ƒ o t j |  ƒ S|  Sn |  o t |  ƒ } n d } | d k	 o7 t | ƒ d d … } d t j j | d | ƒ } n | o d | } n t j | ƒ S(   u  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).
    u    i    iÿÿÿÿu   ^u   .*N(	   u
   isinstanceu   stru   reu   compileu
   glob_to_reu   Noneu   osu   pathu   join(   u   patternu   anchoru   prefixu   is_regexu
   pattern_reu	   prefix_re(    (    u/   /mit/python/lib/python3.0/distutils/filelist.pyu   translate_pattern(  s    !(   u   __doc__u   __revision__u   osu   reu   fnmatchu   distutils.utilu   convert_pathu   distutils.errorsu   DistutilsTemplateErroru   DistutilsInternalErroru	   distutilsu   logu   FileListu   curdiru   findallu
   glob_to_reu   Noneu   translate_pattern(    (    (    u/   /mit/python/lib/python3.0/distutils/filelist.pyu   <module>   s   ç	