
Tc           @   sR  d  Z  d d l m Z d d l m Z d d l m Z d d l m Z d d l m	 Z	 m
 Z
 d d l m Z d d l Z d d	 l m Z d d l Z d d l Z d d l Z d d
 l m 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 d d l m Z d d l m  Z  m! Z! m" Z" d d l# m$ Z$ d d l% m& Z& m' Z' d d l( m) Z) d d l* m+ Z+ m, Z, d d d d d d g Z- d Z. d e f d     YZ/ d e f d     YZ0 d   Z1 d e f d     YZ2 d e f d     YZ3 d e4 f d      YZ5 d!   Z6 e7 d"  Z8 g  d#  Z9 e: d$ k rNe6   n  d S(%   s3   Frontends for the message extraction functionality.i(   t   RawConfigParser(   t   datetime(   t   log(   t   Command(   t   DistutilsOptionErrort   DistutilsSetupError(   t   getpreferredencodingN(   t   OptionParser(   t   StringIO(   t   __version__(   t   Localet
   localedata(   t   UnknownLocaleError(   t   Catalog(   t   extract_from_dirt   DEFAULT_KEYWORDSt   DEFAULT_MAPPING(   t   write_mo(   t   read_pot   write_po(   t   PLURALS(   t   odictt   LOCALTZt   CommandLineInterfacet   compile_catalogt   extract_messagest   init_catalogt   check_message_extractorst   update_catalogs   restructuredtext enc        	   B   sV   e  Z d  Z d Z d d d d d d d  g Z d d g Z d   Z d   Z d   Z	 RS(!   s  Catalog compilation command for use in ``setup.py`` scripts.

    If correctly installed, this command is available to Setuptools-using
    setup scripts automatically. For projects using plain old ``distutils``,
    the command needs to be registered explicitly in ``setup.py``::

        from babel.messages.frontend import compile_catalog

        setup(
            ...
            cmdclass = {'compile_catalog': compile_catalog}
        )

    :since: version 0.9
    :see: `Integrating new distutils commands <http://docs.python.org/dist/node32.html>`_
    :see: `setuptools <http://peak.telecommunity.com/DevCenter/setuptools>`_
    s+   compile message catalogs to binary MO filess   domain=t   Ds&   domain of PO file (default 'messages')s
   directory=t   ds.   path to base directory containing the catalogss   input-file=t   is   name of the input files   output-file=t   osQ   name of the output file (default '<output_dir>/<locale>/LC_MESSAGES/<domain>.po')s   locale=t   ls    locale of the catalog to compiles	   use-fuzzyt   fs   also include fuzzy translationst
   statisticss#   print statistics about translationsc         C   sC   d |  _  d  |  _ d  |  _ d  |  _ d  |  _ t |  _ t |  _ d  S(   Nt   messages(	   t   domaint   Nonet	   directoryt
   input_filet   output_filet   localet   Falset	   use_fuzzyR#   (   t   self(    (    s;   /usr/lib/python2.7/site-packages/babel/messages/frontend.pyt   initialize_optionsV   s    						c         C   sJ   |  j  r# |  j r# t d   n  |  j rF |  j rF t d   n  d  S(   Ns<   you must specify either the input file or the base directory(   R(   R'   R   R)   (   R-   (    (    s;   /usr/lib/python2.7/site-packages/babel/messages/frontend.pyt   finalize_options_   s    c      	   C   s@  g  } g  } |  j  s!|  j r | j |  j t j j |  j |  j d |  j d  f  | j t j j |  j |  j d |  j d   qx t j |  j  D] } t j j |  j | d |  j d  } t j j	 |  r | j | | f  | j t j j |  j | d |  j d   q q Wnd | j |  j |  j  f  |  j
 rV| j |  j
  n/ | j t j j |  j |  j d |  j d   | st d   n  xt |  D]\ } \ } } | | } t | d  } z t | |  } Wd  | j   X|  j r~d }	 x. t |  d D] }
 |
 j r|	 d 7}	 qqWd } t |  r\|	 d t |  } n  t j d	 |	 t |  | |  n  | j r|  j rt j d
 |  qn  xD | j   D]6 \ }
 } x' | D] } t j d | |
 j |  qWqWt j d | |  t | d  } z t | | d |  j Wd  | j   XqWd  S(   Nt   LC_MESSAGESs   .pos   .mos   no message catalogs foundt   ri    i   id   s)   %d of %d messages (%d%%) translated in %rs'   catalog %r is marked as fuzzy, skippings   error: %s:%d: %ss   compiling catalog %r to %rt   wbR,   (   R(   R*   t   appendt   ost   patht   joinR'   R%   t   listdirt   existsR)   R   t	   enumeratet   openR   t   closeR#   t   listt   stringt   lenR   t   infot   fuzzyR,   t   warnt   checkt   errort   linenoR   (   R-   t   po_filest   mo_filesR*   t   po_filet   idxt   mo_filet   infilet   catalogt
   translatedt   messaget
   percentaget   errorsRC   t   outfile(    (    s;   /usr/lib/python2.7/site-packages/babel/messages/frontend.pyt   rung   sn    			
			(   s   domain=R   s&   domain of PO file (default 'messages')(   s
   directory=R   s.   path to base directory containing the catalogs(   s   input-file=R   s   name of the input file(   s   output-file=R    sQ   name of the output file (default '<output_dir>/<locale>/LC_MESSAGES/<domain>.po')(   s   locale=R!   s    locale of the catalog to compile(   s	   use-fuzzyR"   s   also include fuzzy translationsN(   s
   statisticsNs#   print statistics about translations(
   t   __name__t
   __module__t   __doc__t   descriptionR&   t   user_optionst   boolean_optionsR.   R/   RQ   (    (    (    s;   /usr/lib/python2.7/site-packages/babel/messages/frontend.pyR   /   s(          				c           B   s   e  Z d  Z d Z d, d- d. d/ d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 d: d; g Z d d d d d d d# g Z d'   Z d(   Z d)   Z	 d*   Z
 RS(<   sj  Message extraction command for use in ``setup.py`` scripts.

    If correctly installed, this command is available to Setuptools-using
    setup scripts automatically. For projects using plain old ``distutils``,
    the command needs to be registered explicitly in ``setup.py``::

        from babel.messages.frontend import extract_messages

        setup(
            ...
            cmdclass = {'extract_messages': extract_messages}
        )

    :see: `Integrating new distutils commands <http://docs.python.org/dist/node32.html>`_
    :see: `setuptools <http://peak.telecommunity.com/DevCenter/setuptools>`_
    s1   extract localizable strings from the project codes   charset=s!   charset to use in the output files	   keywords=t   ksH   space-separated list of keywords to look for in addition to the defaultss   no-default-keywordss#   do not include the default keywordss   mapping-file=t   Fs&   path to the mapping configuration files   no-locations>   do not include location comments with filename and line numbers   omit-headers'   do not include msgid "" entry in headers   output-file=R    s   name of the output files   width=t   ws"   set output line width (default 76)s   no-wrapsV   do not break long message lines, longer than the output line width, into several liness   sort-outputs&   generate sorted output (default False)s   sort-by-files,   sort output by file location (default False)s   msgid-bugs-address=s   set report address for msgids   copyright-holder=s   set copyright holder in outputs   add-comments=t   csu   place comment block with TAG (or those preceding keyword lines) in output file. Seperate multiple TAGs with commas(,)s   strip-commentss)   strip the comment TAGs from the comments.s   input-dirs=s/   directories that should be scanned for messagesc         C   s   d |  _  d |  _ t j   |  _ t |  _ d  |  _ t |  _	 t |  _
 d  |  _ d  |  _ d  |  _ t |  _ t |  _ t |  _ d  |  _ d  |  _ d  |  _ g  |  _ t |  _ d  S(   Ns   utf-8t    (   t   charsett   keywordsR   t   copyt	   _keywordsR+   t   no_default_keywordsR&   t   mapping_filet   no_locationt   omit_headerR)   t
   input_dirst   widtht   no_wrapt   sort_outputt   sort_by_filet   msgid_bugs_addresst   copyright_holdert   add_commentst   _add_commentst   strip_comments(   R-   (    (    s;   /usr/lib/python2.7/site-packages/babel/messages/frontend.pyR.      s$    																c      
   C   sr  |  j  r" |  j r" t d   n  |  j  r7 i  |  _ n  |  j rb |  j j t |  j j     n  |  j sz t d   n  |  j r |  j	 r t d   n  |  j r |  j	 r d |  _	 n$ |  j	 d  k	 r t |  j	  |  _	 n  |  j r |  j r t d   n  |  j sMt j g  |  j j D] } | j d d  d ^ q j   |  _ n  |  j rn|  j j d	  |  _ n  d  S(
   Ns=   you must specify new keywords if you disable the default oness   no output file specifieds0   '--no-wrap' and '--width' are mutually exclusiveiL   s;   '--sort-output' and '--sort-by-file' are mutually exclusivet   .i   i    t   ,(   Ra   R^   R   R`   t   updatet   parse_keywordst   splitR)   Rg   Rf   R&   t   intRh   Ri   Re   t   dictt   fromkeyst   distributiont   packagest   keysRl   Rm   (   R-   RX   (    (    s;   /usr/lib/python2.7/site-packages/babel/messages/frontend.pyR/      s*    		"			;	c            s  |  j    } t |  j d  } zYt d |  j j   d |  j j   d |  j d |  j d |  j	  } x | j
   D] \   \ } }   f d   } t   | | d |  j d	 |  j d
 | d |  j } x] | D]U \ } }	 }
 } t j j t j j   |   } | j |
 d  | |	 f g d | q Wqp Wt j d |  j  t | | d |  j d |  j d |  j d |  j d |  j Wd  | j   Xd  S(   NRZ   t   projectt   versionRj   Rk   R]   c            s   | d k r d  St  j j t  j j   |    } d } | r| d d j g  | j   D] \ } } d | | f ^ qS  } n  t j d | |  d  S(   Nt   ignoreR\   s    (%s)s   , s   %s="%s"s   extracting messages from %s%s(   R4   R5   t   normpathR6   t   itemsR   R?   (   t   filenamet   methodt   optionst   filepatht   optstrRX   t   v(   t   dirname(    s;   /usr/lib/python2.7/site-packages/babel/messages/frontend.pyt   callback)  s    !3R^   t   comment_tagsR   t   strip_comment_tagst   auto_commentss   writing PO template file to %sRf   Rc   Rd   Rh   Ri   (   t   _get_mappingsR:   R)   R   Rw   t   get_namet   get_versionRj   Rk   R]   R~   R   R`   Rm   Rn   R4   R5   R}   R6   t   addR&   R   R?   R   Rf   Rc   Rd   Rh   Ri   R;   (   R-   t   mappingsRP   RK   t
   method_mapt   options_mapR   t	   extractedR   RD   RM   t   commentsR   (    (   R   s;   /usr/lib/python2.7/site-packages/babel/messages/frontend.pyRQ     s4    		
		!			c         C   sY  i  } |  j  rl t |  j  d  } z: t |  \ } } x! |  j D] } | | f | | <q@ WWd  | j   Xn t |  j d d   r1|  j j } x | j	   D] \ } } t
 | t  r t t |   \ } } nJ g  i  } } x: | D]2 \ } }	 }
 | j | |	 f  |
 pi  | | <q W| | f | | <q Wn$ x! |  j D] } t i  f | | <q;W| S(   Nt   Ut   message_extractors(   Rb   R:   t   parse_mappingRe   R;   t   getattrRw   R&   R   R~   t
   isinstancet
   basestringR   R3   R   (   R-   R   t   fileobjR   R   R   R   t   mappingt   patternR   R   (    (    s;   /usr/lib/python2.7/site-packages/babel/messages/frontend.pyR   G  s*    	N(   s   charset=Ns!   charset to use in the output file(   s	   keywords=RX   sH   space-separated list of keywords to look for in addition to the defaults(   s   no-default-keywordsNs#   do not include the default keywords(   s   mapping-file=RY   s&   path to the mapping configuration file(   s   no-locationNs>   do not include location comments with filename and line number(   s   omit-headerNs'   do not include msgid "" entry in header(   s   output-file=R    s   name of the output file(   s   width=RZ   s"   set output line width (default 76)(   s   no-wrapNsV   do not break long message lines, longer than the output line width, into several lines(   s   sort-outputNs&   generate sorted output (default False)(   s   sort-by-fileNs,   sort output by file location (default False)(   s   msgid-bugs-address=Ns   set report address for msgid(   s   copyright-holder=Ns   set copyright holder in output(   s   add-comments=R[   su   place comment block with TAG (or those preceding keyword lines) in output file. Seperate multiple TAGs with commas(,)(   s   strip-commentsNs)   strip the comment TAGs from the comments.(   s   input-dirs=Ns/   directories that should be scanned for messages(   RR   RS   RT   RU   R&   RV   RW   R.   R/   RQ   R   (    (    (    s;   /usr/lib/python2.7/site-packages/babel/messages/frontend.pyR      sP                   				)c         C   s4   | d k s t   t | t  s0 t d   n  d S(   s  Validate the ``message_extractors`` keyword argument to ``setup()``.

    :param dist: the distutils/setuptools ``Distribution`` object
    :param name: the name of the keyword argument (should always be
                 "message_extractors")
    :param value: the value of the keyword argument
    :raise `DistutilsSetupError`: if the value is not valid
    :see: `Adding setup() arguments
           <http://peak.telecommunity.com/DevCenter/setuptools#adding-setup-arguments>`_
    R   sD   the value of the "message_extractors" parameter must be a dictionaryN(   t   AssertionErrorR   Ru   R   (   t   distt   namet   value(    (    s;   /usr/lib/python2.7/site-packages/babel/messages/frontend.pyR   f  s    c           B   sD   e  Z d  Z d Z d d d d d g Z d   Z d   Z d   Z RS(   sf  New catalog initialization command for use in ``setup.py`` scripts.

    If correctly installed, this command is available to Setuptools-using
    setup scripts automatically. For projects using plain old ``distutils``,
    the command needs to be registered explicitly in ``setup.py``::

        from babel.messages.frontend import init_catalog

        setup(
            ...
            cmdclass = {'init_catalog': init_catalog}
        )

    :see: `Integrating new distutils commands <http://docs.python.org/dist/node32.html>`_
    :see: `setuptools <http://peak.telecommunity.com/DevCenter/setuptools>`_
    s(   create a new catalog based on a POT files   domain=R   s&   domain of PO file (default 'messages')s   input-file=R   s   name of the input files   output-dir=R   s   path to output directorys   output-file=R    sQ   name of the output file (default '<output_dir>/<locale>/LC_MESSAGES/<domain>.po')s   locale=R!   s$   locale for the new localized catalogc         C   s1   d  |  _ d  |  _ d  |  _ d  |  _ d |  _ d  S(   NR$   (   R&   t
   output_dirR)   R(   R*   R%   (   R-   (    (    s;   /usr/lib/python2.7/site-packages/babel/messages/frontend.pyR.     s
    				c         C   s	  |  j  s t d   n  |  j s0 t d   n  y t j |  j  |  _ Wn t k
 rj } t |   n X|  j r |  j r t d   n  |  j s t	 j
 j |  j |  j d |  j d  |  _ n  t	 j
 j t	 j
 j |  j   st	 j t	 j
 j |  j   n  d  S(   Ns   you must specify the input files-   you must provide a locale for the new catalogs%   you must specify the output directoryR0   s   .po(   R(   R   R*   R
   t   parset   _localeR   R)   R   R4   R5   R6   R%   R8   R   t   makedirs(   R-   t   e(    (    s;   /usr/lib/python2.7/site-packages/babel/messages/frontend.pyR/     s    			!c         C   s   t  j d |  j |  j  t |  j d  } z t | d |  j } Wd  | j   X|  j | _ t	 | _
 t |  j d  } z t | |  Wd  | j   Xd  S(   Ns   creating catalog %r based on %rR1   R*   RZ   (   R   R?   R)   R(   R:   R   R*   R;   R   R+   R@   R   (   R-   RJ   RK   RP   (    (    s;   /usr/lib/python2.7/site-packages/babel/messages/frontend.pyRQ     s    
	(   s   domain=R   s&   domain of PO file (default 'messages')(   s   input-file=R   s   name of the input file(   s   output-dir=R   s   path to output directory(   s   output-file=R    sQ   name of the output file (default '<output_dir>/<locale>/LC_MESSAGES/<domain>.po')(   s   locale=R!   s$   locale for the new localized catalog(   RR   RS   RT   RU   RV   R.   R/   RQ   (    (    (    s;   /usr/lib/python2.7/site-packages/babel/messages/frontend.pyR   w  s        			c        
   B   s\   e  Z d  Z d Z d d d d  d! d# d$ d% g Z d d d g Z d   Z d   Z d   Z	 RS(&   sy  Catalog merging command for use in ``setup.py`` scripts.

    If correctly installed, this command is available to Setuptools-using
    setup scripts automatically. For projects using plain old ``distutils``,
    the command needs to be registered explicitly in ``setup.py``::

        from babel.messages.frontend import update_catalog

        setup(
            ...
            cmdclass = {'update_catalog': update_catalog}
        )

    :since: version 0.9
    :see: `Integrating new distutils commands <http://docs.python.org/dist/node32.html>`_
    :see: `setuptools <http://peak.telecommunity.com/DevCenter/setuptools>`_
    s'   update message catalogs from a POT files   domain=R   s&   domain of PO file (default 'messages')s   input-file=R   s   name of the input files   output-dir=R   s.   path to base directory containing the catalogss   output-file=R    sQ   name of the output file (default '<output_dir>/<locale>/LC_MESSAGES/<domain>.po')s   locale=R!   s    locale of the catalog to compiles   ignore-obsolete=s1   whether to omit obsolete messages from the outputs   no-fuzzy-matchingt   Ns   do not use fuzzy matchingt   previouss+   keep previous msgids of translated messagest   ignore_obsoletet   no_fuzzy_matchingc         C   sL   d |  _  d  |  _ d  |  _ d  |  _ d  |  _ t |  _ t |  _ t |  _	 d  S(   NR$   (
   R%   R&   R(   R   R)   R*   R+   R   R   R   (   R-   (    (    s;   /usr/lib/python2.7/site-packages/babel/messages/frontend.pyR.     s    							c         C   s   |  j  s t d   n  |  j r; |  j r; t d   n  |  j r] |  j r] t d   n  |  j r{ |  j r{ t |  _ n  d  S(   Ns   you must specify the input files-   you must specify the output file or directorys   you must specify the locale(   R(   R   R)   R   R*   R   R   R+   (   R-   (    (    s;   /usr/lib/python2.7/site-packages/babel/messages/frontend.pyR/     s    	c         C   s  g  } |  j  s |  j rS | j |  j t j j |  j |  j d |  j d  f  q x t j |  j  D]S } t j j |  j | d |  j d  } t j j	 |  rf | j | | f  qf qf Wn | j |  j |  j  f  |  j } | st j j
 t j j |  j   d } n  t |  j d  } z t |  } Wd  | j   X| sUt d   n  x]| D]U\ } } t j d | |  j  t | d  } z t | d | d | } Wd  | j   X| j | |  j  t j j t j j |  t j   t j j |   }	 t |	 d	  }
 y5 z# t |
 | d
 |  j d |  j Wd  |
 j   XWn t j |	    n Xy t j |	 |  Wq\t k
 rt j |  t j |	 |  t j |	  q\Xq\Wd  S(   NR0   s   .poi    R   s   no message catalogs founds   updating catalog %r based on %rR*   R%   RZ   R   t   include_previous(    R)   R*   R3   R4   R5   R6   R   R%   R7   R8   t   splitextt   basenameR(   R:   R   R;   R   R   R?   Rq   R   R   t   tempfilet   gettempprefixR   R   R   t   removet   renamet   OSErrort   shutilR_   (   R-   RE   R*   RG   R%   RJ   t   templateR   RK   t   tmpnamet   tmpfile(    (    s;   /usr/lib/python2.7/site-packages/babel/messages/frontend.pyRQ     sd    			(
		(   s   domain=R   s&   domain of PO file (default 'messages')(   s   input-file=R   s   name of the input file(   s   output-dir=R   s.   path to base directory containing the catalogs(   s   output-file=R    sQ   name of the output file (default '<output_dir>/<locale>/LC_MESSAGES/<domain>.po')(   s   locale=R!   s    locale of the catalog to compileN(   s   ignore-obsolete=Ns1   whether to omit obsolete messages from the output(   s   no-fuzzy-matchingR   s   do not use fuzzy matching(   s   previousNs+   keep previous msgids of translated messages(
   RR   RS   RT   RU   R&   RV   RW   R.   R/   RQ   (    (    (    s;   /usr/lib/python2.7/site-packages/babel/messages/frontend.pyR     s,           		
	c           B   s   e  Z d  Z d Z d e Z i d d 6d d 6d d 6d	 d
 6Z e j d  Z	 d   Z
 d   Z d   Z d   Z d   Z d   Z RS(   s   Command-line interface.

    This class provides a simple command-line interface to the message
    extraction and PO file generation functionality.
    s   %%prog %s [options] %ss	   %%prog %ss$   compile message catalogs to MO filest   compiles:   extract messages from source files and generate a POT filet   extracts+   create new message catalogs from a POT filet   inits0   update existing message catalogs from a POT fileRq   c         C   s  t  d |  j d d |  j  |  _ |  j j   |  j |  j _ |  j j d d d d d	 d
 d |  j j d d d d d d d t j	 d
 d |  j j d d d d d d d t j
 d
 d |  j j d t d t j  |  j j | d  \ } } |  j | j  | j rt j   } t g  | D] } t |  ^ q# } | j   d | d } xV | D]N } t j |  } | | | j f }	 |	 j t j j pt   pd d  GHq]Wd S| s|  j j d  n  | d }
 |
 |  j  k r|  j j d |
  n  t! |  |
  | d  S(   s{   Main entry point of the command-line interface.

        :param argv: list of arguments passed on the command-line
        t   usaget   commands   [args]R{   s   --list-localest   destt   list_localest   actiont
   store_truet   helps    print all known locales and exits   -vs	   --verboset   store_constt   loglevelt   consts   print as much as possibles   -qs   --quiets   print as little as possiblei   u
   %%-%ds %%st   asciit   replacei    sQ   no valid command or option passed. Try the -h/--help option for more information.s   unknown command "%s"(   s   commands   [args]("   R   R   R{   t   parsert   disable_interspersed_argst   _helpt
   print_helpt
   add_optiont   loggingt   DEBUGt   ERRORt   set_defaultsR+   t   INFOt
   parse_argst   _configure_loggingR   R   R   R<   t   maxR>   t   sortR
   R   t   english_namet   encodet   syst   stdoutt   encodingR   RC   t   commandsR   (   R-   t   argvR   t   argst   identifierst
   identifiert   longestt   formatR*   t   outputt   cmdname(    (    s;   /usr/lib/python2.7/site-packages/babel/messages/frontend.pyRQ   ^  sD    	%
	
c         C   s   t  j d  |  _ |  j j |  |  j j rA |  j j d } n t  j   } |  j j |  | j |  t  j d  } | j |  d  S(   Nt   babeli    s   %(message)s(	   R   t	   getLoggerR   t   setLevelt   handlerst   StreamHandlert
   addHandlert	   Formattert   setFormatter(   R-   R   t   handlert	   formatter(    (    s;   /usr/lib/python2.7/site-packages/babel/messages/frontend.pyR     s    c         C   s   |  j  j   GHd GHt g  |  j D] } t |  ^ q   } d t d | d  } |  j j   } | j   x# | D] \ } } | | | f GHqr Wd  S(   Ns	   commands:s     %%-%ds %%si   i   (   R   t   format_helpR   R   R>   R~   R   (   R-   R   R   R   R   R   RU   (    (    s;   /usr/lib/python2.7/site-packages/babel/messages/frontend.pyR     s    (
c      	   C   s  t  d |  j d9 d |  j d  } | j d d d d d	 d
 | j d d d d d d d	 d | j d d d d d d d	 d | j d d d d d d d	 d | j d d d d d d d	 d | j d d  d d! d" d# d	 d$ | j d% d d& d" d# d	 d' | j d d( d! t d) t d& t  | j |  \ } } g  } g  } | j sy| j sm| j	 d*  n  | j
 r| j | j
 t j j | j | j
 d+ | j d,  f  | j t j j | j | j
 d+ | j d-   qxt j | j  D] } t j j | j | d+ | j d,  } t j j |  r| j | | f  | j t j j | j | d+ | j d-   qqWn} | j | j
 | j f  | j r| j | j  nH | j s| j	 d*  n  | j t j j | j | j
 d+ | j d-   | s| j	 d.  n  xt |  D]\ }	 \ } } | |	 }
 t | d/  } z t | |  } Wd0 | j   X| j rd1 } x. t |  d2 D] } | j r| d2 7} qqWd1 } t |  r| d3 t |  } n  |  j j d4 | t |  | |  n  | j r| j r|  j j d5 |  qn  xG | j    D]9 \ } } x* | D]" } |  j j	 d6 | | j! |  q?Wq,W|  j j d7 | |
  t |
 d8  } z t" | | d! | j Wd0 | j   XqWd0 S(:   s   Subcommand for compiling a message catalog to a MO file.

        :param argv: the command arguments
        :since: version 0.9
        R   R   R\   RU   s   --domains   -DR   R%   R   s.   domain of MO and PO files (default '%default')s   --directorys   -dR'   t   metavart   DIRs   base directory of catalog filess   --locales   -lR*   t   LOCALEs   locale of the catalogs   --input-files   -iR(   t   FILEs   name of the input files   --output-files   -oR)   sQ   name of the output file (default '<output_dir>/<locale>/LC_MESSAGES/<domain>.mo')s   --use-fuzzys   -fR,   R   R   s2   also include fuzzy translations (default %default)s   --statisticsR#   s#   print statistics about translationsR$   t   compile_alls<   you must specify either the input file or the base directoryR0   s   .pos   .mos   no message catalogs foundR1   Ni    i   id   s)   %d of %d messages (%d%%) translated in %rs'   catalog %r is marked as fuzzy, skippings   error: %s:%d: %ss   compiling catalog %r to %rR2   (   s   compileR\   (#   R   R   R   R   R   R+   R   R(   R'   RC   R*   R3   R4   R5   R6   R%   R7   R8   R)   R9   R:   R   R;   R#   R<   R=   R>   R   R?   R@   R,   RA   RB   RD   R   (   R-   R   R   R   R   RE   RF   R*   RG   RH   RI   RJ   RK   RL   RM   RN   RO   RC   RP   (    (    s;   /usr/lib/python2.7/site-packages/babel/messages/frontend.pyR     s    						
		c            sc  t  d  j dW d  j d  } | j d d d d d	 | j d
 d d d d d d d | j d d d d d d d | j d d d d d d | j d d d d d d d | j d d d d d d d | j d d d d  d d! | j d" d# d d$ d% d& d d' | j d( d d) d d d d* | j d+ d d, d d d d- | j d. d d/ d d d d0 | j d1 d d2 d3 d4 d d5 | j d6 d d7 d d8 | j d9 d d: d d; | j d< d d= d d> | j d? d@ d dA d3 dB d d d dC | j dD dE d dF d d d dG | j d dH d g  d t d t d t d$ dN d) t d, t d/ t dA g  dF t  | j |  \ } } | s| j dI  n  | j	 dX k rt
 | j	 dK  } n	 t j } t j   } | j r| j s| j dL  n  i  } n  | j r#| j t | j   n  | j ret
 | j dM  } z t |  \ } }	 WdN | j   Xn t } i  }	 | j r| j r| j dO  n  | j r| j rdP | _ n  | j r| j r| j dQ  n  zpt d: | j d= | j d2 | j d7 | j d | j   }
 x | D]   t! j" j#    sA| j dR    n     f dS   } t$   | |	 | | j% dT | dF | j& } x] | D]U \ } } } } t! j" j' t! j" j(   |   } |
 j) | dN | | f g dU | qWqW| j	 dY k r
 j* j+ dV | j	  n  t, | |
 d$ | j d | j- d | j. d, | j d/ | j WdN | j	 r^| j   n  XdN S(Z   s   Subcommand for extracting messages from source files and generating
        a POT file.

        :param argv: the command arguments
        R   R   s   dir1 <dir2> ...RU   s	   --charsetR   R]   R   s1   charset to use in the output (default "%default")s   -ks	   --keywordR^   R   R3   sh   keywords to look for in addition to the defaults. You can specify multiple -k flags on the command line.s   --no-default-keywordsRa   R   s#   do not include the default keywordss	   --mappings   -FRb   s#   path to the extraction mapping files   --no-locationRc   s>   do not include location comments with filename and line numbers   --omit-headerRd   s'   do not include msgid "" entry in headers   -os   --outputR   s   path to the output POT files   -ws   --widthRf   t   typeRt   s"   set output line width (default 76)s	   --no-wrapRg   sV   do not break long message lines, longer than the output line width, into several liness   --sort-outputRh   s&   generate sorted output (default False)s   --sort-by-fileRi   s,   sort output by file location (default False)s   --msgid-bugs-addressRj   R   s   EMAIL@ADDRESSs   set report address for msgids   --copyright-holderRk   s   set copyright holder in outputs	   --projectRz   s   set project name in outputs	   --versionR{   s   set project version in outputs   --add-commentss   -cR   t   TAGsi   place comment block with TAG (or those preceding keyword lines) in output file. One TAG per argument calls   --strip-comment-tagss   -sR   s)   Strip the comment tags from the comments.s   utf-8s   incorrect number of argumentst   -RZ   s=   you must specify new keywords if you disable the default onesR   Ns1   '--no-wrap' and '--width' are mutually exclusive.iL   s;   '--sort-output' and '--sort-by-file' are mutually exclusives   %r is not a directoryc            s   | d k r d  St  j j t  j j   |    } d } | r| d d j g  | j   D] \ } } d | | f ^ qS  } n   j j d | |  d  S(   NR|   R\   s    (%s)s   , s   %s="%s"s   extracting messages from %s%s(   R4   R5   R}   R6   R~   R   R?   (   R   R   R   R   R   RX   R   (   R   R-   (    s;   /usr/lib/python2.7/site-packages/babel/messages/frontend.pyR     s    !3R   R   s   writing PO template file to %s(   s   extracts   dir1 <dir2> ...(   NR   (   NR   (/   R   R   R   R   R   R+   R&   R   RC   R   R:   R   R   R   R_   Ra   R^   Rq   Rr   Rb   R   R;   R   Rf   Rg   Rh   Ri   R   Rz   R{   Rj   Rk   R]   R4   R5   t   isdirR   R   R   R}   R6   R   R   R?   R   Rc   Rd   (   R-   R   R   R   R   RP   R^   R   R   R   RK   R   R   R   RD   RM   R   R   (    (   R   R-   s;   /usr/lib/python2.7/site-packages/babel/messages/frontend.pyR     s    									!				c   
   	   C   s  t  d |  j d) d |  j d  } | j d d d d d	 d
 | j d d d d d d d	 d | j d d d d d d d	 d | j d d d d d d d	 d | j d d d d d d d	 d | j d d  | j |  \ } } | j s| j d   n  y t j	 | j  } Wn  t
 k
 r=} | j |  n X| j sW| j d!  n  | j r{| j r{| j d"  n  | j st j j | j | j d# | j d$  | _ n  t j j t j j | j   st j t j j | j   n  t | j d%  } z t | d | j } Wd& | j   X| | _ t j t  | _ |  j j d' | j | j  t | j d(  }	 z t |	 |  Wd& |	 j   Xd& S(*   sr   Subcommand for creating new message catalogs from a template.

        :param argv: the command arguments
        R   R   R\   RU   s   --domains   -DR   R%   R   s&   domain of PO file (default '%default')s   --input-files   -iR(   R   R   s   name of the input files   --output-dirs   -dR   R   s   path to output directorys   --output-files   -oR)   sQ   name of the output file (default '<output_dir>/<locale>/LC_MESSAGES/<domain>.po')s   --locales   -lR*   R   s$   locale for the new localized catalogR$   s-   you must provide a locale for the new catalogs   you must specify the input files-   you must specify the output file or directoryR0   s   .poR1   Ns   creating catalog %r based on %rRZ   (   s   initR\   (   R   R   R   R   R   R   R*   RC   R
   R   R   R(   R)   R   R4   R5   R6   R%   R8   R   R   R:   R   R;   R   t   nowR   t   revision_dateR   R?   R   (
   R-   R   R   R   R   R*   R   RJ   RK   RP   (    (    s;   /usr/lib/python2.7/site-packages/babel/messages/frontend.pyR     sV    				!	
c         C   s  t  d |  j d8 d |  j d  } | j d d d d d	 d
 | j d d d d d d d	 d | j d d d d d d d	 d | j d d d d d d d	 d | j d d d d d d d	 d | j d d d  d! d" d	 d# | j d$ d% d d& d! d" d	 d' | j d( d d) d! d" d	 d* | j d d+ d  t d& t d) t  | j |  \ } } | j sw| j d,  n  | j	 r| j
 r| j d-  n  | j	 r| j r| j d.  n  | j r| j rt | _ n  g  } | j	 s| j r/| j | j t j j | j
 | j d/ | j d0  f  qx t j | j
  D]S } t j j | j
 | d/ | j d0  } t j j |  rB| j | | f  qBqBWn | j | j | j	 f  | j } | st j j t j j | j   d1 } n  t | j d2  }	 z t |	  }
 Wd3 |	 j   X| s2| j d4  n  x`| D]X\ } } |  j j d5 | | j  t | d2  }	 z t |	 d | d | } Wd3 |	 j   X| j |
 | j  t j j t j j |  t j   t j j |   } t | d6  } y5 z# t  | | d  | j! d7 | j Wd3 | j   XWn t j" |    n Xy t j# | |  Wq9t$ k
 rt j" |  t% j& | |  t j" |  q9Xq9Wd3 S(9   s   Subcommand for updating existing message catalogs from a template.

        :param argv: the command arguments
        :since: version 0.9
        R   Rq   R\   RU   s   --domains   -DR   R%   R   s&   domain of PO file (default '%default')s   --input-files   -iR(   R   R   s   name of the input files   --output-dirs   -dR   R   s   path to output directorys   --output-files   -oR)   sQ   name of the output file (default '<output_dir>/<locale>/LC_MESSAGES/<domain>.po')s   --locales   -lR*   R   s"   locale of the translations catalogs   --ignore-obsoleteR   R   R   sA   do not include obsolete messages in the output (default %default)s   --no-fuzzy-matchings   -NR   s,   do not use fuzzy matching (default %default)s
   --previousR   s>   keep previous msgids of translated messages (default %default)R$   s   you must specify the input files-   you must specify the output file or directorys   you must specify the localeR0   s   .poi    R   Ns   no message catalogs founds   updating catalog %r based on %rRZ   R   (   s   updateR\   ('   R   R   R   R   R   R+   R   R(   RC   R)   R   R*   R   R   R3   R4   R5   R6   R%   R7   R8   R   R   R:   R   R;   R   R?   Rq   R   R   R   R   R   R   R   R   R   R_   (   R-   R   R   R   R   RE   R*   RG   R%   RJ   R   R   RK   R   R   (    (    s;   /usr/lib/python2.7/site-packages/babel/messages/frontend.pyRq     s    					(
		(   RR   RS   RT   R   t   VERSIONR{   R   R   R   RQ   R   R   R   R   R   Rq   (    (    (    s;   /usr/lib/python2.7/site-packages/babel/messages/frontend.pyR   N  s   

.		
	k		@c           C   s   t    j t j  S(   N(   R   RQ   R   R   (    (    (    s;   /usr/lib/python2.7/site-packages/babel/messages/frontend.pyt   mainQ  s    c         C   s4  i  } g  } i  } t    } t | j  | _ | j |  |  x | j   D] } | d k rt t | j |   } qJ g  | j d d  D] } | j   ^ q \ } }	 | j	 |	 | f  t | j |   | |	 <qJ W| r*xL t
 |  D]; \ }
 \ }	 } | | k r| | } n  |	 | f | |
 <q Wn  | | f S(   s]  Parse an extraction method mapping from a file-like object.

    >>> buf = StringIO('''
    ... [extractors]
    ... custom = mypackage.module:myfunc
    ... 
    ... # Python source files
    ... [python: **.py]
    ...
    ... # Genshi templates
    ... [genshi: **/templates/**.html]
    ... include_attrs =
    ... [genshi: **/templates/**.txt]
    ... template_class = genshi.template:TextTemplate
    ... encoding = latin-1
    ... 
    ... # Some custom extractor
    ... [custom: **/custom/*.*]
    ... ''')

    >>> method_map, options_map = parse_mapping(buf)
    >>> len(method_map)
    4

    >>> method_map[0]
    ('**.py', 'python')
    >>> options_map['**.py']
    {}
    >>> method_map[1]
    ('**/templates/**.html', 'genshi')
    >>> options_map['**/templates/**.html']['include_attrs']
    ''
    >>> method_map[2]
    ('**/templates/**.txt', 'genshi')
    >>> options_map['**/templates/**.txt']['template_class']
    'genshi.template:TextTemplate'
    >>> options_map['**/templates/**.txt']['encoding']
    'latin-1'

    >>> method_map[3]
    ('**/custom/*.*', 'mypackage.module:myfunc')
    >>> options_map['**/custom/*.*']
    {}

    :param fileobj: a readable file-like object containing the configuration
                    text to parse
    :return: a `(method_map, options_map)` tuple
    :rtype: `tuple`
    :see: `extract_from_directory`
    t
   extractorst   :i   (   R    R   t	   _sectionst   readfpt   sectionsRu   R~   Rs   t   stripR3   R9   (   R   R   R   R   R   R   t   sectiont   partR   R   RH   (    (    s;   /usr/lib/python2.7/site-packages/babel/messages/frontend.pyR   T  s$    3	1c         C   s   i  } x |  D] } d | k r7 | j  d  \ } } n | d } } | | k r | r t g  | j  d  D] } t |  ^ qi  } n  | | | <q q W| S(   s)  Parse keywords specifications from the given list of strings.

    >>> kw = parse_keywords(['_', 'dgettext:2', 'dngettext:2,3']).items()
    >>> kw.sort()
    >>> for keyword, indices in kw:
    ...     print (keyword, indices)
    ('_', None)
    ('dgettext', (2,))
    ('dngettext', (2, 3))
    R   Rp   N(   Rs   R&   t   tupleRt   (   t   stringsR^   R=   t   funcnamet   indicest   x(    (    s;   /usr/lib/python2.7/site-packages/babel/messages/frontend.pyRr     s    1t   __main__(;   RT   t   ConfigParserR    R   t	   distutilsR   t   distutils.cmdR   t   distutils.errorsR   R   R*   R   R   t   optparseR   R4   t   reR   R   R   R   R   R	   R   R
   R   t
   babel.coreR   t   babel.messages.catalogR   t   babel.messages.extractR   R   R   t   babel.messages.mofileR   t   babel.messages.pofileR   R   t   babel.messages.pluralsR   t
   babel.utilR   R   t   __all__t   __docformat__R   R   R   R   R   t   objectR   R   R&   R   Rr   RR   (    (    (    s;   /usr/lib/python2.7/site-packages/babel/messages/frontend.pyt   <module>   sN   		S  	J