o
    /h                     @   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                       sD   e Zd ZdZdZeg dZ fddZdd Ze	dd	 Z
  ZS )
Command z/Validate templates on syntax and compile errors)z	.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__ s/var/www/html/env_mimamsha/lib/python3.10/site-packages/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   filename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 }|s;t tdr;ttd}t D ]}|j	|v rGq?t
j|jd}t
j|rZ|| q?t|tjd	 d< d
t_|d }d	}	|D ]e}
t
|
D ]]\}}}|D ]U}| |rq}t
j||}|dkr| j| zt| W n+ ty } z|	d7 }	| jd||d|jjt|f f  W Y d }~nd }~ww |	r|d rtdq}qvqo|	rtd|	 | jd|	  d S )NVALIDATE_TEMPLATES_IGNORESDIRSr   &VALIDATE_TEMPLATES_EXTRA_TEMPLATE_DIRSr   r   VALIDATE_TEMPLATES_IGNORE_APPS	templatesr   T	verbosity   z%s: %sz%s %sr   zErrors foundz%s errors found)hasattrr   getattrr"   r   setr   r   get_app_configsnamer   r    joinisdiraddlist	TEMPLATESTEMPLATE_DEBUGwalkr&   stdoutwriter   	ExceptionERRORr   __name__strr   )r   argsoptionsstyletemplate_dirsr   appapp_template_dirr,   errorstemplate_dirrootdirs	filenamesr$   filepather   r   r   handleG   sh   





	zCommand.handle)r>   
__module____qualname__r@   r   r0   r"   r   r&   r	   rM   __classcell__r   r   r   r   r
      s    !r
   )r   r#   django.appsr   django.confr   django.core.management.baser   r   django.core.management.colorr   django.template.loaderr   django_extensions.compatr   "django_extensions.management.utilsr	   r
   r   r   r   r   <module>   s   