ó
®â0_c           @  s¢   d  d l  m 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
 d  d l m Z m Z d „  Z d „  Z d e f d	 „  ƒ  YZ d S(
   iÿÿÿÿ(   t   unicode_literalsN(   t   BaseCommandt   CommandError(   t   find_commandt   popen_wrapper(   t   npatht   upathc         C  sF   t  |  d ƒ  } | j d ƒ } Wd  QX| j t j t j t j f ƒ S(   Nu   rbi   (   t   opent   readt
   startswitht   codecst   BOM_UTF8t   BOM_UTF16_LEt   BOM_UTF16_BE(   t   fnt   ft   sample(    (    sQ   /tmp/pip-unpacked-wheel-BAJOf3/django/core/management/commands/compilemessages.pyt   has_bom   s    c         C  sI   y* t  |  d ƒ  t j |  d  ƒ Wd  QXWn t t f k
 rD t SXt S(   Nu   a(   R   t   ost   utimet   Nonet   IOErrort   OSErrort   Falset   True(   t   path(    (    sQ   /tmp/pip-unpacked-wheel-BAJOf3/django/core/management/commands/compilemessages.pyt   is_writable   s    t   Commandc           B  sD   e  Z d  Z e Z e Z d Z d g Z d „  Z	 d „  Z
 d „  Z RS(   uE   Compiles .po files to .mo files for use with builtin gettext support.u   msgfmtu   --check-formatc         C  s|   | j  d d d d d d d g  d d	 ƒ| j  d
 d d d d d d g  d d ƒ| j  d d d d d d d t d d ƒd  S(   Nu   --localeu   -lt   destu   localet   actionu   appendt   defaultt   helpuY   Locale(s) to process (e.g. de_AT). Default is to process all. Can be used multiple times.u	   --excludeu   -xu   excludeu@   Locales to exclude. Default is none. Can be used multiple times.u   --use-fuzzyu   -fu   fuzzyu
   store_trueu   Use fuzzy translations.(   t   add_argumentR   (   t   selft   parser(    (    sQ   /tmp/pip-unpacked-wheel-BAJOf3/django/core/management/commands/compilemessages.pyt   add_arguments&   s    c           s   | d } | d } | d |  _  | d rA |  j d g |  _ n  t |  j ƒ d  k rl t d |  j ƒ ‚ n  t j j d d ƒ d g } t j	 j
 d ƒ rÆ d	 d
 l m } | j d „  | j Dƒ ƒ n  xb t j d d t ƒD]K \ ‰  } } x9 | D]1 } | d k rò | j t j j ˆ  | ƒ ƒ qò qò WqÜ Wt t t j j t t j j | ƒ ƒ ƒ } | sjt d ƒ ‚ n  g  }	 xL | D]D }
 t t j j t j d |
 ƒ ƒ } |	 j t t j j | ƒ ƒ qwW| pÈ|	 } t | ƒ t | ƒ } x¸ | D]° }
 | r"g  | D] } t j j |
 | d ƒ ^ qû} n	 |
 g } g  } xN | D]F } x= t j | ƒ D], \ ‰  } } | j ‡  f d †  | Dƒ ƒ qNWq8W| rè|  j | ƒ qèqèWd  S(   Nu   localeu   excludeu	   verbosityu   fuzzyu   -fuL   Can't find %s. Make sure you have GNU gettext tools 0.15 or newer installed.u   confu   DJANGO_SETTINGS_MODULEiÿÿÿÿ(   t   settingsc         s  s   |  ] } t  | ƒ Vq d  S(   N(   R   (   t   .0R   (    (    sQ   /tmp/pip-unpacked-wheel-BAJOf3/django/core/management/commands/compilemessages.pys	   <genexpr>C   s    u   .t   topdownuz   This script should be run from the Django Git checkout or your project or app tree, or with the settings module specified.u   %s/*u   LC_MESSAGESc         3  s*   |  ]  } | j  d  ƒ r ˆ  | f Vq d S(   u   .poN(   t   endswith(   R%   R   (   t   dirpath(    sQ   /tmp/pip-unpacked-wheel-BAJOf3/django/core/management/commands/compilemessages.pys	   <genexpr>e   s    (   t	   verbosityt   program_optionsR   t   programR   R   R   R   t   joint   environt   gett   django.confR$   t   extendt   LOCALE_PATHSt   walkR   t   appendt   sett   mapt   abspatht   filtert   isdirt   globt   basenamet   compile_messages(   R!   t   optionst   localet   excludet   basedirsR$   t   dirnamest	   filenamest   dirnamet   all_localest   basedirt   locale_dirst   localest   lt   dirst	   locationst   ldir(    (   R(   sQ   /tmp/pip-unpacked-wheel-BAJOf3/django/core/management/commands/compilemessages.pyt   handle5   sF    


%'*" .	%c         C  s_  xXt  | ƒ D]J\ } \ } } |  j d k rK |  j j d | | f ƒ n  t j j | | ƒ } t | ƒ r t d | ƒ ‚ n  t j j	 | ƒ d } | d k rÐ t
 t | d ƒ ƒ rÐ |  j j d | ƒ d S|  j g |  j d t | d ƒ t | d ƒ g } t | ƒ \ } }	 }
 |
 r |	 r;d	 |  j |	 f } n d
 |  j } t | ƒ ‚ q q Wd S(   uI   
        Locations is a list of tuples: [(directory, file), ...]
        i    u   processing file %s in %s
um   The %s file has a BOM (Byte Order Mark). Django only supports .po files encoded in UTF-8 and without any BOM.u   .moue   The po files under %s are in a seemingly not writable location. mo files will not be updated/created.Nu   -ou   .pou   Execution of %s failed: %su   Execution of %s failed(   t	   enumerateR)   t   stdoutt   writeR   R   R,   R   R   t   splitextR   R   t   stderrR+   R*   R   (   R!   RI   t   iR(   R   t   po_patht	   base_patht   argst   outputt   errorst   statust   msg(    (    sQ   /tmp/pip-unpacked-wheel-BAJOf3/django/core/management/commands/compilemessages.pyR;   i   s(    #$(   t   __name__t
   __module__R   R   t   requires_system_checksR   t   leave_locale_aloneR+   R*   R#   RK   R;   (    (    (    sQ   /tmp/pip-unpacked-wheel-BAJOf3/django/core/management/commands/compilemessages.pyR      s   			4(   t
   __future__R    R
   R9   R   t   django.core.management.baseR   R   t   django.core.management.utilsR   R   t   django.utils._osR   R   R   R   R   (    (    (    sQ   /tmp/pip-unpacked-wheel-BAJOf3/django/core/management/commands/compilemessages.pyt   <module>   s   		