î
Ý^Q\x<  ã               @   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 Gd d „  d e ƒ Z d S)é    )Úunicode_literalsN)ÚOrderedDict)Úapps)Úget_finders)Ústaticfiles_storage)ÚFileSystemStorage)ÚBaseCommandÚCommandError)Úno_style)Ú
force_text)Úcached_property)Úinputc                   sÁ   e  Z d  Z d Z d Z d Z ‡  f d d †  Z e d d „  ƒ Z d d	 „  Z	 d
 d „  Z
 d d „  Z d d „  Z d d d „ Z d d „  Z d d „  Z d d „  Z d d „  Z d d „  Z ‡  S)ÚCommandzw
    Command that allows to copy or symlink static files from different
    locations to the settings.STATIC_ROOT.
    z*Collect static files in a single location.Fc                sV   t  t |  ƒ j | | Ž  g  |  _ g  |  _ g  |  _ g  |  _ t |  _ t	 ƒ  |  _
 d  S)N)Úsuperr   Ú__init__Úcopied_filesÚsymlinked_filesÚunmodified_filesÚpost_processed_filesr   Ústorager
   Ústyle)ÚselfÚargsÚkwargs)Ú	__class__© úb/var/www/dbchiro/venv/build/Django/django/contrib/staticfiles/management/commands/collectstatic.pyr      s    					zCommand.__init__c             C   s1   y |  j  j d ƒ Wn t k
 r, d SYn Xd S)NÚ FT)r   ÚpathÚNotImplementedError)r   r   r   r   Úlocal"   s
    	zCommand.localc             C   s  | j  d d d d d d d d d	 d
 ƒ| j  d d d d d d d d	 d ƒ| j  d d d d d g  d d d d d	 d ƒ| j  d d d d d d d d d	 d ƒ| j  d d d d d d d d d	 d ƒ| j  d d  d d d d! d d d	 d" ƒ| j  d# d d d d$ d d d	 d% ƒd  S)&Nz	--noinputz
--no-inputÚactionÚstore_falseÚdestÚinteractiveÚdefaultTÚhelpz-Do NOT prompt the user for input of any kind.z--no-post-processÚpost_processz$Do NOT post process collected files.z-iz--ignoreÚappendÚignore_patternsÚmetavarÚPATTERNz`Ignore files or directories matching this glob-style pattern. Use multiple times to ignore more.z-nz	--dry-runÚ
store_trueÚdry_runFz+Do everything except modify the filesystem.z-cz--clearÚclearz[Clear the existing files using the storage before trying to copy or link the original file.z-lz--linkÚlinkz7Create a symbolic link to each file instead of copying.z--no-default-ignoreÚuse_default_ignore_patternszWDon't ignore the common private glob-style patterns (defaults to 'CVS', '.*' and '*~').)Úadd_argument)r   Úparserr   r   r   Úadd_arguments*   s8    				zCommand.add_argumentsc             K   s”   | d |  _  | d |  _ | d |  _ | d |  _ | d |  _ | d } | d rn | t j d ƒ j 7} n  t t	 | ƒ ƒ |  _ | d	 |  _
 d
 S)zA
        Set instance variables based on an options dict
        r$   Ú	verbosityr/   r.   r-   r)   r0   Zstaticfilesr'   N)r$   r4   Úsymlinkr.   r-   r   Zget_app_configr)   ÚlistÚsetr'   )r   Úoptionsr)   r   r   r   Úset_optionsQ   s    

zCommand.set_optionsc             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)zx
        Perform the bulk of the work of collectstatic.

        Split off from handle() to facilitate testing.
        z&Can't symlink to a remote destination.r   ÚprefixNzÆ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.Úlevelé   r'   r-   zPost-processing '%s' failed!zPost-processed '%s' as '%s'zSkipped post-processing '%s'ÚmodifiedÚ
unmodifiedÚpost_processed)r5   r    r	   r.   Ú	clear_dirÚ	link_fileÚ	copy_filer   r   r6   r)   ÚgetattrÚosr   Újoinr:   Úlogr'   Úhasattrr   r-   Ú
isinstanceÚ	ExceptionÚstderrÚwriter   r(   r   r   r   )r   ÚhandlerZfound_filesÚfinderr   r   Úprefixed_pathÚ	processorZoriginal_pathZprocessed_pathÚ	processedr   r   r   Úcollect`   sJ    						
zCommand.collectc             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 ƒ d } |  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)NÚ
zGYou have activated the --dry-run option so no files will be modified.

zdYou have requested to collect static files at the destination
location as specified in your settingsz:

    %s

z.

Tz-This will DELETE ALL FILES in this location!
z$This will overwrite existing files!
zNAre you sure you want to do this?

