
 X[                 @   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 d   Z d d	   Z Gd
 d   d e  Z d S)    )unicode_literalsN)BaseCommandCommandError)find_commandpopen_wrapper)npathupathc          
   C   sF   t  |  d   } | j d  } Wd  QX| 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   ]/home/ubuntu/projects/ifolica/build/django/django/core/management/commands/compilemessages.pyhas_bom   s    r   c             C   sM   y* t  |  d   t j |  d   Wd  QXWn t t f k
 rH d SYn Xd S)NaFT)r   osutimeIOErrorOSError)pathr   r   r   is_writable   s    	r   c               @   sU   e  Z d  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.FTZmsgfmtz--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 d d d d  S)Nz--localez-ldestlocaleactionappenddefaulthelpzYLocale(s) to process (e.g. de_AT). Default is to process all. Can be used multiple times.z	--excludez-xexcludez@Locales to exclude. Default is none. Can be used multiple times.z--use-fuzzyz-ffuzzy
store_trueFzUse fuzzy translations.)add_argument)selfparserr   r   r   add_arguments&   s    zCommand.add_argumentsc                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 d   | j D  n  xb t j d d d D]K \  } } x9 | D]1 } | d k r | j t j j  |   q q Wq Wt t t j j t t j j |    } | smt d   n  g  }	 xL | D]D   t t j j t j d     }
 |	 j t t j j |
   qzW| p|	 } t |  t |  } x | D]   | r  f d d   | D } n	   g } g  } xQ | D]I } x@ t j |  D]/ \  } } | j  f d d   | D  q?Wq)W| r|  j |  qqWd  S)Nr!   r&   	verbosityr'   z-fzLCan't find %s. Make sure you have GNU gettext tools 0.15 or newer installed.confZDJANGO_SETTINGS_MODULEr   )settingsc             s   s   |  ] } t  |  Vq d  S)N)r   ).0r   r   r   r   	<genexpr>C   s    z!Command.handle.<locals>.<genexpr>.topdownTzzThis script should be run from the Django Git checkout or your project or app tree, or with the settings module specified.z%s/*c                s(   g  |  ] } t  j j   | d    q S)LC_MESSAGES)r   r   join)r0   l)basedirr   r   
<listcomp>_   s   	 z"Command.handle.<locals>.<listcomp>c             3   s*   |  ]  } | j  d   r   | f Vq d S)z.poN)endswith)r0   r   )dirpathr   r   r1   e   s    )r-   program_optionsr   programr   r   r   r5   environgetZdjango.confr/   extendZLOCALE_PATHSwalkr#   setmapabspathfilterisdirglobbasenamecompile_messages)r*   optionsr!   r&   Zbasedirsr/   dirnames	filenamesdirnameZall_localesZlocale_dirsZlocalesdirs	locationsZldirr   )r7   r:   r   handle5   sF    


 %'*" 	(zCommand.handlec             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)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.z.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)	enumerater-   stdoutwriter   r   r5   r   r   splitextr   r   stderrr<   r;   r   )r*   rN   ir:   r   Zpo_path	base_pathargsoutputerrorsstatusmsgr   r   r   rH   i   s(    #$zCommand.compile_messagesN)__name__
__module____qualname__r%   Zrequires_system_checksZleave_locale_aloner<   r;   r,   rO   rH   r   r   r   r   r      s   	4r   )
__future__r   r   rF   r   Zdjango.core.management.baser   r   Zdjango.core.management.utilsr   r   Zdjango.utils._osr   r   r   r   r   r   r   r   r   <module>   s   