B
    ©0H[Ñ  ã               @   s\   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„ Z	dd„ Z
G dd	„ d	eƒZdS )
é    N)ÚBaseCommandÚCommandError)Úfind_commandÚpopen_wrapperc          	   C   s6   t | dƒ�}| d¡}W d Q R X | 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   úsC:\Users\HIRONO~1\AppData\Local\Temp\pip-install-6bm3nxem\django\django\core\management\commands\compilemessages.pyÚhas_bom	   s    r   c          	   C   sD   y&t | dƒ� t | d ¡ W d Q R X W n ttfk
r>   dS X dS )NÚaFT)r   ÚosÚutimeÚIOErrorÚOSError)Úpathr   r   r   Úis_writable   s    r   c               @   s:   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   sD   |j ddddg dd� |j ddd	dg d
d� |j dddddd� d S )Nz--localez-lÚlocaleÚappendzYLocale(s) to process (e.g. de_AT). Default is to process all. Can be used multiple times.)ÚdestÚactionÚdefaultÚhelpz	--excludez-xÚexcludez@Locales to exclude. Default is none. Can be used multiple times.z--use-fuzzyz-fÚfuzzyÚ
store_truezUse fuzzy translations.)r   r    r"   )Úadd_argument)ÚselfÚparserr   r   r   Úadd_arguments#   s    

zCommand.add_argumentsc                sÔ  |d }|d }|d | _ |d r0| jdg | _t| jƒd krLtd| j ƒ‚tj dd¡dg}tj 	d¡r‚d	d
l
m} | |j¡ xFtjddd�D ]4\‰}}x(|D ] }|dkr¢| tj ˆ|¡¡ q¢W q’W tttjjttjj|ƒƒƒ}|sòtdƒ‚g }	x8|D ]0‰ ttjjt dˆ  ¡ƒ}
|	 ttjj|
ƒ¡ qüW |�p8|	}t|ƒ |¡}x†|D ]~‰ |�rl‡ fdd„|D ƒ}nˆ g}g }xB|D ]:}x2t |¡D ]$\‰}}| ‡fdd„|D ƒ¡ �qŒW �q|W |�rN|  |¡ �qNW d 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   )ÚsettingsÚ.T)ÚtopdownzzThis 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 ˆ |d ¡‘qS )ÚLC_MESSAGES)r   r   Újoin)Ú.0Úl)Úbasedirr   r   ú
<listcomp>\   s    z"Command.handle.<locals>.<listcomp>c             3   s    | ]}|  d ¡rˆ |fV  qdS )z.poN)Úendswith)r1   r   )Údirpathr   r   ú	<genexpr>b   s    z!Command.handle.<locals>.<genexpr>)r*   Úprogram_optionsr   Úprogramr   r   r   r0   ÚenvironÚgetZdjango.confr,   ÚextendZLOCALE_PATHSÚwalkr   ÚsetÚmapÚabspathÚfilterÚisdirÚglobÚbasenameÚ
differenceÚcompile_messages)r'   Úoptionsr   r#   Zbasedirsr,   ÚdirnamesÚ	filenamesÚdirnameZall_localesZlocale_dirsZlocalesÚdirsÚ	locationsZldirr   )r3   r6   r   Úhandle2   sF    






$zCommand.handlec             C   sî   xèt |ƒD ]Ü\}\}}| jdkr4| j d||f ¡ tj ||¡}t|ƒrVtd| ƒ‚tj 	|¡d }|dkrŽt
|d ƒsŽ| j d| ¡ dS | jg| j d|d |d g }t|ƒ\}}	}
|
r
|	rÔd	| j|	f }n
d
| j }t|ƒ‚q
W d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   r0   r   r   Úsplitextr   Ústderrr9   r8   r   )r'   rL   Úir6   r   Zpo_pathÚ	base_pathÚargsÚoutputÚerrorsÚstatusÚmsgr   r   r   rF   f   s(    

zCommand.compile_messagesN)Ú__name__Ú
__module__Ú__qualname__r"   Zrequires_system_checksZleave_locale_aloner9   r8   r)   rM   rF   r   r   r   r   r      s   4r   )r   rC   r   Zdjango.core.management.baser   r   Zdjango.core.management.utilsr   r   r   r   r   r   r   r   r   Ú<module>   s   