ó
®â0_c           @  sÜ   d  d l  m Z d  d l Z d  d l m Z d  d l 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  d	 l m Z d  d
 l m Z d  d l m Z d  d l m Z d e f d „  ƒ  YZ d S(   iÿÿÿÿ(   t   unicode_literalsN(   t   OrderedDict(   t   apps(   t   get_finders(   t   staticfiles_storage(   t   FileSystemStorage(   t   BaseCommandt   CommandError(   t   no_style(   t
   force_text(   t   cached_property(   t   inputt   Commandc           B  s   e  Z d  Z d Z e Z d „  Z e d „  ƒ Z d „  Z	 d „  Z
 d „  Z d „  Z d d	 „ Z 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*   Collect static files in a single location.c         O  sV   t  t |  ƒ j | | Ž  g  |  _ g  |  _ g  |  _ g  |  _ t |  _ t	 ƒ  |  _
 d  S(   N(   t   superR   t   __init__t   copied_filest   symlinked_filest   unmodified_filest   post_processed_filesR   t   storageR   t   style(   t   selft   argst   kwargs(    (    s^   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/staticfiles/management/commands/collectstatic.pyR      s    					c         C  s-   y |  j  j d ƒ Wn t k
 r( t SXt S(   Nu    (   R   t   patht   NotImplementedErrort   Falset   True(   R   (    (    s^   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/staticfiles/management/commands/collectstatic.pyt   local"   s
    c         C  s  | j  d d d d d d d t d d	 ƒ| j  d
 d d d d d t d d ƒ| j  d d d d d g  d d d d d d ƒ| j  d d d d d d d t d d ƒ| j  d d d d d d d t d d ƒ| j  d d d d d d d t d d  ƒ| j  d! d d d d" d t d d# ƒd  S($   Nu	   --noinputu
   --no-inputt   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_patternsuW   Don't ignore the common private glob-style patterns (defaults to 'CVS', '.*' and '*~').(   t   add_argumentR   R   (   R   t   parser(    (    s^   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/staticfiles/management/commands/collectstatic.pyt   add_arguments*   s8    				c         K  s”   | d |  _  | d |  _ | d |  _ | d |  _ | d |  _ | d } | d rn | t j d ƒ j 7} n  t t	 | ƒ ƒ |  _ | d	 |  _
 d
 S(   uA   
        Set instance variables based on an options dict
        u   interactiveu	   verbosityu   linku   clearu   dry_runu   ignore_patternsu   use_default_ignore_patternsu   staticfilesu   post_processN(   t   interactivet	   verbosityt   symlinkt   cleart   dry_runR   t   get_app_configt   ignore_patternst   listt   sett   post_process(   R   t   optionsR+   (    (    s^   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/staticfiles/management/commands/collectstatic.pyt   set_optionsQ   s    

c         C  s  |  j  r" |  j r" t d ƒ ‚ n  |  j r; |  j d ƒ n  |  j  rP |  j } n	 |  j } t ƒ  } x­ t ƒ  D]¢ } x™ | j	 |  j
 ƒ D]… \ } } t | d d ƒ r¾ t j j | j | ƒ } n | } | | k ró | | f | | <| | | | ƒ q… |  j d | d d ƒq… Wql W|  j rèt |  j d ƒ rè|  j j | d |  j ƒ} x | D]’ \ } }	 }
 t |
 t ƒ rš|  j j d	 | ƒ |  j j d ƒ |
 ‚ n  |
 rÐ|  j d
 | |	 f d d ƒ|  j j | ƒ qO|  j d | ƒ qOWn  i |  j |  j d 6|  j d 6|  j d 6S(   ux   
        Perform the bulk of the work of collectstatic.

        Split off from handle() to facilitate testing.
        u&   Can't symlink to a remote destination.u    u   prefixuÆ   Found another file with the destination path '%s'. It will be ignored since only the first encountered file is collected. If this is not what you want, make sure every static file has a unique path.t   leveli   u   post_processR)   u   Post-processing '%s' failed!u   Post-processed '%s' as '%s'u   Skipped post-processing '%s'u   modifiedu
   unmodifiedu   post_processedN(   R'   R   R   R(   t	   clear_dirt	   link_filet	   copy_fileR   R   R,   R+   t   getattrt   Nonet   osR   t   joint   prefixt   logR.   t   hasattrR   R)   t
   isinstancet	   Exceptiont   stderrt   writeR   t   appendR   R   R   (   R   t   handlert   found_filest   finderR   R   t   prefixed_patht	   processort   original_patht   processed_patht	   processed(    (    s^   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/staticfiles/management/commands/collectstatic.pyt   collect`   sJ    						
c         K  s  |  j  |   d g } |  j r/ | j d ƒ n  | j d ƒ |  j ƒ  rž |  j j rž |  j j } | j d | ƒ |  j j | ƒ o˜ t |  j j | ƒ ƒ } n d  } | j d ƒ t
 } |  j r&| r&|  j rß | j d ƒ n | j d ƒ | j d ƒ t d	 j | ƒ ƒ 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	 n d d 6|  j r°d n d d 6| rÇd | n d	 d 6| d râd | n d	 d 6| d rýd | p d	 d 6}
 |
 Sd  S(   Nu   
uG   You have activated the --dry-run option so no files will be modified.

ud   You have requested to collect static files at the destination
location as specified in your settingsu   :

    %s

u   .

u-   This will DELETE ALL FILES in this location!
u$   This will overwrite existing files!
uN   Are you sure you want to do this?

Type 'yes' to continue, or 'no' to cancel: u    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
   identifieru	   symlinkedu   copiedu   actionu    to '%s'u   destinationu   , %s unmodifiedu   , %s post-processed(   R0   R)   R@   t   is_local_storageR   t   locationt   existst   anyt   listdirR6   R   R%   R(   R   R8   R   RI   t   lenR&   R'   (   R   R/   t   messaget   destination_patht   should_warn_usert	   collectedt   modified_countt   unmodified_countt   post_processed_countt   templatet   summary(    (    s^   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/staticfiles/management/commands/collectstatic.pyt   handleŸ   sN    		
	
i   c         C  s&   |  j  | k r" |  j j | ƒ n  d S(   u"   
        Small log helper
        N(   R&   t   stdoutR?   (   R   t   msgR1   (    (    s^   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/staticfiles/management/commands/collectstatic.pyR:   Û   s    c         C  s   t  |  j t ƒ S(   N(   R<   R   R   (   R   (    (    s^   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/staticfiles/management/commands/collectstatic.pyRJ   â   s    c         C  sJ  |  j  j | ƒ s d S|  j  j | ƒ \ } } xè | D]à } t j j | | ƒ } |  j ry |  j d t | ƒ d d ƒq5 |  j d t | ƒ d d ƒy |  j  j | ƒ } Wn! t	 k
 rÏ |  j  j
 | ƒ q5 Xt j j | ƒ rt j j | ƒ rt j | ƒ q5 |  j  j
 | ƒ q5 Wx* | D]" } |  j t j j | | ƒ ƒ q Wd S(   uX   
        Deletes the given relative path using the destination storage backend.
        Nu   Pretending to delete '%s'R1   i   u   Deleting '%s'(   R   RL   RN   R7   R   R8   R)   R:   R	   R   t   deletet   lexistst   unlinkR2   (   R   R   t   dirst   filest   ft   fpatht	   full_patht   d(    (    s^   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/staticfiles/management/commands/collectstatic.pyR2   å   s"    	 %c   	      C  se  |  j  j | ƒ ra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 | ƒ } |  j t	 j j
 | ƒ A} n d } t } | j d d ƒ | j d d ƒ k } | r | r | |  j k r|  j j | ƒ n  |  j d | ƒ t S|  j r=|  j d | ƒ qa|  j d | ƒ |  j  j | ƒ n  t S(   uR   
        Checks if the target file should be deleted if it already exists
        t   microsecondi    u   Skipping '%s' (not modified)u   Pretending to delete '%s'u   Deleting '%s'N(   R   RL   t   get_modified_timet   OSErrorR   t   AttributeErrorR   R   R'   R7   t   islinkR6   R   t   replaceR   R@   R:   R   R)   R\   (	   R   R   RD   t   source_storaget   target_last_modifiedt   source_last_modifiedRc   t   can_skip_unmodified_filest   file_is_unmodified(    (    s^   /tmp/pip-unpacked-wheel-BAJOf3/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 ƒn|  j d | d d ƒ|  j j | ƒ } y t j t j j | ƒ ƒ Wn t	 k
 rÄ n Xy6 t j j
 | ƒ rê t j | ƒ n  t j | | ƒ Wnƒ t k
 r0d d l } t d | j ƒ  ƒ ‚ nQ t k
 rbd d l } t d	 | j ƒ  ƒ ‚ n t	 k
 r€} t | ƒ ‚ n X| |  j  k r£|  j  j | ƒ n  d S(
   u*   
        Attempt to link ``path``
        u&   Skipping '%s' (already linked earlier)Nu   Pretending to link '%s'R1   i   u   Linking '%s'iÿÿÿÿu)   Symlinking is not supported by Python %s.u2   Symlinking is not supported in this platform (%s).(   R   R:   Rp   R   R)   R   R7   t   makedirst   dirnameRg   R]   R^   R'   Rh   t   platformR   t   python_versionR   R@   (   R   R   RD   Rk   t   source_pathRc   Rs   t   e(    (    s^   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/staticfiles/management/commands/collectstatic.pyR3   3  s:    	c         C  sÁ   | |  j  k r  |  j d | ƒ S|  j | | | ƒ s9 d S| j | ƒ } |  j rk |  j d | d d ƒnB |  j d | d d ƒ| j | ƒ  } |  j j | | ƒ Wd QX|  j  j | ƒ d S(   u7   
        Attempt to copy ``path`` with storage
        u&   Skipping '%s' (already copied earlier)Nu   Pretending to copy '%s'R1   i   u   Copying '%s'(	   R   R:   Rp   R   R)   t   openR   t   saveR@   (   R   R   RD   Rk   Ru   t   source_file(    (    s^   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/staticfiles/management/commands/collectstatic.pyR4   Z  s    	(   t   __name__t
   __module__t   __doc__R    R   t   requires_system_checksR   R
   R   R$   R0   RI   RY   R:   RJ   R2   Rp   R3   R4   (    (    (    s^   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/staticfiles/management/commands/collectstatic.pyR      s   			'		?	<			3	'(   t
   __future__R    R7   t   collectionsR   t   django.appsR   t"   django.contrib.staticfiles.findersR   t"   django.contrib.staticfiles.storageR   t   django.core.files.storageR   t   django.core.management.baseR   R   t   django.core.management.colorR   t   django.utils.encodingR	   t   django.utils.functionalR
   t   django.utils.six.movesR   R   (    (    (    s^   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/staticfiles/management/commands/collectstatic.pyt   <module>   s   