
v^O                 @   s   d  d l  Z  d  d l Z d  d l Z d  d l Z d  d l m Z m Z d  d l m	 Z	 m
 Z
 m Z d d   Z d d   Z Gd d	   d	 e  Z d S)
    N)BaseCommandCommandError)find_commandis_ignored_pathpopen_wrapperc             C   sG   t  |  d   } | j d  } Wd  QRX| j t j t j t j f  S)Nrb   )openread
startswithcodecsBOM_UTF8BOM_UTF16_LEBOM_UTF16_BE)fnfsample r   Q/tmp/pip-build-8lau8j11/django/django/core/management/commands/compilemessages.pyhas_bom   s    r   c             C   sH   y+ t  |  d   t j |  d   Wd  QRXWn t k
 rC d SYn Xd S)NaFT)r	   osutimeOSError)pathr   r   r   is_writable   s    	r   c               @   sO   e  Z d  Z d Z d Z d Z d g Z d d   Z d d   Z d	 d
   Z	 d S)CommandzECompiles .po files to .mo files for use with builtin gettext support.FZmsgfmtz--check-formatc             C   s   | j  d d d d d g  d d | j  d d	 d d d g  d d
 | j  d d d d d d d d | j  d d d d d d d g  d d d d d  S)Nz--localez-lactionappenddefaulthelpzYLocale(s) to process (e.g. de_AT). Default is to process all. Can be used multiple times.z	--excludez-xz@Locales to exclude. Default is none. Can be used multiple times.z--use-fuzzyz-fdestfuzzy
store_truezUse fuzzy translations.z--ignorez-iignore_patternsmetavarPATTERNzWIgnore directories matching this glob-style pattern. Use multiple times to ignore more.)add_argument)selfparserr   r   r   add_arguments%   s    zCommand.add_argumentsc                s  | d } | d } t  | d  } | d |  _ | d rN |  j d g |  _ t |  j  d  k rv t d |  j   t j j d d  d g } t j	 j
 d	  r d
 d l m } | j | j  x t j d d d D] \  } } xp | D]h }	 t t j j t j j  |	   |  r/| j |	  q |	 d k r | j t j j  |	   q Wq Wt  t t j j t t j j |    } | st d   g  }
 xL | D]D   t t j j t j d     } |
 j t t j j |   qW| p|
 } t  |  j |  } d |  _ x | D]   | rI  f d d   | D } n	   g } g  } xQ | D]I } x@ t j |  D]/ \  } } | j  f d d   | D  quWq_W| r!|  j |  q!W|  j rt d   d  S)Nlocaleexcluder$   	verbosityr"   z-fzLCan't find %s. Make sure you have GNU gettext tools 0.15 or newer installed.ZconfZDJANGO_SETTINGS_MODULEr   )settings.topdownTzzThis script should be run from the Django Git checkout or your project or app tree, or with the settings module specified.z%s/*Fc                s(   g  |  ] } t  j j   | d    q S)LC_MESSAGES)r   r   join).0l)basedirr   r   
<listcomp>h   s   	 z"Command.handle.<locals>.<listcomp>c             3   s*   |  ]  } | j  d   r   | f Vq d S)z.poN)endswith)r3   r   )dirpathr   r   	<genexpr>n   s    z!Command.handle.<locals>.<genexpr>z-compilemessages generated one or more errors.)setr-   program_optionsr   programr   r   r   r2   environgetZdjango.confr.   extendZLOCALE_PATHSwalkr   normpathremover   mapabspathfilterisdirglobbasename
difference
has_errorscompile_messages)r(   optionsr+   r,   r$   Zbasedirsr.   dirnames	filenamesdirnameZall_localesZlocale_dirsZlocalesdirs	locationsZldirr   )r5   r8   r   handle:   sR    


%*$*" 		(	zCommand.handlec             C   s  t  j j   } g  } xt |  D]\ } \ } } |  j d k r` |  j j d | | f  t j j	 | |  } t
 |  r |  j j d |  d |  _ q% t j j |  d } | d k r t | d  r |  j j d |  d |  _ d S|  j g |  j d | d | d	 g }	 | j | j t |	   q% Wx t  j j |  D]v }
 |
 j   \ } } } | rM|  j d k r| r|  j j d
 |  j | f  n |  j j d |  j  d |  _ qMWWd QRXd S)zI
        Locations is a list of tuples: [(directory, file), ...]
        r   zprocessing file %s in %s
zmThe %s file has a BOM (Byte Order Mark). Django only supports .po files encoded in UTF-8 and without any BOM.Tz.mozeThe po files under %s are in a seemingly not writable location. mo files will not be updated/created.Nz-oz.pozExecution of %s failed: %szExecution of %s failed)
concurrentfuturesThreadPoolExecutor	enumerater-   stdoutwriter   r   r2   r   stderrrJ   splitextr   r<   r;   r   submitr   as_completedresult)r(   rQ   executorrT   ir8   r   Zpo_path	base_pathargsfutureoutputerrorsstatusr   r   r   rK   u   s<    				 zCommand.compile_messagesN)
__name__
__module____qualname__r    Zrequires_system_checksr<   r;   r*   rR   rK   r   r   r   r   r      s   	;r   )r   concurrent.futuresrS   rG   r   Zdjango.core.management.baser   r   Zdjango.core.management.utilsr   r   r   r   r   r   r   r   r   r   <module>   s   