ó
jdQc           @   sM   d  d l  Z  d  d l Z d Z d d d „  ƒ  YZ d d „ Z d d „ Z d S(   iÿÿÿÿNs-   /usr/share/language-selector/data/pkg_dependst   LanguageSupportc           B   s•   e  Z d Z d d d  „ Z e d „ Z e d „ Z e d „ Z e d „ Z	 d „  Z
 d „  Z d „  Z e d „  ƒ Z e d	 „  ƒ Z e d
 „  ƒ Z RS(   c         C   sC   | d  k r t j ƒ  |  _ n	 | |  _ |  j | p6 t ƒ |  _ d  S(   N(   t   Nonet   aptt   Cachet	   apt_cachet   _parse_pkg_dependst   DEFAULT_DEPENDS_FILEt   pkg_depends(   t   selfR   t   depends_file(    (    s9   /usr/lib/python2.7/dist-packages/language_support_pkgs.pyt   __init__   s
    	c         C   s  g  } |  j  j | i  ƒ } xY | j |  j | ƒ i  ƒ j ƒ  D]6 } x- | D]% } | |  j k rJ | j | ƒ qJ qJ Wq= Wxm | j d i  ƒ j ƒ  D]S } xJ | D]B }	 x9 |  j |	 | ƒ D]% }
 |
 |  j k r¶ | j |
 ƒ q¶ q¶ Wq Wq W| sg  | D] } |  j | j sô | ^ qô } n  | S(   sˆ  Get language support packages for a package and locale.

        Note that this does not include support packages which are not specific
        to a particular trigger package, e. g. general language packs. To get
        those, call this with package==''.

        By default, only return packages which are not installed. If installed
        is True, return all packages instead.
        t    (   R   t   gett   _langcode_from_localet   valuesR   t   appendt   _expand_pkg_patternt	   installed(   R   t   packaget   localeR   t   packagest   depmapt   pkglistt   pt   pattern_listt   patternt   pkg_candidate(    (    s9   /usr/lib/python2.7/dist-packages/language_support_pkgs.pyt   by_package_and_locale   s    
(,c         C   sq   g  } xd |  j  D]Y } y< | d k s5 |  j | j rQ | |  j | | | ƒ 7} n  Wq t k
 rh q q Xq W| S(   sŸ  Get language support packages for a locale.

        Return all packages which need to be installed in order to provide
        language support for the given locale for all already installed
        packages. This should be called after adding a new locale to the
        system.

        By default, only return packages which are not installed. If installed
        is True, return all packages instead.
        R   (   R   R   R   R   t   KeyError(   R   R   R   R   t   trigger(    (    s9   /usr/lib/python2.7/dist-packages/language_support_pkgs.pyt	   by_locale3   s     c         C   s@   t  ƒ  } x0 |  j ƒ  D]" } | j |  j | | | ƒ ƒ q W| S(   s:  Get language support packages for a package.

        This will install language support for that package for all available
        system languages. This is a wrapper around available_languages() and
        by_package_and_locale().

        Note that this does not include support packages which are not specific
        to a particular trigger package, e. g. general language packs. To get
        those, call this with package==''.

        By default, only return packages which are not installed. If installed
        is True, return all packages instead.
        (   t   sett   available_languagest   updateR   (   R   R   R   R   t   lang(    (    s9   /usr/lib/python2.7/dist-packages/language_support_pkgs.pyt
   by_packageI   s    	 c         C   sF   t  ƒ  } x- |  j ƒ  D] } | j |  j | | ƒ ƒ q W|  j | ƒ S(   sL  Get language support packages for current system.

        Return all packages which need to be installed in order to provide
        language support all system locales for all already installed
        packages. This should be called after installing the system without
        language support packages (perhaps because there was no network
        available to download them).

        This is a wrapper around available_languages() and by_locale().

        By default, only return packages which are not installed. If installed
        is True, return all packages instead.
        (   R   R    R!   R   t   _hunspell_frami_special(   R   R   R   R"   (    (    s9   /usr/lib/python2.7/dist-packages/language_support_pkgs.pyt   missing\   s    	c         C   sº   g  } x] d d d g D]L } d | d } y$ |  j  | j rM | j | ƒ n  Wq t k
 ra q Xq Wt | ƒ d k r| | St ƒ  } x. | D]& } | d | k rŒ | j | ƒ qŒ qŒ W| S(   sy    Ignore missing hunspell-de-xx if hunspell-de-xx-frami is installed.

        https://launchpad.net/bugs/1103547
        t   det   att   chs   hunspell-de-s   -framii    (   R   R   R   R   t   lenR   t   add(   R   R   t   framist   countryt   framit   packages_newt   pack(    (    s9   /usr/lib/python2.7/dist-packages/language_support_pkgs.pyR$   o   s    	c         C   su   t  ƒ  } t j d g d t ƒ} xM | j ƒ  D]? } | j | ƒ | j d ƒ s. | j | j d ƒ d ƒ q. q. W| S(   s¥   List available languages in the system.

        The list items can be passed as the "locale" argument of by_locale(),
        by_package_and_locale(), etc.
        s*   /usr/share/language-tools/language-optionst   universal_newlinest   zh_t   _i    (   R   t
   subprocesst   check_outputt   Truet   splitR*   t
   startswith(   R   t	   languagest   lang_stringR"   (    (    s9   /usr/lib/python2.7/dist-packages/language_support_pkgs.pyR    „   s    			!c   	   
   C   s¤   i  } t  | ƒ Œ } x‚ | D]z } | j ƒ  } | s | j d ƒ rJ q n  | j d ƒ \ } } } } | j | i  ƒ j | i  ƒ j | g  ƒ j | ƒ q WWd QX| S(   sq   Parse pkg_depends file.

        Return trigger_package -> langcode -> category -> [dependency,...] map.
        t   #t   :N(   t   opent   stripR7   R6   t
   setdefaultR   (	   R   t   filenamet   mapt   ft   linet   catt   lcR   t   dep(    (    s9   /usr/lib/python2.7/dist-packages/language_support_pkgs.pyR   —   s    !c         C   sI   | j  d ƒ s | j  d ƒ r" d S| j  d ƒ r5 d S| j d d ƒ d S(	   s:   Turn a locale name into a language code as in pkg_depends.t   zh_CNt   zh_SGs   zh-hansR1   s   zh-hantR2   i   i    (   R7   R6   (   t   klassR   (    (    s9   /usr/lib/python2.7/dist-packages/language_support_pkgs.pyR   ©   s
    c         C   sã  | d k r d } n | d k r* d } n  | j  d d ƒ d j ƒ  } d } d } yC | j  d d ƒ \ } } d	 | k r” | j  d	 d ƒ \ } } n  Wn t k
 r® | } n X| d
 | | f g } | r| j d | | | f ƒ | j d | | | f ƒ nN xK |  j | ƒ D]: } | j d | | | f ƒ | j d | | | f ƒ qW| rs| j d | | | f ƒ n  | rŸ| rŸ| j d | | | | f ƒ n  | d k rß| d k rË| j | d ƒ qß| j | d ƒ n  | S(   s9   Return all possible suffixes for given pattern and locales   zh-hansRF   s   zh-hantt   zh_TWt   .i   i    R2   t   @s   %s%ss   %s%s%ss   %s%s-%ss
   %s%s-%s-%st   zht   cnt   sgN(   RM   RN   (   R6   t   lowerR   t
   ValueErrorR   t   _countries_for_lang(   RH   R   R   t   variantR,   R"   t   pkgs(    (    s9   /usr/lib/python2.7/dist-packages/language_support_pkgs.pyR   ·   s<    		
 c      
   C   s  |  j  d	 k rî i  |  _  t d ƒ Å } x» | D]³ } | j d d ƒ d j d ƒ d } | sc q. n  | j d d ƒ d j d ƒ d } y | j d ƒ \ } } Wn t k
 rµ q. n X| j ƒ  } |  j  j | t ƒ  ƒ j | ƒ q. WWd	 QXn  |  j  j	 | g  ƒ S(
   s-   Return a list of countries for given languages   /usr/share/i18n/SUPPORTEDR:   i   i    t    RJ   RK   R2   N(
   t   lang_country_mapR   R<   R6   RP   RO   R>   R   R*   R   (   RH   R"   RA   RB   t   lt   c(    (    s9   /usr/lib/python2.7/dist-packages/language_support_pkgs.pyRQ   æ   s    	##,N(   t   __name__t
   __module__R   RU   R
   t   FalseR   R   R#   R%   R$   R    R   t   classmethodR   R   RQ   (    (    (    s9   /usr/lib/python2.7/dist-packages/language_support_pkgs.pyR       s   				/c         C   s}   t  | | ƒ } t ƒ  } x9 | j ƒ  D]+ } | j r% | j | j | j ƒ ƒ q% q% Wx" | D] } | | j d t ƒ q[ Wd S(   sC  Add language support for packages marked for installation.
    
    For all packages which are marked for installation in the given apt.Cache()
    object, mark the corresponding language packs and support packages for
    installation as well.

    This function can be used as an aptdaemon modify_cache_after plugin.
    t	   from_userN(	   R    R   t   get_changest   marked_installR!   R#   t   namet   mark_installRZ   (   t   resolvert   cacheR	   t   lst   support_pkgst   pkg(    (    s9   /usr/lib/python2.7/dist-packages/language_support_pkgs.pyt   apt_cache_add_language_packsü   s    			 c         C   s{   | j  d ƒ s" t d | ƒ ‚ n  | j d d ƒ d d  } t |  | ƒ } | j | d t ƒ} g  | D] } |  | ^ qg S(   s,   PackageKit WhatProvides plugin for locale().s   locale(s   cannot handle query type t   (i   iÿÿÿÿR   (   R7   t   NotImplementedErrorR6   R    R   R5   (   Rb   t   typet   searchR	   R   Rc   RS   R   (    (    s9   /usr/lib/python2.7/dist-packages/language_support_pkgs.pyt   packagekit_what_provides_locale  s    (    (   R   R3   R   R    R   Rf   Rk   (    (    (    s9   /usr/lib/python2.7/dist-packages/language_support_pkgs.pyt   <module>   s
   ô