a
    [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   C:\Users\91910\OneDrive\Desktop\vts_admin_rebuild-master\vts\Lib\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	rd
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|	 qqt 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rt|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 s0    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   