ó
ø¢TQc           @   s€  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 d  d l	 m
 Z
 m Z d  d l Z d  d l m Z m Z d  d l m Z d  d l m Z e j d e j e j Bƒ Z d	 Z d d d „ Z d „  Z e j e d „ Z d „  Z e j d „ Z d „  Z  e j d „ Z! d „  Z" d d d e d e d e e e e j d „ Z$ d e f d „  ƒ  YZ% d S(   iÿÿÿÿN(   t	   dropwhile(   t   make_option(   t   PIPEt   Popen(   t   CommandErrort   NoArgsCommand(   t   get_text_list(   t   prepare_js_for_gettexts$   ^(?P<value>"Plural-Forms.+?\\n")\s*$i    t   htmlt   pyc         C   s¬   g  } x0 |  D]( } | j  | j d d ƒ j d ƒ ƒ q Wx> t | ƒ D]0 \ } } | j d ƒ sF d | | | | <qF qF Wt g  | D]! } | j d ƒ | k r„ | ^ q„ ƒ S(   sŽ  
    Organizes multiple extensions that are separated with commas or passed by
    using --extension/-e multiple times. Note that the .py extension is ignored
    here because of the way non-*.py files are handled in make_messages() (they
    are copied to file.ext.py files to trick xgettext to parse them as Python
    files).

    For example: running 'django-admin makemessages -e js,txt -e xhtml -a'
    would result in an extension list: ['.js', '.txt', '.xhtml']

    >>> handle_extensions(['.html', 'html,js,py,py,py,.py', 'py,.py'])
    set(['.html', '.js'])
    >>> handle_extensions(['.html, txt,.tpl'])
    set(['.html', '.tpl', '.txt'])
    t    t    t   ,t   .s   .%s(   t   extendt   replacet   splitt	   enumeratet
   startswitht   sett   strip(   t
   extensionst   ignoredt   ext_listt   extt   it   x(    (    sE   ../Django//lib/python/django/core/management/commands/makemessages.pyt   handle_extensions   s    &c         C   sU   t  |  d t d t d t d t j d k d t ƒ} | j ƒ  \ } } | | | j f S(   s3   
    Friendly wrapper around Popen for Windows
    t   shellt   stdoutt   stderrt	   close_fdst   ntt   universal_newlines(   R   t   TrueR   t   ost   namet   communicatet
   returncode(   t   cmdt   pt   outputt   errors(    (    sE   ../Django//lib/python/django/core/management/commands/makemessages.pyt   _popen*   s    3c         C   so  d t  j } g  | D], } | j | ƒ r: | t | ƒ  n | ^ q } g  } xt  j |  d t d | ƒD]õ \ }	 }
 } xi |
 D]` } t t  j j t  j j	 |	 | ƒ ƒ | ƒ r |
 j
 | ƒ | d k rß | j d | ƒ qß q q Wxw | D]o } t t  j j t  j j	 |	 | ƒ ƒ | ƒ rC| d k rY| j d | |	 f ƒ qYqê | j |	 | f g ƒ qê Wqh W| j ƒ  | S(   s=   
    Helper function to get all files in the given root.
    s   %s*t   topdownt   followlinksi   s   ignoring directory %s
s   ignoring file %s in %s
(   R#   t   sept   endswitht   lent   walkR"   t
   is_ignoredt   patht   normpatht   joint   removet   writeR   t   sort(   t   roott   ignore_patternst	   verbosityR   t   symlinkst
   dir_suffixR(   t   norm_patternst	   all_filest   dirpatht   dirnamest	   filenamest   dirnamet   filename(    (    sE   ../Django//lib/python/django/core/management/commands/makemessages.pyt
   find_files2   s     9+**
c         C   s+   x$ | D] } t  j |  | ƒ r t Sq Wt S(   sN   
    Helper function to check if the given path should be ignored or not.
    (   t   fnmatcht   fnmatchcaseR"   t   False(   R3   R:   t   pattern(    (    sE   ../Django//lib/python/django/core/management/commands/makemessages.pyR2   H   s    c      	   C   sc  t  j j t  j j t  j j t j ƒ ƒ ƒ } | d k rB d } n d } x| D]} t  j j | d d | d d | ƒ } t  j j | ƒ rO t | d ƒ  } t	 j
 | j ƒ  ƒ }	 Wd QX|	 r[| d	 k rè | j d
 |	 j d ƒ ƒ n  g  }
 t } xN |  j d ƒ D]= } | r4| r4d |	 j d ƒ } t } n  |
 j | ƒ qWd j |
 ƒ }  Pq[qO qO W|  S(   sÃ   
    Copies plural forms header contents from a Django catalog of locale to
    the msgs string, inserting it at the right place. msgs should be the
    contents of a newly created .po file.
    t   djangojst   djangot   conft   localet   LC_MESSAGESs   %s.pot   rUNi   s   copying plural forms: %s
t   values   
s   %s
(   RJ   s   django(   s   django(   R#   R3   R4   R5   RC   RK   t   __file__t   existst   opent   plural_forms_ret   searcht   readR7   t   groupRH   R   R"   t   append(   t   msgsRM   t   domainR;   R   t
   django_dirt   domainst	   django_pot   fpt   mt   linest   seent   line(    (    sE   ../Django//lib/python/django/core/management/commands/makemessages.pyt   copy_plural_formsQ   s,    -	%	c         C   s¨   | r7 d | d } d | d } | j  | | ƒ } n  t j j |  ƒ rm d j t t | j d ƒ ƒ ƒ } n | j  d d ƒ } t |  d ƒ  } | j	 | ƒ Wd QXd S(   s|   
    Write the :param potfile: POT file with the :param msgs: contents,
    previously making sure its format is valid.
    s   #: i   s   
s   charset=CHARSETs   charset=UTF-8t   aN(
   R   R#   R3   RR   R5   R    R0   R   RS   R7   (   t   potfileRY   t   filet	   work_filet   is_templatizedt   oldt   newR^   (    (    sE   ../Django//lib/python/django/core/management/commands/makemessages.pyt   write_pot_fileo   s    $c	         C   sÖ  d d l  m }	 | d k r6 | j d |  | f ƒ n  t j j |  ƒ \ }
 } | d k r| | k rt } t j j | |  ƒ } t | ƒ  } | j	 ƒ  } Wd QXt
 | ƒ } d |  } t j j | | ƒ } t | d ƒ  } | j | ƒ Wd QXd	 | | | | f } nû | d
 k r| d k s/| | k r|  } t j j | |  ƒ } | | k } | rÔt | d ƒ  } | j	 ƒ  } Wd QXd |  } |	 | | d ƒ } t t j j | | ƒ d ƒ  } | j | ƒ Wd QXn  t j j | | ƒ } d | | | | f } n d St | ƒ \ } } } | r| t k r~| rCt j | ƒ n  t j j | ƒ ret j | ƒ n  t d |  | f ƒ ‚ q| d k r| j | ƒ qn  | r¼t | | | | | ƒ n  | rÒt j | ƒ n  d S(   s¯   
    Extract translatable literals from :param file: for :param domain:
    creating or updating the :param potfile: POT file.

    Uses the xgettext GNU gettext utility.
    iÿÿÿÿ(   t
   templatizei   s   processing file %s in %s
RJ   Ns   %s.ct   wsÍ   xgettext -d %s -L C %s %s --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy:1,2 --keyword=pgettext:1c,2 --keyword=npgettext:1c,2,3 --from-code UTF-8 --add-comments=Translators -o - "%s"RK   s   .pyRO   s   %s.pyi   s\  xgettext -d %s -L Python %s %s --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy:1,2 --keyword=ugettext_noop --keyword=ugettext_lazy --keyword=ungettext_lazy:1,2 --keyword=pgettext:1c,2 --keyword=npgettext:1c,2,3 --keyword=pgettext_lazy:1c,2 --keyword=npgettext_lazy:1c,2,3 --from-code UTF-8 --add-comments=Translators -o - "%s"s/   errors happened while running xgettext on %s
%si    (   t   django.utils.translationRl   R7   R#   R3   t   splitextR"   R5   RS   RV   R   R+   t	   STATUS_OKt   unlinkRR   R   Rk   (   Rf   R@   Re   RZ   R;   R   t   wrapt   locationR   Rl   t   _t   file_extRh   t	   orig_fileR^   t   src_datat   thefileRg   R'   t   contentRY   R*   t   status(    (    sE   ../Django//lib/python/django/core/management/commands/makemessages.pyt   process_file€   s^    	
$
!c
         C   s  t  d | | | f ƒ \ }
 } } | rs | t k rT t j | ƒ t d | ƒ ‚ qs | d k rs | j | ƒ qs n  t j j |  ƒ r#t | d ƒ  } | j |
 ƒ Wd QXt  d | | |  | f ƒ \ }
 } } | rD| t k rt j | ƒ t d | ƒ ‚ q | d k r | j | ƒ q qDn! | rDt	 |
 | | | | ƒ }
 n  |
 j
 d | d	 ƒ }
 t |  d ƒ  } | j |
 ƒ Wd QXt j | ƒ |	 rþt  d
 | | |  |  f ƒ \ }
 } } | rþ| t k rÜt d | ƒ ‚ qû| d k rû| j | ƒ qûqþn  d S(   sÓ   
    Creates of updates the :param pofile: PO file for :param domain: and :param
    locale:.  Uses contents of the existing :param potfile:.

    Uses mguniq, msgmerge, and msgattrib GNU gettext utilities.
    s"   msguniq %s %s --to-code=utf-8 "%s"s(   errors happened while running msguniq
%si    Rm   Ns   msgmerge %s %s -q "%s" "%s"s)   errors happened while running msgmerge
%ss2   #. #-#-#-#-#  %s.pot (PACKAGE VERSION)  #-#-#-#-#
R   s*   msgattrib %s %s -o "%s" --no-obsolete "%s"s*   errors happened while running msgattrib
%s(   R+   Rp   R#   Rq   R   R7   R3   RR   RS   Rc   R   (   t   pofileRe   RZ   RM   R;   R   t   copy_pformsRr   Rs   t   no_obsoleteRY   R*   Rz   R^   (    (    sE   ../Django//lib/python/django/core/management/commands/makemessages.pyt   write_po_fileÇ   sL    RK   i   c         C   sÜ  d d l  m } | j r% t | _ n | j d t ƒ | d k rJ g  } n  t } t j	 j
 t j	 j d d ƒ ƒ r¨ t j	 j t j	 j d d ƒ ƒ } t } | d g 7} n3 t j	 j
 d ƒ rÏ t j	 j d ƒ } n t d ƒ ‚ | d  k rö t d
 ƒ ‚ n  |  d k r	| s| d k rNd t j	 j t j d ƒ t j d f } t | ƒ ‚ n  t d ƒ \ } } } | t k r~t d ƒ ‚ n  t j d | ƒ } | rèt | j d ƒ ƒ t | j d ƒ ƒ f } | d! k  rèt d | j ƒ  ƒ ‚ qèn  g  } |  d k	 r| j t |  ƒ ƒ nP | r`t t j	 j
 t j d | ƒ ƒ } g  | D] } t j	 j | ƒ ^ q?} n  | rld n d } | r~d n d } xQ| D]I}  | d k r±|
 j d |  ƒ n  t j	 j | |  d ƒ } t j	 j
 | ƒ sët j | ƒ n  t j	 j | d t | ƒ ƒ } t j	 j | d t | ƒ ƒ } t j	 j | ƒ rKt j | ƒ n  xK t d | | |
 d | ƒD]. \ } } t  | | | | | | | | |
 ƒ	 qgWt j	 j | ƒ r‹t! | | | |  | |
 | | | |	 ƒ
 q‹q‹Wd S("   sÌ   
    Uses the ``locale/`` directory from the Django Git tree or an
    application/project to process all files with translatable literals for
    the :param domain: domain and :param locale: locale.
    iÿÿÿÿ(   t   settingst   USE_I18NRL   RM   s	   contrib/*sŒ  This script should be run from the Django Git tree or your project or app tree. If you did indeed run it from the Git checkout or your project or application, maybe you are just missing the conf/locale (in the django tree) or locale (for project and application) directory? It is not created automatically, you have to create it by hand if you want to enable i18n for your project or application.RK   RJ   sD   currently makemessages only supports domains 'django' and 'djangojs's(   Type '%s help %s' for usage information.i    i   s   xgettext --versionsa   Error running xgettext. Note that Django internationalization requires GNU gettext 0.15 or newer.s   (?P<major>\d+)\.(?P<minor>\d+)t   majort   minori   s~   Django internationalization requires GNU gettext 0.15 or newer. You are using version %s, please upgrade your gettext toolset.s   %s/*s	   --no-wrapR   s   --no-locations   processing language %s
RN   s   %s.pos   %s.potR   R<   N(   s   djangos   djangojs(   i    i   ("   t   django.confR€   t
   configuredR"   R   t	   configuret   NoneRH   R#   R3   t   isdirR5   t   abspathR   t   basenamet   syst   argvR+   Rp   t   reRU   t   intRW   RX   t   strt   filtert   globR7   t   makedirsRR   Rq   RE   R{   R   (   RM   RZ   R;   t   allR   R<   R:   t   no_wrapt   no_locationR~   R   R€   t   invoked_for_djangot	   localedirt   messageR)   R*   Rz   t   matcht   xversiont   localest   locale_dirst   lRr   Rs   t   basedirR|   Re   R@   Rf   (    (    sE   ../Django//lib/python/django/core/management/commands/makemessages.pyt   make_messages÷   sj    			!!**"(t   Commandc           B   s€  e  Z e j e d  d d d0 d d d d ƒe d d d d	 d d
 d d ƒe d d d d d d d e d d ƒe d d d d d d d d ƒe d d d d d d d e d d ƒe d d d d d d d g  d d d d  ƒe d! d d" d d# d e d d$ ƒe d% d d d d& d e d d' ƒe d( d d d d) d e d d* ƒe d+ d d d d, d e d d- ƒf
 Z d. Z e Z	 e Z
 d/ „  Z RS(1   s   --locales   -lt   defaultt   destRM   t   helpsG   Creates or updates the message files for the given locale (e.g. pt_BR).s   --domains   -dRK   RZ   s4   The domain of the message files (default: "django").s   --alls   -at   actiont
   store_trueR“   s3   Updates the message files for all existing locales.s   --extensions   -eR   s    The file extension(s) to examine (default: "html,txt", or "js" if the domain is "djangojs"). Separate multiple extensions with commas, or use -e multiple times.RX   s
   --symlinkss   -sR<   sa   Follows symlinks to directories when examining source code and templates for translation strings.s   --ignores   -iR:   t   metavart   PATTERNs`   Ignore files or directories matching this glob-style pattern. Use multiple times to ignore more.s   --no-default-ignoret   store_falset   use_default_ignore_patternssA   Don't ignore the common glob-style patterns 'CVS', '.*' and '*~'.s	   --no-wrapR”   s1   Don't break long message lines into several liness   --no-locationR•   s$   Don't write '#: filename:line' liness   --no-obsoleteR~   s   Remove obsolete message stringss<  Runs over the entire source tree of the current directory and pulls out all strings marked for translation. It creates (or updates) a message file in the conf/locale (in the django tree) or locale (for projects and applications) directory.

You must run this command with one of either the --locale or --all options.c         O   s|  | j  d ƒ } | j  d ƒ } t | j  d ƒ ƒ } | j  d ƒ } | j  d ƒ } | j  d ƒ } | j  d ƒ }	 | j  d ƒ r” |	 d	 d
 d g 7}	 n  t t |	 ƒ ƒ }	 | j  d ƒ }
 | j  d ƒ } | j  d ƒ } | d k r÷ | rë | n d g } n | r| n	 d d g } t | ƒ } | d k rM|  j j d t t | ƒ d ƒ ƒ n  t | | | | | | |	 |
 | | |  j ƒ d  S(   NRM   RZ   R;   R“   R   R<   R:   R©   t   CVSs   .*s   *~R”   R•   R~   RJ   t   jsR   t   txti   s(   examining files with the extensions: %s
t   and(	   t   getRŽ   t   listR   R   R   R7   R   RŸ   (   t   selft   argst   optionsRM   RZ   R;   t   process_allR   R<   R:   R”   R•   R~   t   exts(    (    sE   ../Django//lib/python/django/core/management/commands/makemessages.pyt   handle_noargsp  s,    N(   t   __name__t
   __module__R   t   option_listR   R‡   RH   R"   R£   t   requires_model_validationt   can_import_settingsRµ   (    (    (    sE   ../Django//lib/python/django/core/management/commands/makemessages.pyR    O  s4   (   s   html(   R	   (&   RF   R‘   R#   R   R‹   t	   itertoolsR    t   optparseR   t
   subprocessR   R   RK   t   django.core.management.baseR   R   t   django.utils.textR   t   django.utils.jslexR   t   compilet	   MULTILINEt   DOTALLRT   Rp   R   R+   R   RH   RE   R2   Rc   Rk   R{   R   R‡   RŸ   R    (    (    (    sE   ../Django//lib/python/django/core/management/commands/makemessages.pyt   <module>   s2   				F	0V