î
2!ìVÐ  ã               @   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
 Gd 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   sÉ   | j  d d d d d g  d d d d	 d
 d ƒf | j  d d d d d d d d
 d ƒf | j  d d d d d d
 d ƒf | j  d d d d d d d
 d ƒf | j  d d d d d d d
 d ƒf d  S)Nz-iz--ignoreÚactionÚappendÚdefaultÚdestÚignore_patternsÚmetavarÚPATTERNÚhelpz`Ignore files or directories matching this glob-style pattern. Use multiple times to ignore more.z--no-default-ignoreÚstore_falseÚuse_default_ignore_patternsTzIDon't ignore the common private glob-style patterns 'CVS', '.*' and '*~'.z--follow-linksÚfollow_linksÚ
store_truez¼Follow 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.z-cz--cleanÚcleanzRemove all itemsz-az--addÚaddzAdd all items)Úadd_argument)ÚselfÚparser© r   úW/tmp/pip-build-0sboevxh/django-compressor/compressor/management/commands/mtime_cache.pyÚadd_arguments   s"    



zCommand.add_argumentsc             C   s.   x' |  j  D] } t j | | ƒ r
 d Sq
 Wd 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   s8  | d } | d r4 | d d d g 7} | | d <n  | |  _  | d rQ | d sg | d rv | d rv t d ƒ ‚ n  t j sŽ t d	 ƒ ‚ n  t ƒ  } t ƒ  } xt j t j d
 | d ƒD]ÿ \ } } } x- | D]% } |  j | ƒ rÓ | j	 | ƒ qÓ qÓ Wx½ | D]µ }	 d j
 | j t j ƒ ƒ }
 |
 j t j ƒ rR|
 t t j ƒ d  … }
 n  |  j t j j
 |
 |	 ƒ ƒ rvqn  t j j
 | |	 ƒ }	 | j t |	 ƒ ƒ | d r| j |	 ƒ qqWq½ W| röt j t | ƒ ƒ |  j j d t | ƒ ƒ n  | r4x | D] }	 t |	 ƒ qW|  j j d t | ƒ ƒ n  d  S)Nr   r   Z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.Úfollowlinksr   Ú z*Deleted mtimes of %d files from the cache.z"Added mtimes of %d files to cache.)r   r   r   ZCOMPRESS_MTIME_DELAYÚsetÚosÚwalkZCOMPRESS_ROOTr!   ÚremoveÚjoinÚsplitÚ
startswithÚsepÚlenr   r   r   r   Zdelete_manyÚlistÚstdoutÚwriter   )r   Úoptionsr   Zfiles_to_addZkeys_to_deleteÚrootÚdirsÚfilesZdir_ÚfilenameÚcommonr   r   r   Úhandle/   sJ    

				
zCommand.handleN)Ú__name__Ú
__module__Ú__qualname__r   r   r!   r6   r   r   r   r   r   
   s   
r   )r   r%   Zdjango.core.management.baser   r   Zcompressor.confr   Zcompressor.cacher   r   r   r   r   r   r   r   Ú<module>   s
   