U
    ad+                     @   s|   d dl Z d dl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 d dlmZ d dlmZ G d	d
 d
eZdS )    N)apps)settings)BaseCommandCommandError)color_style)get_template)get_template_setting)signalcommandc                       sF   e Zd ZdZdZedddgZ fddZdd	 Ze	d
d Z
  ZS )Command z/Validate templates on syntax and compile errorsz	.DS_Storez*.swpz*~c                    sd   t  | |jdddddd |jdddd	dd
d |jddddg dd |jdddg dd d S )Nz	--no-apps
store_trueno_appsFz"Do not automatically include apps.)actiondestdefaulthelpz--breakz-bbreakzBreak on first error.z	--includez-iappendincludesz#Append these paths to TEMPLATE DIRSz--ignore-appignore_appszIgnore these apps)superadd_argumentsadd_argument)selfparser	__class__ \/tmp/pip-unpacked-wheel-portabvm/django_extensions/management/commands/validate_templates.pyr      s>                  zCommand.add_argumentsc                 C   s.   t j|}| jD ]}t||r dS qdS )NTF)ospathbasenameignoresfnmatch)r   filenameZignore_patternr   r   r   ignore_filename,   s
    
zCommand.ignore_filenamec                 O   s  t tdrttd| _t }ttdg }|t|d O }|tttdg O }|d s|d }|svt tdrvttd}t D ]6}|j	|krq~t
j|jd}t
j|r~|| q~t|tjd	 d< d
t_|d }d	}	|D ]}
t
|
D ]\}}}|D ]}| |rqt
j||}|dkr0| j| zt| W nV tk
r } z6|	d7 }	| jd||d|jjt|f f  W 5 d }~X Y nX |	r|d rtdqqq|	rtd|	 | jd|	  d S )NZVALIDATE_TEMPLATES_IGNORESZDIRSr   Z&VALIDATE_TEMPLATES_EXTRA_TEMPLATE_DIRSr   r   ZVALIDATE_TEMPLATES_IGNORE_APPSZ	templatesr   T	verbosity   z%s: %sz%s %sr   zErrors foundz%s errors found)hasattrr   getattrr"   r   setr   r   Zget_app_configsnamer   r    joinisdiraddlistZ	TEMPLATESZTEMPLATE_DEBUGwalkr%   stdoutwriter   	ExceptionERRORr   __name__strr   )r   argsoptionsstyleZtemplate_dirsr   ZappZapp_template_dirr&   errorsZtemplate_dirrootdirs	filenamesr$   filepather   r   r   handle3   sL    



<zCommand.handle)r5   
__module____qualname__r7   r   r*   r"   r   r%   r	   r@   __classcell__r   r   r   r   r
      s   r
   )r   r#   Zdjango.appsr   Zdjango.confr   Zdjango.core.management.baser   r   Zdjango.core.management.colorr   Zdjango.template.loaderr   Zdjango_extensions.compatr   Z"django_extensions.management.utilsr	   r
   r   r   r   r   <module>   s   