Type 'yes' to continue, or 'no' to cancel: r   Úyesz"Collecting static files cancelled.r=   r>   r?   r<   z^
%(modified_count)s %(identifier)s %(action)s%(destination)s%(unmodified)s%(post_processed)s.
Úmodified_countzstatic fileÚsZ
identifierZ	symlinkedÚcopiedr!   z to '%s'Zdestinationz, %s unmodifiedz, %s post-processed)r9   r-   r(   Úis_local_storager   ÚlocationÚexistsÚanyÚlistdirr$   r.   r   rE   r	   rQ   Úlenr4   r5   )r   r8   ÚmessageZdestination_pathZshould_warn_userZ	collectedrT   Zunmodified_countZpost_processed_countÚtemplateÚsummaryr   r   r   ÚhandleŸ   sN    		
	
zCommand.handleé   c             C   s&   |  j  | k r" |  j j | ƒ n  d S)z"
        Small log helper
        N)r4   ÚstdoutrK   )r   Úmsgr;   r   r   r   rF   Û   s    zCommand.logc             C   s   t  |  j t ƒ S)N)rH   r   r   )r   r   r   r   rW   â   s    zCommand.is_local_storagec             C   sK  |  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
 | ƒ Yq5 Xt j j | ƒ rt j j | ƒ rt j | ƒ q5 |  j  j
 | ƒ q5 Wx* | D]" } |  j t j j | | ƒ ƒ q!Wd S)zX
        Deletes the given relative path using the destination storage backend.
        NzPretending to delete '%s'r;   r<   zDeleting '%s')r   rY   r[   rD   r   rE   r-   rF   r   r   ÚdeleteÚlexistsÚunlinkr@   )r   r   ÚdirsÚfilesÚfZfpathÚ	full_pathÚdr   r   r   r@   å   s"    	 %zCommand.clear_dirc       	      C   sg  |  j  j | ƒ rcy |  j  j | ƒ } Wn t t t f k
 rE YnÝ Xy | j | ƒ } Wn t t t f k
 rv Yn¬ X|  j r¯ |  j  j | ƒ } |  j t	 j j
 | ƒ A} n d } d } | j d d ƒ | j d d ƒ k } | r"| r"| |  j k r|  j j | ƒ n  |  j d | ƒ d S|  j r?|  j d | ƒ qc|  j d | ƒ |  j  j | ƒ n  d S)	zR
        Checks if the target file should be deleted if it already exists
        NTÚmicrosecondr   zSkipping '%s' (not modified)FzPretending to delete '%s'zDeleting '%s')r   rY   Zget_modified_timeÚOSErrorr   ÚAttributeErrorr    r   r5   rD   ÚislinkÚreplacer   r(   rF   r-   rd   )	r   r   rN   Úsource_storageZtarget_last_modifiedZsource_last_modifiedrj   Zcan_skip_unmodified_filesZfile_is_unmodifiedr   r   r   Údelete_file   s4    		zCommand.delete_filec             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Å Yn Xy6 t j j
 | ƒ rë t j | ƒ n  t j | | ƒ Wn— t k
 r2d d l } t d | j ƒ  ƒ ‚ Ynd t k
 red d l } t d	 | j ƒ  ƒ ‚ Yn1 t	 k
 r•} z t | ƒ ‚ WYd d } ~ Xn X| |  j  k r¸|  j  j | ƒ n  d S)
z*
        Attempt to link ``path``
        z&Skipping '%s' (already linked earlier)NzPretending to link '%s'r;   r<   zLinking '%s'r   z)Symlinking is not supported by Python %s.z2Symlinking is not supported in this platform (%s).)r   rF   rr   r   r-   r   rD   ÚmakedirsÚdirnamerm   re   rf   r5   rn   Úplatformr	   Úpython_versionr   r(   )r   r   rN   rq   Úsource_pathrj   ru   Úer   r   r   rA   3  s:    	zCommand.link_filec          
   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)z7
        Attempt to copy ``path`` with storage
        z&Skipping '%s' (already copied earlier)NzPretending to copy '%s'r;   r<   zCopying '%s')	r   rF   rr   r   r-   Úopenr   Úsaver(   )r   r   rN   rq   rw   Zsource_filer   r   r   rB   Z  s    	zCommand.copy_file)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r&   Zrequires_system_checksr   r   r    r3   r9   rQ   r`   rF   rW   r@   rr   rA   rB   r   r   )r   r   r      s   	'?<3'r   )Ú
__future__r   rD   Úcollectionsr   Zdjango.appsr   Z"django.contrib.staticfiles.findersr   Z"django.contrib.staticfiles.storager   Zdjango.core.files.storager   Zdjango.core.management.baser   r	   Zdjango.core.management.colorr
   Zdjango.utils.encodingr   Zdjango.utils.functionalr   Zdjango.utils.six.movesr   r   r   r   r   r   Ú<module>   s   