o
    uvXj­:  ã                   @   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                    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/var/www/html/myproject/venv/lib/python3.10/site-packages/django/contrib/staticfiles/management/commands/collectstatic.pyr      s   zCommand.__init__c                 C   s(   z	| j  d¡ W dS  ty   Y dS w )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_patternsÚ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   sx   |d | _ |d | _|d | _|d | _|d | _|d }|d r)|t d¡j7 }t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   � | ]	}t j |¡V  qd S r   )Úosr   Únormpath)Ú.0Úpr   r   r   Ú	<genexpr>S   s   € z&Command.set_options.<locals>.<genexpr>r&   N)r"   r1   Úsymlinkr3   r4   r   Úget_app_configr(   ÚlistÚsetr&   )r   Úoptionsr(   r   r   r   Úset_optionsG   s   




zCommand.set_optionsc                 C   sb  | j r
| js
tdƒ‚| jr|  d¡ | j r| j}n| j}tƒ }tƒ D ]8}| 	| j
¡D ]/\}}t|ddƒr=tj |j|¡}n|}||vrP||f||< ||||ƒ q*| jd| dd� q*q"| jr¥t| jdƒr¥| jj|| jd	�}|D ]5\}}	}
t|
tƒr‰| j d
| ¡ | j d¡ |
‚|
r�| jd||	f dd� | j |¡ qo|  d| ¡ qo| 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&   )r4   zPost-processing '%s' failed!zPost-processed '%s' as '%s'é   zSkipped post-processing '%s')ÚmodifiedÚ
unmodifiedÚpost_processed)r;   r    r   r3   Ú	clear_dirÚ	link_fileÚ	copy_filer   r   r=   r(   Úgetattrr6   r   ÚjoinrA   Úlogr&   Úhasattrr   r4   Ú
isinstanceÚ	ExceptionÚstderrÚwriter   r'   r   r   r   )r   ÚhandlerÚfound_filesÚfinderr   r   Úprefixed_pathÚ	processorÚoriginal_pathÚprocessed_pathÚ	processedr   r   r   ÚcollectV   sX   

ýûõÿ
ÿÿ
ýzCommand.collectc                 K   sn  | j di |¤Ž dg}| jr| d¡ | d¡ |  ¡ r:| jjr:| jj}| d| ¡ | j |¡o8t| j |¡ƒ}n	d }| d¡ d}| j	rh|rh| j
rQ| d¡ n| d¡ | d	¡ td
 |¡ƒdkrhtdƒ‚|  ¡ }t|d ƒ}t|d ƒ}t|d ƒ}| jdkrµd}	|	|d|dkrŽd
nd | jr•dnd|rœd| nd
|d r¥d| nd
|d r®d| p¯d
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.rF   rG   rH   rB   z^
%(modified_count)s %(identifier)s %(action)s%(destination)s%(unmodified)s%(post_processed)s.
zstatic fileÚsÚ	symlinkedÚcopiedz to '%s'z, %s unmodifiedz, %s post-processed)Úmodified_countÚ
identifierr#   ÚdestinationrG   rH   r   )r@   r4   r'   Úis_local_storager   ÚlocationÚexistsÚanyÚlistdirr"   r3   ÚinputrM   r   r\   Úlenr1   r;   )r   r?   ÚmessageÚdestination_pathÚshould_warn_userÚ	collectedrb   Úunmodified_countÚpost_processed_countÚtemplateÚsummaryr   r   r   Úhandle”   s`   ÿÿþ


ÿ
ÿÿø
ózCommand.handlerE   c                 C   s   | j |kr| j |¡ dS dS )z"
        Small log helper
        N)r1   ÚstdoutrS   )r   ÚmsgrD   r   r   r   rN   Ð   s   
