î
à^Q\0  ã               @   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 Gd	 d
 „  d
 e ƒ Z d S)é    N)Úapps)Úsettings)ÚBaseCommandÚCommandError)Úcolor_style)Úget_template)Úget_template_setting)Úsignalcommandc                   sa   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
 ‡  S)ÚCommandÚ z/Validate templates on syntax and compile errorsz	.DS_Storez*.swpz*~c                s´   t  t |  ƒ j | ƒ | j d d d d d d d d d	 ƒ| j d
 d d d d d d d d d ƒ| j d d d d d d d g  d d ƒ| j d d d d d d g  d d ƒd  S)Nz	--no-appsÚactionÚ
store_trueÚdestÚno_appsÚdefaultFÚhelpz"Do not automatically include apps.z--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)Úsuperr
   Úadd_argumentsÚadd_argument)ÚselfÚparser)Ú	__class__© úi/var/www/dbchiro/venv/build/django-extensions/django_extensions/management/commands/validate_templates.pyr      s    zCommand.add_argumentsc             C   s@   t  j j | ƒ } x' |  j D] } t j | | ƒ r d Sq Wd 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 ƒ |  _ n  t ƒ  } t t d ƒ ƒ } | t | j d g  ƒ ƒ O} | t t t d g  ƒ ƒ O} | d s| d } | r³ t  t d ƒ r³ t t d ƒ } n  xf t j	 ƒ  D]U } | j
 | k rÛ qÀ n  t j j | j d ƒ } t j j | ƒ rÀ | j | ƒ qÀ qÀ Wn  t  t d	 ƒ rEt | ƒ t j d
 d <n t | ƒ t _ d t _ t | j d d ƒ ƒ } d
 }	 x+| D]#}
 xt j |
 ƒ D]	\ } } } x÷ | D]ï } |  j | ƒ rÉq®n  t j j t j j | | ƒ ƒ } | d k rt | ƒ n  y t | ƒ Wnb t k
 ru} zB |	 d 7}	 t d | | j d | j j t | ƒ f ƒ f ƒ WYd  d  } ~ Xn X|	 r®| j d d ƒ r®t d ƒ ‚ q®q®Wq˜Wq‚W|	 rÂt d |	 ƒ ‚ n  t d |	 ƒ d  S)NZVALIDATE_TEMPLATES_IGNORESZDIRSr   Z&VALIDATE_TEMPLATES_EXTRA_TEMPLATE_DIRSr   r   ZVALIDATE_TEMPLATES_IGNORE_APPSZ	templatesÚ	TEMPLATESr   TÚ	verbosityé   z%s: %sz%s %sr   FzErrors foundz%s errors found) Úhasattrr   Úgetattrr!   r   Úsetr   Úgetr   Zget_app_configsÚnamer   r   ÚjoinÚisdirÚaddÚlistr%   ZTEMPLATE_DIRSZTEMPLATE_DEBUGÚintÚwalkr$   ÚrealpathÚprintr   Ú	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   sP    	

	!
FzCommand.handle)r7   Ú
__module__Ú__qualname__r9   r   r*   r!   r   r$   r	   rB   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   