a
    Lcòf!;  ã                   @   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)Úapps)Úget_finders)Ústaticfiles_storage)ÚTags)ÚFileSystemStorage)ÚBaseCommandÚCommandError)Úno_style)Úcached_propertyc                       sŠ   e Zd ZdZdZejg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.c                    s<   t ƒ j|i |¤Ž 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__© úy/home/httpd/docs/test/DocsMgr/lib/python3.9/site-packages/django/contrib/staticfiles/management/commands/collectstatic.pyr      s    zCommand.__init__c                 C   s*   z| j  d¡ W n ty$   Y dS 0 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� |j ddddd� |j 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_truez+Do everything except modify the filesystem.)r#   r%   z-cz--clearz[Clear the existing files using the storage before trying to copy or link the original file.z-lz--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   st   |d | _ |d | _|d | _|d | _|d | _|d }|d rR|t d¡j7 }td	d
„ |D ƒƒ| _|d | _	dS )zA
        Set instance variables based on an options dict
        r"   Ú	verbosityÚlinkÚclearÚdry_runr(   r,   Ústaticfilesc                 S   s   h | ]}t j |¡’qS r   )Úosr   Únormpath)Ú.0Úpr   r   r   Ú	<setcomp>h   ó    z&Command.set_options.<locals>.<setcomp>r&   N)
r"   r0   Úsymlinkr2   r3   r   Zget_app_configr(   Úlistr&   )r   Úoptionsr(   r   r   r   Úset_options\   s    




zCommand.set_optionsc                 C   sf  | j r| jstdƒ‚| jr$|  d¡ | j r2| j}n| j}i }tƒ D ]p}| | j	¡D ]^\}}t
|ddƒrxtj |j|¡}n|}||vrž||f||< ||||ƒ qR| jd| dd� qRqB| j�rNt| jdƒ�rN| jj|| jd	�}|D ]l\}}	}
t|
tƒ�r| j d
| ¡ | j ¡  |
‚|
�r>| jd||	f dd� | j |¡ qà|  d| ¡ qà| 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&   )r3   zPost-processing '%s' failed!zPost-processed '%s' as '%s'é   zSkipped post-processing '%s')ÚmodifiedÚ
unmodifiedÚpost_processed)r;   r    r   r2   Ú	clear_dirÚ	link_fileÚ	copy_filer   r<   r(   Úgetattrr5   r   Újoinr?   Úlogr&   Úhasattrr   r3   Ú
isinstanceÚ	ExceptionÚstderrÚwriter   r'   r   r   r   )r   ÚhandlerZfound_filesÚfinderr   r   Úprefixed_pathÚ	processorZoriginal_pathZprocessed_pathÚ	processedr   r   r   Úcollectk   sP    

ýû
	

þ
ýzCommand.collectc           	      K   st  | j f i |¤Ž dg}| jr&| d¡ | d¡ |  ¡ rt| jjrt| jj}| d| ¡ | j |¡opt| j |¡ƒ}nd }| d¡ d}| j	rÐ|rÐ| j
r¢| d¡ n
| d¡ | d	¡ td
 |¡ƒdkrÐtdƒ‚|  ¡ }| jdk�rpt|d ƒ}t|d ƒ}t|d ƒ}d|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.r@   rD   rE   rF   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#   ÚdestinationrE   rF   )r>   r3   r'   Úis_local_storager   ÚlocationÚexistsÚanyÚlistdirr"   r2   ÚinputrK   r   rW   r0   Úlenr;   )	r   r=   ÚmessageZdestination_pathZshould_warn_userÚ	collectedr\   Zunmodified_countZpost_processed_countr   r   r   Úhandleª   s\    ÿÿ
ÿ


ÿÿ
ÿñýzCommand.handlerC   c                 C   s   | j |kr| j |¡ dS )z"
        Small log helper
        N)r0   ÚstdoutrQ   )r   ÚmsgrB   r   r   r   rL   í   s    
zCommand.logc                 C   s   t | jtƒS r   )rN   r   r   r   r   r   r   r_   ô   s    zCommand.is_local_storagec              	   C   sæ   | j  |¡sdS | j  |¡\}}|D ]ž}tj ||¡}| jrP| jd| dd� q$| jd| dd� z| j  |¡}W n ty�   | j  	|¡ Y q$0 tj |¡s¶tj 
|¡r¶t |¡ q$| j  	|¡ q$|D ]}|  tj ||¡¡ qÈdS )zW
        Delete the given relative path using the destination storage backend.
        NúPretending to delete '%s'r@   rA   úDeleting '%s')r   ra   rc   r5   r   rK   r3   rL   r   ÚdeleteÚlexistsÚunlinkrG   )r   r   ÚdirsÚfilesÚfZfpathÚ	full_pathÚdr   r   r   rG   ÷   s"    zCommand.clear_dirc           	   
   C   s  | j  |¡�rz| j  |¡}W n tttfy6   Y nž0 z| |¡}W n tttfy^   Y nv0 | jrˆ| j  |¡}| jt	j 
|¡A  }nd}|jdd�|jdd�k}|rÔ|rÔ|| jv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.
        Tr   )ÚmicrosecondzSkipping '%s' (not modified)Frk   rl   )r   ra   Zget_modified_timeÚOSErrorr   ÚAttributeErrorr    r   r;   r5   ÚislinkÚreplacer   r'   rL   r3   rm   )	r   r   rT   Úsource_storageZtarget_last_modifiedZsource_last_modifiedrs   Zcan_skip_unmodified_filesZfile_is_unmodifiedr   r   r   Údelete_file  s:    ÿÿ
þ
zCommand.delete_filec              
   C   s  || j v r|  d| ¡S |  |||¡s*dS | |¡}| jrN| jd| dd� n°| jd| dd� | j |¡}tjtj |¡dd	� z&tj 	|¡ršt 
|¡ t ||¡ W nT tyÒ   d
dl}td| ¡  ƒ‚Y n, tyü } zt|ƒ‚W Y d}~n
d}~0 0 || j v�r| j  |¡ dS )z*
        Attempt to link ``path``
        z&Skipping '%s' (already linked earlier)NzPretending to link '%s'r@   rA   zLinking '%s'rC   T)Úexist_okr   z2Symlinking is not supported in this platform (%s).)r   rL   r{   r   r3   r   r5   ÚmakedirsÚdirnamern   ro   r;   r   Úplatformr   rv   r'   )r   r   rT   rz   Úsource_pathrs   r   Úer   r   r   rH   E  s2    


ÿÿzCommand.link_filec                 C   s¨   || j v r|  d| ¡S |  |||¡s*dS | |¡}| jrN| jd| dd� nJ| jd| dd� | |¡�}| j ||¡ W d  ƒ n1 sŽ0    Y  | j  |¡ dS )z7
        Attempt to copy ``path`` with storage
        z&Skipping '%s' (already copied earlier)NzPretending to copy '%s'r@   rA   zCopying '%s'rC   )	r   rL   r{   r   r3   Úopenr   Úsaver'   )r   r   rT   rz   r€   Zsource_filer   r   r   rI   h  s    

,zCommand.copy_file)rC   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r%   r   r4   Zrequires_system_checksr   r
   r    r/   r>   rW   rh   rL   r_   rG   r{   rH   rI   Ú__classcell__r   r   r   r   r      s    	
5?C
3#r   )r5   Zdjango.appsr   Z"django.contrib.staticfiles.findersr   Z"django.contrib.staticfiles.storager   Zdjango.core.checksr   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   