³ò
oª9Fc           @   s±   d  d k  Z  d  d k l Z d  d k l Z d  d k Z d  d k Z d  d k l Z d  d k Z d  d k	 l
 Z
 l Z d  d k Z d  d k Z d  d k Z d d d „  ƒ  YZ d S(	   iÿÿÿÿN(   t   AptAuth(   t   gettext(   t   escape(   t   SourcesListt   SourceEntryt   SoftwarePropertiesc           B   s[  e  Z d% d% d  „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z  d „  Z! d „  Z" d  „  Z# d! „  Z$ d" „  Z% d# „  Z& d$ „  Z' RS(&   c         C   s   d |  _  | d j o
 d } n | |  _ t ƒ  |  _ t i i ƒ  |  _ g  |  _ t	 |  _
 |  i ƒ  |  i ƒ  |  i ƒ  g  |  _ t ƒ  |  _ d S(   sœ    Provides the core functionality to configure the used software 
        repositories, the corresponding authentication keys and 
        update automation s   /etc/popularity-contest.confs   /usr/share/software-properties/N(   t
   popconfilet   Nonet   datadirR   t   sourceslistt
   aptsourcest   distrot
   get_distrot   seen_servert   Falset   modified_sourceslistt   reload_sourceslistt   backup_sourceslistt   backup_apt_conft   custom_mirrorsR    t   apt_key(   t   selfR   t   options(    (    sJ   /var/lib/python-support/python2.5/softwareproperties/SoftwareProperties.pyt   __init__&   s    	
			


	c         C   sM   h  |  _  x= t i i ƒ  D], } t i i t i | ƒ } | |  i  | <q Wd S(   s$   Backup all apt configuration optionsN(   t   apt_conf_backupt   softwarepropertiest   CONF_MAPt   keyst   apt_pkgt   Configt   FindI(   R   t   optiont   value(    (    sJ   /var/lib/python-support/python2.5/softwareproperties/SoftwareProperties.pyR   C   s
    	 c         C   sO   x> |  i  i ƒ  D]- } t i i t i | t |  i  | ƒ ƒ q W|  i ƒ  d S(   s$   Restore the stored apt configurationN(	   R   R   R   R   t   SetR   R   t   strt   write_config(   R   R   (    (    sJ   /var/lib/python-support/python2.5/softwareproperties/SoftwareProperties.pyt   restore_apt_confJ   s
     c         C   s\  t  i i t i d ƒ d j oé t  i i t i d ƒ d j o+ t  i i t i d ƒ d j o t i SqXt  i i t i d ƒ d j o+ t  i i t i d ƒ d j o t i SqXt  i i t i d ƒ d j o+ t  i i t i d ƒ d j o t i SqXd SnP t  i i t i d ƒ d j o+ t  i i t i d ƒ d j o t i	 Sn d Sd S(   sÊ    Parse the apt cron configuration. Try to fit a predefined use case 
        and return it. Special case: if the user made a custom 
        configurtation, that we cannot represent it will return None t
   autoupdatei    t
   unattendedi   t   autodownloadN(
   R   R   R   R   R   t   UPDATE_INST_SECt   UPDATE_DOWNLOADt   UPDATE_NOTIFYR   t   UPDATE_MANUAL(   R   (    (    sJ   /var/lib/python-support/python2.5/softwareproperties/SoftwareProperties.pyt   get_update_automation_levelQ   s             c         C   sj  | t  i j oD t i i t  i d t d ƒ ƒ t i i t  i d t d ƒ ƒ n	| t  i j oD t i i t  i d t d ƒ ƒ t i i t  i d t d ƒ ƒ nµ | t  i j oD t i i t  i d t d ƒ ƒ t i i t  i d t d ƒ ƒ na t i i t  i d t d ƒ ƒ t i i t  i d t d ƒ ƒ t i i t  i d t d ƒ ƒ |  i	 ƒ  d S(   só    Set the apt periodic configurtation to the selected 
        update automation level. To synchronize the cache update and the 
        actual upgrading function, the upgrade function, e.g. unattended, 
        will run every day, if enabled. R&   i   R'   i    R%   N(
   R   R(   R   R   R!   R   R"   R)   R*   t   set_modified_config(   R   t   state(    (    sJ   /var/lib/python-support/python2.5/softwareproperties/SoftwareProperties.pyt   set_update_automation_levelh   s     $ $ $   c         C   sR   | t  i i t i d ƒ j p. t  i i t i d t | ƒ ƒ |  i ƒ  n d S(   s8   Set the interval in which we check for available updatesR%   N(   R   R   R   R   R   R!   R"   R-   (   R   t   days(    (    sJ   /var/lib/python-support/python2.5/softwareproperties/SoftwareProperties.pyt   set_update_interval|   s      c         C   s   t  i i t i d ƒ S(   s3    Returns the interval of the apt periodic cron job R%   (   R   R   R   R   R   (   R   (    (    sJ   /var/lib/python-support/python2.5/softwareproperties/SoftwareProperties.pyt   get_update_intervalƒ   s    c         C   sÀ   t  i i |  i ƒ o¢ t |  i ƒ i ƒ  i d ƒ } t } xs | D]k } yL | i d ƒ \ } } | d j o& | i d ƒ i	 ƒ  d j o
 t
 } n WqA t j
 o
 qA qA XqA W| Sn t Sd S(   s½    Will return True if the user wants to participate in the popularity 
        contest. Otherwise it will return False. Special case: if no 
        popcon is installed it will return False s   
t   =t   PARTICIPATEt   "t   yesN(   t   ost   patht   existsR   t   opent   readt   splitR   t   stript   lowert   Truet
   ValueError(   R   t   linest   activet   linet   keyR    (    (    sJ   /var/lib/python-support/python2.5/softwareproperties/SoftwareProperties.pyt   get_popcon_participation‡   s     )c            sð   | t  j o
 d ‰  n d ‰  t i i |  i ƒ o. t ‡  f d †  t |  i d ƒ i ƒ  ƒ } ns t i	 ƒ  } | i
 t d d ƒ i d ƒ ƒ | i ƒ  } g  } | i d | ƒ | i d t ˆ  ƒ ƒ | i d	 ƒ t |  i d
 ƒ i | ƒ d S(   s?    Enable or disable the participation in the popularity contest R6   t   noc            s   t  i d  d ˆ  |  ƒ S(   s   ^(PARTICIPATE=)(".+?")s   \1"%s"(   t   ret   sub(   RC   (   R    (    sJ   /var/lib/python-support/python2.5/softwareproperties/SoftwareProperties.pyt   <lambda>¢   s   	t   rs   /dev/urandomi   s   MY_HOSTID="%s"
s   PARTICIPATE="%s"
s   USE_HTTP="yes"
t   wN(   R?   R7   R8   R9   R   t   mapR:   t	   readlinest   md5t   newt   updateR;   t	   hexdigestt   appendR"   t
   writelines(   R   t
   is_helpfulRA   t   mt   id(    (   R    sJ   /var/lib/python-support/python2.5/softwareproperties/SoftwareProperties.pyt   set_popcon_pariticipation™   s    
c         C   s¯  t  |  i i ƒ d j  o t |  i _ t Snt |  i _ h  } g  } | i |  i i ƒ | i |  i i ƒ xc | D][ } | i	 | i
 ƒ o, x? | i D] } | | i
 i | ƒ q• Wqr t | i ƒ | | i
 <qr Wt  |  i i ƒ d j o |  i i | |  i i <n x¤ |  i i D]– } | i	 | i
 ƒ pg | i	 | i
 ƒ oi t  t | | i
 ƒ t | i ƒ Aƒ d j p# t  t | i ƒ |  i i Aƒ d j o t |  i _ d SPqqWt S(   s²   Return True if all distro componets are also available as 
       source code. Otherwise return Flase. Special case: If the
       configuration cannot be represented return Nonei   i    N(   t   lenR   t   source_code_sourcesR   t   get_source_codeR?   t   extendt   main_sourcest   child_sourcest   has_keyt   templatet   compst   addt   sett   cdrom_sourcest   cdrom_compst   source_templatet   enabled_compsR   (   R   t	   templatest   sourcest   sourcet   comp(    (    sJ   /var/lib/python-support/python2.5/softwareproperties/SoftwareProperties.pyt   get_source_code_state±   s6     
  -'	c         C   s³   xU d | i  f d | i f d | i f d | i f g D] \ } } d | | f GHq9 W| i oH xE d | i i f d | i i f g D] \ } } d | | f GHq‡ Wn d GHd	 S(
   s4   Print the data of a source entry to the command lines   URI:s   Comps:s   Enabled:s   Valid:s    %s %ss	   MatchURI:s   BaseURI:s   
N(   t   uriR`   t   disabledt   invalidR_   t	   match_urit   base_uri(   R   Ri   t   labelR    (    (    sJ   /var/lib/python-support/python2.5/softwareproperties/SoftwareProperties.pyt   print_source_entryØ   s     
 c         C   s-   d GHx |  i  D] } | i ƒ  GHq Wd GHd S(   s   Print the complete sources.lists   START SOURCES.LIST:s   END SOURCES.LIST
N(   R	   R"   (   R   Ri   (    (    sJ   /var/lib/python-support/python2.5/softwareproperties/SoftwareProperties.pyt   massive_debug_outputå   s
    
 c         C   s   |  i  i | ƒ |  i ƒ  d S(   s    Enable a component of the distroN(   R   t   enable_componentt   set_modified_sourceslist(   R   Rj   (    (    sJ   /var/lib/python-support/python2.5/softwareproperties/SoftwareProperties.pyRt   ì   s    c         C   s   |  i  i | ƒ |  i ƒ  d S(   s!   Disable a component of the distroN(   R   t   disable_componentRu   (   R   Rj   (    (    sJ   /var/lib/python-support/python2.5/softwareproperties/SoftwareProperties.pyRv   ñ   s    c         C   s„   x8 |  i  i D]* } | i | j o |  i i | ƒ q q Wx8 |  i  i D]* } | i | j o |  i i | ƒ qH qH W|  i ƒ  d S(   s7   Enable a child repo of the distribution main repositoryN(   R   R]   R_   R	   t   removeRY   Ru   (   R   R_   Ri   (    (    sJ   /var/lib/python-support/python2.5/softwareproperties/SoftwareProperties.pyt   disable_child_sourceö   s      c         C   sS   | i  d j o |  i i } n
 | i  } |  i i d | d | i ƒ |  i ƒ  d S(   s7   Enable a child repo of the distribution main repositoryRl   t   distN(   Rp   R   R   t   default_servert
   add_sourcet   nameRu   (   R   R_   t	   child_uri(    (    sJ   /var/lib/python-support/python2.5/softwareproperties/SoftwareProperties.pyt   enable_child_source   s
    	c         C   sa   g  } | i  |  i i ƒ | i  |  i i ƒ x$ |  i i D] } |  i i | ƒ q9 W|  i ƒ  d S(   s%   Remove all distro source code sourcesN(   R[   R   R\   R]   RY   R	   Rw   Ru   (   R   Rh   Ri   (    (    sJ   /var/lib/python-support/python2.5/softwareproperties/SoftwareProperties.pyt   disable_source_code_sources  s     c         C   s  g  } | i  |  i i ƒ | i  |  i i ƒ x$ |  i i D] } |  i i | ƒ q9 WxO | D]G } |  i i d | i | i	 | i
 d |  i i i | ƒ d | i ƒ qZ Wxa |  i i D]S } |  i i d |  i i i |  i i i | i
 d |  i i i | ƒ d | i ƒ q² W|  i ƒ  d S(   s0   Enable source code source for all distro sourcess   deb-srcs   Added by software-propertiesi   N(   R[   R   R\   R]   RY   R	   Rw   Ra   Rl   Ry   R`   t   listt   indext   fileRc   Re   Rp   R|   Ru   (   R   Rh   Ri   (    (    sJ   /var/lib/python-support/python2.5/softwareproperties/SoftwareProperties.pyt   enable_source_code_sources  s2       c         C   sO   g  |  _  x? |  i i D]1 } t d | i d | i ƒ } |  i  i | ƒ q Wd S(   s+   Store a backup of the source.list in memoryRC   R‚   N(   t   sourceslist_backupR	   R€   R   RC   R‚   RR   (   R   Ri   t
   source_bkp(    (    sJ   /var/lib/python-support/python2.5/softwareproperties/SoftwareProperties.pyR   1  s
    	 c         C   s   | i  | _  |  i ƒ  d S(   s&   Enable or disable the selected channelN(   Rm   Ru   (   R   Ri   (    (    sJ   /var/lib/python-support/python2.5/softwareproperties/SoftwareProperties.pyt   toggle_source_use8  s    c         C   s   |  i  ƒ  |  i ƒ  d S(   sN   Revert all settings to the state when software-properties 
       was launchedN(   R$   t   revert_sourceslist(   R   (    (    sJ   /var/lib/python-support/python2.5/softwareproperties/SoftwareProperties.pyt   revert>  s    
c         C   sf   g  |  i  _ x? |  i D]4 } t d | i d | i ƒ } |  i  i i | ƒ q W|  i ƒ  |  i ƒ  d S(   s6   Restore the source list from the startup of the dialogRC   R‚   N(	   R	   R€   R„   R   RC   R‚   RR   t   save_sourceslistR   (   R   Ri   t   source_reset(    (    sJ   /var/lib/python-support/python2.5/softwareproperties/SoftwareProperties.pyR‡   E  s    
 
c         C   sB   t  |  _ |  i i t  j o |  i ƒ  n |  i ƒ  |  i ƒ  d S(   sC   The sources list was changed and now needs to be saved and reloadedN(   R?   R   R   t   massive_debugRs   R‰   R   (   R   (    (    sJ   /var/lib/python-support/python2.5/softwareproperties/SoftwareProperties.pyRu   N  s
    	
c         C   s   |  i  ƒ  d S(   s+   Write the changed apt configuration to fileN(   R#   (   R   (    (    sJ   /var/lib/python-support/python2.5/softwareproperties/SoftwareProperties.pyR-   V  s    c         C   sÀ  | i  d j oÅ | i oS d t | i ƒ } t | i ƒ d j o& x# | i D] } | d | 7} qM Wq¥ n9 d | i | i f } x | i D] } | d | 7} q W| i d j o | d t	 d ƒ 7} n | Snè d | i  i
 } | i d j o | d t	 d	 ƒ 7} n | i o | d | i 7} n | i  i t j oy xv | i D]g } | i  i | ƒ o@ xK | i  i D]+ } | i | j o | d
 | i
 7} qoqoWqI| d
 | 7} qIWn | Sd S(   s5   Render a nice output to show the source in a treeviews	   <b>%s</b>i   s    %ss   <b>%s %s</b>s   deb-srcs   rpm-srcs   (Source Code)s    (%s)s   Source Codes   
%sN(   s   deb-srcs   rpm-src(   s   deb-srcs   rpm-src(   R_   R   t   commentR   RX   R`   Rl   Ry   t   typet   _t   descriptiont   childR   t   has_componentt
   componentsR|   (   R   Ri   t   contentst   cRj   (    (    sJ   /var/lib/python-support/python2.5/softwareproperties/SoftwareProperties.pyt   render_sourceZ  s:    

 
 

  c         C   sÓ   d } d } d } d } t  i d d ƒ } | i o6 d } | i i } | i i |  i j o
 d } qš n1 d | i | i | i f } | i	 o
 d } n | i
 i d ƒ o
 d } n | | | | | i | ƒ f S(   s&   extract attributes to sort the sourcesi   t
   0123456789t
   9876543210i    s   %s %s %st   src(   t   stringt	   maketransR_   R   t   distributionR   Rl   Ry   R`   RŒ   R   t   findt	   translate(   R   Ri   t   cur_syst   has_templatet   has_commentt	   is_sourcet   revert_numberst   desc(    (    sJ   /var/lib/python-support/python2.5/softwareproperties/SoftwareProperties.pyt   get_comparable}  s"    



c         C   sœ   g  } x |  i  i D] } | i op | |  i i j oI | |  i i j o6 | |  i i j o# | |  i i j o$ | |  i i j o | i	 | ƒ q q W| S(   s>   Return a list of sources that are not part of the distribution(
   R	   R€   Rn   R   R\   Rc   R]   t   disabled_sourcesRY   RR   (   R   t   isv_sourcesRi   (    (    sJ   /var/lib/python-support/python2.5/softwareproperties/SoftwareProperties.pyt   get_isv_sources’  s     c         C   s
   |  i  i S(   s-   Return the list of CDROM based distro sources(   R   Rc   (   R   (    (    sJ   /var/lib/python-support/python2.5/softwareproperties/SoftwareProperties.pyt   get_cdrom_sourcesŸ  s    c         C   s   | i  |  i i j t f S(   s®   Return a tuple: the first value describes if a component is enabled
       in the Internet repositories. The second value describes if the
       first value is inconsistent.(   R|   R   t   download_compsR   (   R   Rj   (    (    sJ   /var/lib/python-support/python2.5/softwareproperties/SoftwareProperties.pyt   get_comp_download_state£  s    c         C   s×   g  } x8 |  i  i D]* } | i | j o | i | i ƒ q q Wt | ƒ d j o1 t |  i  i t | ƒ Aƒ d j o t t	 f SnO t | ƒ d j o1 t |  i  i t | ƒ Aƒ d j o t	 t f Sn t	 t	 f Sd S(   sÌ   Return a tuple: the first value describes if a component is enabled
       in one of the child source that matcth the given template. 
       The second value describes if the first value is inconsistent.i    N(
   R   R]   R_   R[   R`   RX   Rf   Rb   R?   R   (   R   R_   R`   R   (    (    sJ   /var/lib/python-support/python2.5/softwareproperties/SoftwareProperties.pyt   get_comp_child_stateª  s     ##c         C   s-   |  i  i ƒ  g  |  _ |  i i |  i  ƒ d  S(   N(   R	   t   refresht   sourceslist_visibleR   t   get_sources(   R   (    (    sJ   /var/lib/python-support/python2.5/softwareproperties/SoftwareProperties.pyR   ¿  s    	c   	      C   sH  d d g } x< | D] } t  i i | ƒ o Pq q Wd GHt | d d ƒ xö | D]î } g  } t  i i | ƒ oÏ t | d ƒ i ƒ  } t i i d ƒ } t | d ƒ } xQ | D]I } x@ | i ƒ  D]% } | i	 d | ƒ d j o PqÁ qÁ W| i
 | ƒ q® Wx4 | i ƒ  D]& } | i
 d	 | | i | ƒ f ƒ qW| i ƒ  qR qR Wd
 S(   s+   Write the current apt configuration to files   /etc/apt/apt.conf.d/10periodics+   /etc/apt/apt.conf.d/15adept-periodic-updates   No config found, creating onei    RK   RJ   s   APT::Periodics   APT::Periodic::%ss   APT::Periodic::%s "%s";
N(   R7   R8   t   isfileR:   RM   R   R   t   SubTreet   ListRœ   t   writeR   t   close(	   R   t	   conffilest   ft   periodict   contentt   cnfRC   RD   t   i(    (    sJ   /var/lib/python-support/python2.5/softwareproperties/SoftwareProperties.pyR#   Ä  s4    	 	   	 $c         C   s!   |  i  i d ƒ |  i  i ƒ  d S(   sR   Backup the existing sources.list files and write the current 
       configurations   .saveN(   R	   t   backupt   save(   R   (    (    sJ   /var/lib/python-support/python2.5/softwareproperties/SoftwareProperties.pyR‰   è  s    c         C   s'   |  i  i i t | ƒ ƒ |  i ƒ  d S(   s$   Add a source with the given apt lineN(   R	   R€   RR   R   Ru   (   R   RC   (    (    sJ   /var/lib/python-support/python2.5/softwareproperties/SoftwareProperties.pyt   add_source_from_lineî  s    c         C   s   |  i  i | ƒ |  i ƒ  d S(   s   Remove the given sourceN(   R	   Rw   Ru   (   R   Ri   (    (    sJ   /var/lib/python-support/python2.5/softwareproperties/SoftwareProperties.pyt   remove_sourceó  s    c         C   sE   t  i i | ƒ p t Sn y |  i i | ƒ t SWn t Sn Xd S(   s7   Add a gnupg key to the list of trusted software vendorsN(   R7   R8   R9   R   R   Ra   R?   (   R   R8   (    (    sJ   /var/lib/python-support/python2.5/softwareproperties/SoftwareProperties.pyt   add_keyø  s    c         C   s*   y |  i  i | ƒ t SWn t Sn Xd S(   s<   Remove a gnupg key from the list of trusted software vendorsN(   R   t   rmR?   R   (   R   t   fingerprint(    (    sJ   /var/lib/python-support/python2.5/softwareproperties/SoftwareProperties.pyt
   remove_key  s
    N((   t   __name__t
   __module__R   R   R   R$   R,   R/   R1   R2   RE   RW   Rk   Rr   Rs   Rt   Rv   Rx   R~   R   Rƒ   R   R†   Rˆ   R‡   Ru   R-   R•   R¤   R§   R¨   Rª   R«   R   R#   R‰   R¼   R½   R¾   RÁ   (    (    (    sJ   /var/lib/python-support/python2.5/softwareproperties/SoftwareProperties.pyR   %   sJ   									'					
		
									#							$				
(    (   R   R    R   RŽ   R7   R™   t   xml.sax.saxutilsR   R
   t   aptsources.sourceslistR   R   R   RN   RG   R   (    (    (    sJ   /var/lib/python-support/python2.5/softwareproperties/SoftwareProperties.pys   <module>   s   