ÿzCommand.logc                 C   s   t | jtƒS r   )rP   r   r   r   r   r   r   re   ×   s   zCommand.is_local_storagec              	   C   sæ   | j  |¡sdS | j  |¡\}}|D ]O}tj ||¡}| jr(| jd| dd� q| jd| dd� z| j  |¡}W n tyH   | j  	|¡ Y qw tj |¡s[tj 
|¡r[t |¡ q| j  	|¡ q|D ]}|  tj ||¡¡ qddS )zW
        Delete the given relative path using the destination storage backend.
        NúPretending to delete '%s'rB   rC   úDeleting '%s')r   rg   ri   r6   r   rM   r4   rN   r   ÚdeleteÚlexistsÚunlinkrI   )r   r   ÚdirsÚfilesÚfÚfpathÚ	full_pathÚdr   r   r   rI   Ú   s&   ÿÿzCommand.clear_dirc           	   
   C   s  | j  |¡r‚z| j  |¡}W n tttfy   Y nOw z| |¡}W n tttfy.   Y n;w | jrC| j  |¡}| jt	j 
|¡A  }nd}|jdd�|jdd�k}|ri|ri|| jvr`| j |¡ |  d| ¡ dS | jru|  d| ¡ dS |  d| ¡ | j  |¡ dS )zR
        Check if the target file should be deleted if it already exists.
        Tr   )ÚmicrosecondzSkipping '%s' (not modified)Frw   rx   )r   rg   Úget_modified_timeÚOSErrorr   ÚAttributeErrorr    r   r;   r6   ÚislinkÚreplacer   r'   rN   r4   ry   )	r   r   rW   Úsource_storageÚtarget_last_modifiedÚsource_last_modifiedr€   Úcan_skip_unmodified_filesÚfile_is_unmodifiedr   r   r   Údelete_fileõ   s<   þÿ

ÿÿ
þzCommand.delete_filec              
   C   sD  || j v r|  d| ¡S |  |||¡sdS | |¡}| jr'| jd| dd� nl| jd| dd� | j |¡}zt tj |¡¡ W n	 t	yJ   Y nw ztj 
|¡rWt |¡ t ||¡ W n4 tyq   ddl}td	| ¡  ƒ‚ tyƒ   ddl}td
| ¡  ƒ‚ t	y’ } zt|ƒ‚d}~ww || j vr | j  |¡ dS dS )z*
        Attempt to link ``path``
        z&Skipping '%s' (already linked earlier)NzPretending to link '%s'rB   rC   zLinking '%s'rE   r   z)Symlinking is not supported by Python %s.z2Symlinking is not supported in this platform (%s).)r   rN   r�   r   r4   r   r6   ÚmakedirsÚdirnamer„   rz   r{   r;   r…   Úplatformr   Úpython_versionr   r'   )r   r   rW   rˆ   Úsource_pathr€   r�   Úer   r   r   rJ   '  sF   

ÿ
ÿÿ€ÿ
ÿzCommand.link_filec                 C   s¨   || j v r|  d| ¡S |  |||¡sdS | |¡}| jr'| jd| dd� n%| jd| dd� | |¡�}| j ||¡ W d  ƒ n1 sGw   Y  | j  |¡ dS )z7
        Attempt to copy ``path`` with storage
        z&Skipping '%s' (already copied earlier)NzPretending to copy '%s'rB   rC   zCopying '%s'rE   )	r   rN   r�   r   r4   Úopenr   Úsaver'   )r   r   rW   rˆ   r’   Úsource_filer   r   r   rK   N  s   

ÿzCommand.copy_file)rE   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r%   Úrequires_system_checksr   r
   r    r0   r@   r\   rt   rN   re   rI   r�   rJ   rK   Ú__classcell__r   r   r   r   r      s"    	
!>
<2'r   )r6   Úcollectionsr   Údjango.appsr   Ú"django.contrib.staticfiles.findersr   Ú"django.contrib.staticfiles.storager   Údjango.core.files.storager   Údjango.core.management.baser   r   Údjango.core.management.colorr	   Údjango.utils.functionalr
   r   r   r   r   r   Ú<module>   s    