a
    LcòfP  ã                   @   st   d dl Z d dlZd dlZd dlZd dlmZ d dlmZm	Z	 d dl
mZmZmZ dd„ Zdd„ ZG d	d
„ d
eƒZdS )é    N)ÚPath)ÚBaseCommandÚCommandError)Úfind_commandÚis_ignored_pathÚpopen_wrapperc                 C   sJ   |   d¡�}| d¡}W d   ƒ n1 s*0    Y  | 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   úl/home/httpd/docs/test/DocsMgr/lib/python3.9/site-packages/django/core/management/commands/compilemessages.pyÚhas_bom   s
    (ÿr   c                 C   sT   z:t | dƒ� t | d ¡ W d   ƒ n1 s.0    Y  W n tyN   Y dS 0 dS )NÚaFT)r
   ÚosÚutimeÚOSError)Úpathr   r   r   Úis_writable   s    .r   c                   @   s6   e Zd ZdZg 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.Zmsgfmtz--check-formatc              	   C   sX   |j dddg dd� |j dddg dd� |j d	d
dddd� |j ddddg ddd� d S )Nz--localez-lÚappendzYLocale(s) to process (e.g. de_AT). Default is to process all. Can be used multiple times.)ÚactionÚdefaultÚhelpz	--excludez-xz@Locales to exclude. Default is none. Can be used multiple times.z--use-fuzzyú-fÚfuzzyÚ
store_truezUse fuzzy translations.)Údestr   r!   z--ignorez-iÚignore_patternsZPATTERNzWIgnore directories matching this glob-style pattern. Use multiple times to ignore more.)r   r%   r    Úmetavarr!   )Úadd_argument)ÚselfÚparserr   r   r   Úadd_arguments&   s<    ûûûùzCommand.add_argumentsc              	      s
  |d }|d }t |d ƒ}|d | _|d r<| jdg | _t| jƒd u rXtd| j ƒ‚tj dd¡dg}tj	 
d	¡rŽd
dlm} | |j¡ tjddd�D ]X\‰}}|D ]H}	ttj tj ˆ|	¡¡|ƒrÖ| |	¡ qª|	dkrª| tj ˆ|	¡¡ qªqœt ttjjttjj|ƒƒƒ}|�s tdƒ‚g }
|D ]2‰ ttjjt dˆ  ¡ƒ}|
 ttjj|ƒ¡ �q(|�pd|
}t |ƒ |¡}d| _|D ]v‰ |�rœ‡ fdd„|D ƒ}nˆ g}g }|D ]6}t |¡D ]$\‰}}| ‡fdd„|D ƒ¡ �q¸�qª|�r~|  |¡ �q~| j�rtdƒ‚d S )NÚlocaleÚexcluder&   Ú	verbosityr#   r"   zLCan'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/*Fc                    s   g | ]}t j ˆ |d ¡‘qS )ÚLC_MESSAGES)r   r   Újoin)Ú.0r,   )Úbasedirr   r   Ú
<listcomp>}   s   z"Command.handle.<locals>.<listcomp>c                 3   s    | ]}|  d ¡rˆ |fV  qdS )z.poN)Úendswith)r5   r   )Údirpathr   r   Ú	<genexpr>…   s   z!Command.handle.<locals>.<genexpr>z-compilemessages generated one or more errors.)Úsetr.   Úprogram_optionsr   Úprogramr   r   r   r4   ÚenvironÚgetZdjango.confr0   ÚextendZLOCALE_PATHSÚwalkr   ÚnormpathÚremover   ÚmapÚabspathÚfilterÚisdirÚglobÚbasenameÚ
differenceÚ
has_errorsÚcompile_messages)r)   Úoptionsr,   r-   r&   Zbasedirsr0   ÚdirnamesÚ	filenamesÚdirnameZall_localesZlocale_dirsZlocalesÚdirsÚ	locationsZldirr   )r6   r9   r   ÚhandleH   sh    
ÿÿÿÿ

ÿÿzCommand.handlec              
   C   sº  t j ¡ ��˜}g }t|ƒD �]\}\}}t|ƒ| }| d¡}z6| ¡ j| ¡ jkrr| jdkrn| j	 
d| ¡ W qW n ty†   Y n0 | jdkr¦| j	 
d||f ¡ t|ƒrÆ| j 
d| ¡ d| _q|dkrþt|ƒsþ| j 
d| ¡ d| _ W d  ƒ dS | jg| j¢d	‘|‘|‘}	| | t|	¡¡ qt j |¡D ]\}
|
 ¡ \}}}|�r8| jdk�rŒ|�rz| j 
d
| j|f ¡ n| j 
d| j ¡ d| _�q8W d  ƒ n1 �s¬0    Y  dS )zI
        Locations is a list of tuples: [(directory, file), ...]
        z.mor   u1   File â€œ%sâ€� is already compiled and up to date.zprocessing file %s in %szmThe %s file has a BOM (Byte Order Mark). Django only supports .po files encoded in UTF-8 and without any BOM.TzeThe po files under %s are in a seemingly not writable location. mo files will not be updated/created.Nz-ozExecution of %s failed: %szExecution of %s failed)Ú
concurrentÚfuturesÚThreadPoolExecutorÚ	enumerater   Úwith_suffixÚstatÚst_mtimer.   ÚstdoutÚwriteÚFileNotFoundErrorr   ÚstderrrK   r   r=   r<   r   Úsubmitr   Úas_completedÚresult)r)   rR   ÚexecutorrU   Úir9   r   Zpo_pathZmo_pathÚargsÚfutureÚoutputÚerrorsÚstatusr   r   r   rL   Ž   s\    

ÿÿ
þÿÿÿÿzCommand.compile_messagesN)
Ú__name__Ú
__module__Ú__qualname__r!   Zrequires_system_checksr=   r<   r+   rS   rL   r   r   r   r   r      s   "Fr   )r   Úconcurrent.futuresrT   rH   r   Úpathlibr   Zdjango.core.management.baser   r   Zdjango.core.management.utilsr   r   r   r   r   r   r   r   r   r   Ú<module>   s   