o
    a"<f                     @   sT   d dl Z d dlZd dlmZmZ d dlmZ d dlmZm	Z	m
Z
 G dd deZdS )    N)BaseCommandCommandError)settings)cache	get_mtimeget_mtime_cachekeyc                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	Commandz-Add or remove all mtime values from the cachec              	   C   st   |j dddg ddddf |j dd	d
dddf |j dddddf |j ddddddf |j ddddddf d S )Nz-iz--ignoreappendignore_patternsPATTERNz`Ignore files or directories matching this glob-style pattern. Use multiple times to ignore more.)actiondefaultdestmetavarhelpz--no-default-ignorestore_falseuse_default_ignore_patternsTzIDon't ignore the common private glob-style patterns 'CVS', '.*' and '*~'.)r   r   r   r   z--follow-linksfollow_links
store_truezFollow symlinks when traversing the COMPRESS_ROOT (which defaults to STATIC_ROOT). Be aware that using this can lead to infinite recursion if a link points to a parent directory of itself.)r   r   r   z-cz--cleancleanzRemove all itemsz-az--addaddzAdd all items)add_argument)selfparser r   a/var/www/html/kck/venv/lib/python3.10/site-packages/compressor/management/commands/mtime_cache.pyadd_arguments   s,   zCommand.add_argumentsc                 C   s"   | j D ]}t||r dS qdS )z
        Return True or False depending on whether the ``path`` should be
        ignored (if it matches any pattern in ``ignore_patterns``).
        TF)r
   fnmatchfnmatchcase)r   pathpatternr   r   r   
is_ignored%   s
   
zCommand.is_ignoredc                 K   s  |d }|d r|g d7 }||d< || _ |d r|d s%|d s)|d s)tdtjs0tdt }t }tjtj|d d	D ]S\}}}|D ]}| |rS|	| qG|D ]<}	d

|tj}
|
tjrp|
ttjd  }
| tj
|
|	r{qVtj
||	}	|t|	 |d r||	 qVq@|rtt| | jdt|  |r|D ]}	t|	 q| jdt|  d S d S )Nr
   r   )CVSz.*z*~r   r   z*Please specify either "--add" or "--clean"zhmtime caching is currently disabled. Please set the COMPRESS_MTIME_DELAY setting to a number of seconds.r   )followlinks z*Deleted mtimes of %d files from the cache.z"Added mtimes of %d files to cache.)r
   r   r   COMPRESS_MTIME_DELAYsetoswalkCOMPRESS_ROOTr!   removejoinsplit
startswithseplenr   r   r   r   delete_manyliststdoutwriter   )r   optionsr
   files_to_addkeys_to_deleterootdirsfilesdir_filenamecommonr   r   r   handle/   s`   




zCommand.handleN)__name__
__module____qualname__r   r   r!   r=   r   r   r   r   r   
   s
    
r   )r   r'   django.core.management.baser   r   compressor.confr   compressor.cacher   r   r   r   r   r   r   r   <module>   s    