B
    ©0H[ ;  ã               @   s€   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 G d
d„ deƒZdS )é    N)ÚOrderedDict)Úapps)Úget_finders)Ústaticfiles_storage)ÚFileSystemStorage)ÚBaseCommandÚCommandError)Úno_style)Úcached_propertyc                   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‡  ZS )ÚCommandzc
    Copies or symlinks static files from different locations to the
    settings.STATIC_ROOT.
    z*Collect static files in a single location.Fc                s8   t ƒ j||Ž g | _g | _g | _g | _t| _tƒ | _	d S )N)
ÚsuperÚ__init__Úcopied_filesÚsymlinked_filesÚunmodified_filesÚpost_processed_filesr   Ústorager	   Ústyle)ÚselfÚargsÚkwargs)Ú	__class__© ú€C:\Users\HIRONO~1\AppData\Local\Temp\pip-install-6bm3nxem\django\django\contrib\staticfiles\management\commands\collectstatic.pyr      s    zCommand.__init__c             C   s*   y| j  d¡ W n tk
r$   dS X dS )NÚ FT)r   ÚpathÚNotImplementedError)r   r   r   r   Úlocal   s
    zCommand.localc          	   C   s�   |j dddddd� |j dddd	d� |j d
ddg dddd� |j dddddd� |j dddddd� |j dddddd� |j dddd d� d S )!Nz	--noinputz
--no-inputÚstore_falseÚinteractivez-Do NOT prompt the user for input of any kind.)ÚactionÚdestÚhelpz--no-post-processÚpost_processz$Do NOT post process collected files.z-iz--ignoreÚappendÚignore_patternsZPATTERNz`Ignore files or directories matching this glob-style pattern. Use multiple times to ignore more.)r    Údefaultr!   Úmetavarr"   z-nz	--dry-runÚ
store_trueÚdry_runz+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&   s,    zCommand.add_argumentsc             K   sn   |d | _ |d | _|d | _|d | _|d | _|d }|d rR|t d¡j7 }tt	|ƒƒ| _|d	 | _
d
S )zA
        Set instance variables based on an options dict
        r   Ú	verbosityr+   r*   r)   r%   r,   Zstaticfilesr#   N)r   r0   Úsymlinkr*   r)   r   Zget_app_configr%   ÚlistÚsetr#   )r   Úoptionsr%   r   r   r   Úset_optionsG   s    




zCommand.set_optionsc             C   sv  | j r| jstdƒ‚| jr$|  d¡ | j r2| j}n| j}tƒ }x~tƒ D ]t}xn| 	| j
¡D ]^\}}t|ddƒr~tj |j|¡}n|}||kr¤||f||< ||||ƒ qX| jd| dd� qXW qFW | j�r^t| jdƒ�r^| jj|| jd	�}xv|D ]n\}}	}
t|
tƒ�r"| j d
| ¡ | j d¡ |
‚|
�rL| jd||	f dd� | j |¡ qì|  d| ¡ qìW | j| j | j| jdœS )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.é   )Úlevelr#   )r)   zPost-processing '%s' failed!zPost-processed '%s' as '%s'zSkipped post-processing '%s')ÚmodifiedÚ
unmodifiedÚpost_processed)r1   r   r   r*   Ú	clear_dirÚ	link_fileÚ	copy_filer   r   r2   r%   ÚgetattrÚosr   Újoinr6   Ú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   ÚcollectV   sH    


zCommand.collectc             K   sx  | j f |Ž dg}| jr"| d¡ | d¡ |  ¡ rp| jjrp| jj}| d| ¡ | j |¡olt| j |¡ƒ}nd }| d¡ d}| j	rÌ|rÌ| j
rž| d¡ n
| d¡ | d	¡ td
 |¡ƒdkrÌtdƒ‚|  ¡ }t|d ƒ}t|d ƒ}t|d ƒ}| jdk�rtd}	|	|d|dk�rd
nd | j�r,dnd|�r<d| nd
|d �rPd| nd
|d �rfd| �phd
dœ }
|
S d 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.r9   r:   r;   r7   z^
%(modified_count)s %(identifier)s %(action)s%(destination)s%(unmodified)s%(post_processed)s.
zstatic fileÚsZ	symlinkedÚcopiedz to '%s'z, %s unmodifiedz, %s post-processed)Úmodified_countÚ
identifierr    Zdestinationr:   r;   )r5   r)   r$   Úis_local_storager   ÚlocationÚexistsÚanyÚlistdirr   r*   ÚinputrA   r   rM   Úlenr0   r1   )r   r4   ÚmessageZdestination_pathZshould_warn_userZ	collectedrR   Zunmodified_countZpost_processed_countÚtemplateÚsummaryr   r   r   Úhandle•   sN    



zCommand.handleé   c             C   s   | j |kr| j |¡ dS )z"
        Small log helper
        N)r0   ÚstdoutrG   )r   Úmsgr8   r   r   r   rB   Ñ   s    
zCommand.logc             C   s   t | jtƒS )N)rD   r   r   )r   r   r   r   rT   Ø   s    zCommand.is_local_storagec          	   C   sð   | j  |¡sdS | j  |¡\}}x¨|D ] }tj ||¡}| jrR| jd| dd� q&| jd| dd� y| j  |¡}W n  tk
r”   | j  	|¡ Y q&X tj |¡sºtj 
|¡rºt |¡ q&| j  	|¡ q&W x |D ]}|  tj ||¡¡ qÐW dS )zW
        Delete the given relative path using the destination storage backend.
        NzPretending to delete '%s'r7   )r8   zDeleting '%s')r   rV   rX   r@   r   rA   r)   rB   r   ÚdeleteÚlexistsÚunlinkr<   )r   r   ÚdirsÚfilesÚfZfpathÚ	full_pathÚdr   r   r   r<   Û   s"    

zCommand.clear_dirc       	   
   C   s  | j  |¡�ry| j  |¡}W n tttfk
r8   Y n¤X y| |¡}W n tttfk
rb   Y nzX | jrŒ| j  |¡}| jt	j 
|¡A  }nd}d}|jdd�|jdd�k}|rÜ|rÜ|| jkrÊ| j |¡ |  d| ¡ dS | jrò|  d| ¡ n|  d| ¡ | j  |¡ dS )	zR
        Check if the target file should be deleted if it already exists.
        NTr   )ÚmicrosecondzSkipping '%s' (not modified)FzPretending to delete '%s'zDeleting '%s')r   rV   Zget_modified_timeÚOSErrorr   ÚAttributeErrorr   r   r1   r@   ÚislinkÚreplacer   r$   rB   r)   rb   )	r   r   rJ   Úsource_storageZtarget_last_modifiedZsource_last_modifiedrh   Zcan_skip_unmodified_filesZfile_is_unmodifiedr   r   r   Údelete_fileö   s4    

zCommand.delete_filec          
   C   s^  || j kr|  d| ¡S |  |||¡s*dS | |¡}| jrN| jd| dd� nô| jd| dd� | j |¡}yt tj |¡¡ W n t	k
r–   Y nX y&tj 
|¡r°t |¡ t ||¡ W n‚ tk
rê   ddl}td| ¡  ƒ‚Y nX tk
�r   ddl}td	| ¡  ƒ‚Y n, t	k
�r@ } zt|ƒ‚W dd}~X Y nX || j k�rZ| j  |¡ dS )
z*
        Attempt to link ``path``
        z&Skipping '%s' (already linked earlier)NzPretending to link '%s'r7   )r8   zLinking '%s'r   z)Symlinking is not supported by Python %s.z2Symlinking is not supported in this platform (%s).)r   rB   rp   r   r)   r   r@   ÚmakedirsÚdirnamerk   rc   rd   r1   rl   Úplatformr   Úpython_versionr   r$   )r   r   rJ   ro   Úsource_pathrh   rs   Úer   r   r   r=   )  s:    


zCommand.link_filec          	   C   s”   || j kr|  d| ¡S |  |||¡s*dS | |¡}| jrN| jd| dd� n6| jd| dd� | |¡�}| j ||¡ W dQ R X | j  |¡ dS )z7
        Attempt to copy ``path`` with storage
        z&Skipping '%s' (already copied earlier)NzPretending to copy '%s'r7   )r8   zCopying '%s')	r   rB   rp   r   r)   Úopenr   Úsaver$   )r   r   rJ   ro   ru   Zsource_filer   r   r   r>   P  s    

zCommand.copy_file)r_   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r"   Zrequires_system_checksr   r
   r   r/   r5   rM   r^   rB   rT   r<   rp   r=   r>   Ú__classcell__r   r   )r   r   r      s   	!?<
3'r   )r@   Ú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.functionalr
   r   r   r   r   r   Ú<module>   s   