
    Vhb                     ~    d dl Z 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 Zd Z G d de	      Zy)	    N)Path)BaseCommandCommandError)find_commandis_ignored_pathpopen_wrapperc                     | j                  d      5 }|j                  d      }d d d        j                  t        j                  t        j
                  t        j                  f      S # 1 sw Y   GxY w)Nrb   )openread
startswithcodecsBOM_UTF8BOM_UTF16_LEBOM_UTF16_BE)fnfsamples      _/home/dcms/DCMS/lib/python3.12/site-packages/django/core/management/commands/compilemessages.pyhas_bomr      s^    	 !	&--v/B/BC  s   A**A3c                 |    	 t        j                  |       5  	 d d d        y# 1 sw Y   yxY w# t        $ r Y yw xY w)N)dirFT)tempfileNamedTemporaryFileOSError)paths    r   is_dir_writabler      sE    ((T2 		 		   s    / #/ ,/ / 	;;c                   0    e Zd ZdZg ZdZdgZd Zd Zd Z	y)CommandzECompiles .po files to .mo files for use with builtin gettext support.msgfmtz--check-formatc           	          |j                  dddg d       |j                  dddg d       |j                  d	d
ddd       |j                  ddddg dd       y )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_patternsPATTERNzWIgnore directories matching this glob-style pattern. Use multiple times to ignore more.)r$   r*   r%   metavarr&   )add_argument)selfparsers     r   add_argumentszCommand.add_arguments%   s    * 	 	
 	S 	 	
 	* 	 	
 	"1 	 		
    c           
      d   |d   }|d   }t        |d         }|d   | _        |d   r| j                  dgz   | _        t        | j                        t        d| j                   d      t        j                  j                  d	d      dg}t        j                  j                  d
      r!ddlm} |j                  |j                         t        j                  dd      D ]  \  }}t!        |      D ]  }	t#        t        j                  j%                  t        j                  j                  |	            |      r|j'                  |	       \|	dk(  sb|j)                  t        j                  j                  |	               t        t+        t        j                  j,                  t/        t        j                  j0                  |                  }|st        d      g }
|D ]o  }t/        t        j                  j0                  t3        j2                  d|z              }|
j                  t+        t        j                  j4                  |             q |xs |
}t        |      j7                  |      }d| _        |D ]  }|r/|D cg c]#  }t        j                  j                  ||d      % }}n|g}g }|D ]:  }t        j                  |      D ]   \  }}|j                  fd|D               " < |s{| j;                  |        | j8                  rt        d      y c c}w )Nlocaleexcluder+   	verbosityr(   r'   zCan't find z?. Make sure you have GNU gettext tools 0.19 or newer installed.conf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/*FLC_MESSAGESc              3   J   K   | ]  }|j                  d       s|f  yw)z.poN)endswith).0r   dirpaths     r   	<genexpr>z!Command.handle.<locals>.<genexpr>   s%      %)*1::e;L!%s   #	#z-compilemessages generated one or more errors.)setr6   program_optionsr   programr   osr   joinenvirongetdjango.confr9   extendLOCALE_PATHSwalklistr   normpathremover#   mapabspathfilterisdirglobbasename
difference
has_errorscompile_messages)r/   optionsr4   r5   r+   basedirsr9   dirnames	filenamesdirnameall_localesbasedirlocale_dirslocalesdirs	locationsldirr@   s                    @r   handlezCommand.handleG   s   ")$g&789 -7#'#7#74&#@D %-dll^ ,1 1 
 GGLL2H=::>>23,OOH112 -/GGC,F 	D(GXy> D"GG$$RWW\\'7%CDo OOG,(OOBGGLL'$BCD	D s277??F277==(,KLM1   	CG 		&7:J0KLKs277#3#3[AB	C
 'Kg,))'2 	1GOVEKBGGLL&-@   yI 46GGDM 0GXy$$ %.7% 
 %%i0	1  ??NOO s   (L-c                    t         j                  j                         5 }g }t        |      D ]{  \  }\  }}t	        |      |z  }|j                  d      }	 |j                         j                  |j                         j                  k\  r.| j                  dkD  r| j                  j                  d|z         	 | j                  dkD  r!| j                  j                  d|d|       t        |      r&| j                  j                  d|z         d| _        |dk(  rDt        |j                         s/| j                  j                  d|z         d| _         d	d	d	       y	| j"                  g| j$                  d
||}	|j'                  |j)                  t*        |	             ~ t         j                  j-                  |      D ]  }
|
j/                         \  }}}|s| j                  dkD  rV|r,| j                  j                  d| j"                  d|       n(| j                  j                  d| j"                  z         d| _         	 d	d	d	       y	# t        $ r Y w xY w# 1 sw Y   y	xY w)zI
        Locations is a list of tuples: [(directory, file), ...]
        z.mor   u1   File “%s” is already compiled and up to date.zprocessing file z in zmThe %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 z	 failed: zExecution of %s failed)
concurrentfuturesThreadPoolExecutor	enumerater   with_suffixstatst_mtimer6   stdoutwriteFileNotFoundErrorr   stderrrW   r   parentrD   rC   r#   submitr   as_completedresult)r/   rc   executorrh   ir@   r   po_pathmo_pathargsfutureoutputerrorsstatuss                 r   rX   zCommand.compile_messages   sQ    224 1	+G#,Y#7 #E<GQw-!+!--e4	||~..',,.2I2II>>A- KK-- S")!* ! J >>A%KK%%Aw&OP7#KK%%S!"
 '+DO 6/'.."AKK%%JLST '+DOE1	+ 1	+H Tt';';TTT7TGTx}dCDG#EJ %,,99'B 
+)/&~~)! KK--@Df U !KK--.F.UV&*DO
+O1	+ 1	+ ) 1	+ 1	+s?   7I-A"I9B#I-%A?I-%A.I-	I*&I-)I**I--I6N)
__name__
__module____qualname__r&   requires_system_checksrD   rC   r1   re   rX    r2   r   r    r       s-    RDG'(O 
DEPN5+r2   r    )r   concurrent.futuresrg   rT   rE   r   pathlibr   django.core.management.baser   r   django.core.management.utilsr   r   r   r   r   r    r   r2   r   <module>r      s8       	   A U Uf+k f+r2   