ó
ø¢TQc           @  s¾   d  d l  m Z d  d l Z d  d l Z d  d l m Z d  d l m Z d  d l m	 Z	 m
 Z
 d  d l m Z d  d l m Z d  d l m Z d  d	 l m Z m Z d
 e
 f d „  ƒ  YZ d S(   iÿÿÿÿ(   t   unicode_literalsN(   t   make_option(   t   FileSystemStorage(   t   CommandErrort   NoArgsCommand(   t
   smart_text(   t
   SortedDict(   t   input(   t   finderst   storaget   Commandc           B  st  e  Z d  Z e j e d d d d d d e d d ƒe d	 d d d d
 d e d d ƒe d d d d d g  d d d d d d ƒe d d d d d d d e d d ƒe d d d d d d d e d d ƒe d d d d d d d e d d ƒe d  d d d d! d e d d" ƒf Z d# Z e Z	 d$ „  Z
 d% „  Z d& „  Z d' „  Z d( d) „ Z d* „  Z d+ „  Z d, „  Z d- „  Z RS(.   uw   
    Command that allows to copy or symlink static files from different
    locations to the settings.STATIC_ROOT.
    u	   --noinputt   actionu   store_falset   destu   interactivet   defaultt   helpu-   Do NOT prompt the user for input of any kind.u   --no-post-processu   post_processu$   Do NOT post process collected files.u   -iu   --ignoreu   appendu   ignore_patternst   metavaru   PATTERNu`   Ignore files or directories matching this glob-style pattern. Use multiple times to ignore more.u   -nu	   --dry-runu
   store_trueu   dry_runu+   Do everything except modify the filesystem.u   -cu   --clearu   clearu[   Clear the existing files using the storage before trying to copy or link the original file.u   -lu   --linku   linku7   Create a symbolic link to each file instead of copying.u   --no-default-ignoreu   use_default_ignore_patternsuI   Don't ignore the common private glob-style patterns 'CVS', '.*' and '*~'.u*   Collect static files in a single location.c         O  s¦   t  t |  ƒ j | | Ž  g  |  _ g  |  _ g  |  _ g  |  _ t j |  _ y |  j j	 d ƒ Wn t
 k
 ry t |  _ n
 Xt |  _ t t d ƒ r¢ t j t ƒ n  d  S(   Nu    u   stat_float_times(   t   superR   t   __init__t   copied_filest   symlinked_filest   unmodified_filest   post_processed_filesR	   t   staticfiles_storaget   patht   NotImplementedErrort   Falset   localt   Truet   hasattrt   ost   stat_float_times(   t   selft   argst   kwargs(    (    sU   ../Django//lib/python/django/contrib/staticfiles/management/commands/collectstatic.pyR   2   s    					c         K  sŸ   | d |  _  t | j d d ƒ ƒ |  _ | d |  _ | d |  _ | d |  _ | d } | d ry | d	 d
 d g 7} n  t t | ƒ ƒ |  _	 | d |  _
 d S(   uA   
        Set instance variables based on an options dict
        u   interactiveu	   verbosityi   u   linku   clearu   dry_runu   ignore_patternsu   use_default_ignore_patternsu   CVSu   .*u   *~u   post_processN(   t   interactivet   intt   gett	   verbosityt   symlinkt   cleart   dry_runt   listt   sett   ignore_patternst   post_process(   R   t   optionsR+   (    (    sU   ../Django//lib/python/django/contrib/staticfiles/management/commands/collectstatic.pyt   set_optionsC   s    

c         C  sè  |  j  rI t j d k r. t d t j ƒ ‚ n  |  j sI t d ƒ ‚ qI n  |  j rb |  j d ƒ n  |  j  rw |  j } n	 |  j } t	 ƒ  } x™ t
 j ƒ  D]‹ } x‚ | j |  j ƒ D]n \ } } t | d d ƒ rè t j j | j | ƒ } n | } | | k r¯ | | f | | <| | | | ƒ q¯ q¯ Wq– W|  j r¿t |  j d ƒ r¿|  j j | d |  j ƒ} xa | D]V \ } }	 }
 |
 r§|  j d | |	 f d	 d
 ƒ|  j j | ƒ qb|  j d | ƒ qbWn  i |  j |  j d 6|  j d 6|  j d 6S(   u   
        Perform the bulk of the work of collectstatic.

        Split off from handle_noargs() to facilitate testing.
        u   win32u2   Symlinking is not supported by this platform (%s).u&   Can't symlink to a remote destination.u    u   prefixu   post_processR(   u   Post-processed '%s' as '%st   leveli   u   Skipped post-processing '%s'u   modifiedu
   unmodifiedu   post_processedN(   R&   t   syst   platformR   R   R'   t	   clear_dirt	   link_filet	   copy_fileR   R   t   get_findersR)   R+   t   getattrt   NoneR   R   t   joint   prefixR,   R   R	   R(   t   logR   t   appendR   R   R   (   R   t   handlert   found_filest   finderR   R	   t   prefixed_patht	   processort   original_patht   processed_patht	   processed(    (    sU   ../Django//lib/python/django/contrib/staticfiles/management/commands/collectstatic.pyt   collectR   sB    							
c         K  sž  |  j  |   t |  j t ƒ rD |  j j rD |  j j } d | } n d  } d } |  j rb d } n d } |  j r¥ t d | | f ƒ } | d k r¥ t	 d ƒ ‚ q¥ n  |  j
 ƒ  } t | d ƒ } t | d	 ƒ } t | d
 ƒ }	 |  j d k ršd }
 |
 i | d 6d | d k rd pd d 6|  j r/d p2d d 6| rFd | pId d 6| d	 rad | pdd d	 6| d
 r|d |	 pd d
 6} |  j j | ƒ n  d  S(   Nu	   :

    %su   .u    This will DELETE EXISTING FILES!u#   This will overwrite existing files!uº   
You have requested to collect static files at the destination
location as specified in your settings%s

%s
Are you sure you want to do this?

Type 'yes' to continue, or 'no' to cancel: u   yesu"   Collecting static files cancelled.u   modifiedu
   unmodifiedu   post_processedi   u^   
%(modified_count)s %(identifier)s %(action)s%(destination)s%(unmodified)s%(post_processed)s.
u   modified_countu   static fileu   su    u
   identifieru	   symlinkedu   copiedu   actionu    to '%s'u   destinationu   , %s unmodifiedu   , %s post-processed(   R.   t
   isinstanceR	   R   t   locationR7   R'   R"   R   R   RD   t   lenR%   R&   t   stdoutt   write(   R   R-   t   destination_patht   destination_displayt   clear_displayt   confirmt	   collectedt   modified_countt   unmodified_countt   post_processed_countt   templatet   summary(    (    sU   ../Django//lib/python/django/contrib/staticfiles/management/commands/collectstatic.pyt   handle_noargs‡   sD    				
i   c         C  s&   |  j  | k r" |  j j | ƒ n  d S(   u"   
        Small log helper
        N(   R%   RH   RI   (   R   t   msgR/   (    (    sU   ../Django//lib/python/django/contrib/staticfiles/management/commands/collectstatic.pyR:   º   s    c         C  sÅ   |  j  j | ƒ \ } } xy | D]q } t j j | | ƒ } |  j rc |  j d t | ƒ d d ƒq |  j d t | ƒ d d ƒ|  j  j | ƒ q Wx* | D]" } |  j	 t j j | | ƒ ƒ q› Wd S(   uX   
        Deletes the given relative path using the destination storage backend.
        u   Pretending to delete '%s'R/   i   u   Deleting '%s'N(
   R	   t   listdirR   R   R8   R(   R:   R   t   deleteR2   (   R   R   t   dirst   filest   ft   fpatht   d(    (    sU   ../Django//lib/python/django/contrib/staticfiles/management/commands/collectstatic.pyR2   Á   s    		c         C  sh  |  j  j | ƒ rdy |  j  j | ƒ } Wn t t t f k
 rD nß Xy | j | ƒ } Wn t t t f k
 rt n¯ X|  j r“ |  j  j | ƒ } n d } | | k r#|  j	 rÇ | rÇ t
 j j | ƒ pæ |  j	 oæ | oæ t
 j j | ƒ s#| |  j k r|  j j | ƒ n  |  j d | ƒ t Sn  |  j r@|  j d | ƒ qd|  j d | ƒ |  j  j | ƒ n  t S(   uR   
        Checks if the target file should be deleted if it already exists
        u   Skipping '%s' (not modified)u   Pretending to delete '%s'u   Deleting '%s'N(   R	   t   existst   modified_timet   OSErrorR   t   AttributeErrorR   R   R7   R&   R   t   islinkR   R;   R:   R   R(   RW   R   (   R   R   R?   t   source_storaget   target_last_modifiedt   source_last_modifiedt	   full_path(    (    sU   ../Django//lib/python/django/contrib/staticfiles/management/commands/collectstatic.pyt   delete_fileÑ   s4    		c         C  sû   | |  j  k r  |  j d | ƒ S|  j | | | ƒ s9 d S| j | ƒ } |  j rk |  j d | d d ƒnj |  j d | d d ƒ|  j j | ƒ } y t j t j j | ƒ ƒ Wn t	 k
 rÄ n Xt j
 | | ƒ | |  j  k r÷ |  j  j | ƒ n  d S(   u*   
        Attempt to link ``path``
        u&   Skipping '%s' (already linked earlier)Nu   Pretending to link '%s'R/   i   u   Linking '%s'(   R   R:   Rf   R   R(   R	   R   t   makedirst   dirnameR_   R&   R;   (   R   R   R?   Rb   t   source_pathRe   (    (    sU   ../Django//lib/python/django/contrib/staticfiles/management/commands/collectstatic.pyR3   û   s     	c         C  s"  | |  j  k r  |  j d | ƒ S|  j | | | ƒ s9 d S| j | ƒ } |  j rk |  j d | d d ƒn‘ |  j d | d d ƒ|  j rÑ |  j j | ƒ } y t j t j j	 | ƒ ƒ WqÑ t
 k
 rÍ qÑ Xn  | j | ƒ  } |  j j | | ƒ Wd QX| |  j  k r|  j  j | ƒ n  d S(   u7   
        Attempt to copy ``path`` with storage
        u&   Skipping '%s' (already copied earlier)Nu   Pretending to copy '%s'R/   i   u   Copying '%s'(   R   R:   Rf   R   R(   R   R	   R   Rg   Rh   R_   t   opent   saveR;   (   R   R   R?   Rb   Ri   Re   t   source_file(    (    sU   ../Django//lib/python/django/contrib/staticfiles/management/commands/collectstatic.pyR4     s$    		(   t   __name__t
   __module__t   __doc__R   t   option_listR   R   R   R   t   requires_model_validationR   R.   RD   RT   R:   R2   Rf   R3   R4   (    (    (    sU   ../Django//lib/python/django/contrib/staticfiles/management/commands/collectstatic.pyR
      sD   					5	3		*	(   t
   __future__R    R   R0   t   optparseR   t   django.core.files.storageR   t   django.core.management.baseR   R   t   django.utils.encodingR   t   django.utils.datastructuresR   t   django.utils.six.movesR   t   django.contrib.staticfilesR   R	   R
   (    (    (    sU   ../Django//lib/python/django/contrib/staticfiles/management/commands/collectstatic.pyt   <module>   s   