
AaRc           @   s  d  d l  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 Z d  d l Z d  d l	 Z	 d  d l
 Z
 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 d  d l m 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 m Z m Z d  d
 l m Z m  Z  d  d l! m" Z# d e$ f d     YZ% d   Z& e' d k re%   Z( e( j)   GHe( j* d  n  d S(   iN(   t   md5(   t   NamedTemporaryFile(   t   escape(   t   ConfigParser(   t   gettext(   t   urlparse(   t   AptAuth(   t   SourcesListt   SourceEntry(   t   AddPPASigningKeyThreadt   expand_ppa_line(   t   shortcut_handlert   SoftwarePropertiesc           B   s  e  Z d  Z d Z e d  \ Z Z Z i d e 6d e 6d e 6Z d9 d9 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. d,   Z/ d-   Z0 d.   Z1 d/   Z2 d0   Z3 d1   Z4 d2   Z5 d3   Z6 d4   Z7 d5   Z8 d6   Z9 d7   Z: d8   Z; RS(:   s    /usr/share/app-install/channels/s$   /etc/update-manager/release-upgradesi   t   normalt   ltst   nevert   /c         C   s   | d |  _  | |  _ | d k r8 t j j d |  n  | d k rM d } n  | |  _ | |  _ t   |  _	 t
 j j   |  _ g  |  _ t |  _ |  j   |  j   |  j   g  |  _ t d |  |  _ t j |  j  d S(   s    Provides the core functionality to configure the used software 
        repositories, the corresponding authentication keys and 
        update automation s   /etc/popularity-contest.confR   t   Dirs   /usr/share/software-properties/t   rootdirN(   t
   popconfileR   t   apt_pkgt   configt   sett   Nonet   optionst   datadirR   t   sourceslistt
   aptsourcest   distrot
   get_distrot   seen_servert   Falset   modified_sourceslistt   reload_sourceslistt   backup_sourceslistt   backup_apt_conft   custom_mirrorsR   t   apt_keyt   atexitt   registert   wait_for_threads(   t   selfR   R   R   (    (    sI   /usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.pyt   __init__K   s$    						


	c         C   s@   x9 t  j   D]+ } | j t  j   j k r | j   q q Wd S(   s9    wait for all running threads (PPA key fetchers) to exit N(   t	   threadingt	   enumeratet   identt   current_threadt   join(   R)   t   t(    (    sI   /usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.pyR(   o   s    c         C   sM   i  |  _  x= t j j   D], } t j j t j |  } | |  j  | <q Wd S(   s$   Backup all apt configuration optionsN(   t   apt_conf_backupt   softwarepropertiest   CONF_MAPt   keysR   R   t   find_i(   R)   t   optiont   value(    (    sI   /usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.pyR#   u   s    	c         C   sO   x> |  j  j   D]- } t j j t j | t |  j  |   q W|  j   d S(   s$   Restore the stored apt configurationN(	   R1   R4   R   R   R   R2   R3   t   strt   write_config(   R)   R6   (    (    sI   /usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.pyt   restore_apt_conf|   s    c         C   sB  t  j j t j d  d k r t  j j t j d  d k rd t  j j t j d  d k rd t j St  j j t j d  d k r t  j j t j d  d k r t j St  j j t j d  d k r t  j j t j d  d k r t j Sd SnI t  j j t j d  d k r:t  j j t j d  d k r:t j	 Sd 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   R5   R2   R3   t   UPDATE_INST_SECt   UPDATE_DOWNLOADt   UPDATE_NOTIFYR   t   UPDATE_MANUAL(   R)   (    (    sI   /usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.pyt   get_update_automation_level   s    c         C   sd  | t  j k rR t j j t  j d t d   t j j t  j d t d   n| t  j k r t j j t  j d t d   t j j t  j d t d   n | t  j k r t j j t  j d t d   t j j t  j d t d   n` t j j t  j d t d   t j j t  j d t d   t j j t  j d t d   |  j	   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(
   R2   R>   R   R   R   R3   R8   R?   R@   t   set_modified_config(   R)   t   state(    (    sI   /usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.pyt   set_update_automation_level   s     # # #   c         C   sP   | t  j j t j d  k sL t  j j t j d t |   |  j   n  d S(   s8   Set the interval in which we check for available updatesR;   N(   R   R   R5   R2   R3   R   R8   RC   (   R)   t   days(    (    sI   /usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.pyt   set_update_interval   s     c         C   s   t  j j t j d  S(   s3    Returns the interval of the apt periodic cron job R;   (   R   R   R5   R2   R3   (   R)   (    (    sI   /usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.pyt   get_update_interval   s    c         C   s   t  j j |  j  s |  j St   } | j |  j  | j d d  r | j d d  j	   } x0 |  j
 j   D] \ } } | | k ro | Sqo Wn  |  j S(   s   
    return the release upgrade policy:
     RELEASE_UPGRADES_NORMAL,
     RELEASE_UPGRADES_LTS,
     RELEASE_UPGRADES_NEVER
    t   DEFAULTt   Prompt(   t   ost   patht   existst   RELEASE_UPGRADES_CONFt   RELEASE_UPGRADES_NORMALR   t   readt
   has_optiont   gett   lowert   release_upgrades_policy_mapt	   iteritems(   R)   t   parsert   typet   kt   v(    (    sI   /usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.pyt   get_release_upgrades_policy   s    	c         C   s   t  j j |  j  sC t |  j d  } | j d |  j |  t St |  j d  } t   } xa t	 t
 j | j    D]G } | j   j d  r | j d |  j |  qw | j | d  qw W| j   t j |  j | j  t j | j |  j  t S(   s   
    set the release upgrade policy:
     RELEASE_UPGRADES_NORMAL,
     RELEASE_UPGRADES_LTS,
     RELEASE_UPGRADES_NEVER
     t   ws   [DEFAULT]
prompt=%s
t   rt   prompts
   prompt=%s
s   
(   RK   RL   RM   RN   t   opent   writeRT   t   TrueR   t   mapt   stringt   stript	   readlinesRS   t
   startswitht   flusht   shutilt   copymodet   namet   copy(   R)   t   it   ft   outt   line(    (    sI   /usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.pyt   set_release_upgrades_policy   s    	
c         C   s   t  j j |  j  r t |  j  j   j d  } t } xn | D]f } yI | j d  \ } } | d k r | j d  j	   d k r t
 } n  Wq@ t k
 r q@ q@ Xq@ W| St 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(   RK   RL   RM   R   R^   RP   t   splitR   Rc   RS   R`   t
   ValueError(   R)   t   linest   activeRn   t   keyR7   (    (    sI   /usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.pyt   get_popcon_participation   s    'c            s   | t  k r d   n d   t j j |  j  r] t   f d   t |  j d  j    } no t   } | j	 t d d  j
 d   | j   } g  } | j d |  | j d t     | j d	  t |  j d
  j |  d S(   s?    Enable or disable the participation in the popularity contest Rs   t   noc            s   t  j d d   |   S(   Ns   ^(PARTICIPATE=)(".+?")s   \1"%s"(   t   ret   sub(   Rn   (   R7   (    sI   /usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.pyt   <lambda>   s   	R\   s   /dev/urandomi   s   MY_HOSTID="%s"
s   PARTICIPATE="%s"
s   USE_HTTP="yes"
R[   N(   R`   RK   RL   RM   R   Ra   R^   Rd   R    t   updateRP   t	   hexdigestt   appendR8   t
   writelines(   R)   t
   is_helpfulRv   t   mt   id(    (   R7   sI   /usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.pyt   set_popcon_pariticipation   s    		c         C   s  t  |  j j  d k  r( t |  j _ t St |  j _ i  } g  } | j |  j j  | j |  j j  xa | D]Y } | j	 | j
  r x> | j D] } | | j
 j |  q Wqm t | j  | | j
 <qm Wt  |  j j  d k r |  j j | |  j j <n  x |  j j D] } | j	 | j
  s| j	 | j
  rt  t | | j
  t | j  A d k pt  t | j  |  j j A d k rt |  j _ 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   addR   t   cdrom_sourcest   cdrom_compst   source_templatet   enabled_compsR   (   R)   t	   templatest   sourcest   sourcet   comp(    (    sI   /usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.pyt   get_source_code_state  s0    ,&c         C   s   xU d | j  f d | j f d | j f d | j f g D] \ } } d | | f GHq9 W| j r xD d | j j f d | j j 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)   R   t   labelR7   (    (    sI   /usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.pyt   print_source_entry5  s    	c         C   s-   d GHx |  j  D] } | j   GHq Wd GHd S(   s   Print the complete sources.lists   START SOURCES.LIST:s   END SOURCES.LIST
N(   R   R8   (   R)   R   (    (    sI   /usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.pyt   massive_debug_outputB  s    c         C   s,   | |  j  _ |  j  j |  } |  j   | S(   s!    change the main download server (   R   t   default_servert   change_servert   set_modified_sourceslist(   R)   t   servert   res(    (    sI   /usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.pyt   change_main_download_serverI  s    
c         C   s   |  j  j |  |  j   d S(   s    Enable a component of the distroN(   R   t   enable_componentR   (   R)   R   (    (    sI   /usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.pyR   P  s    c         C   s   |  j  j |  |  j   d S(   s!   Disable a component of the distroN(   R   t   disable_componentR   (   R)   R   (    (    sI   /usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.pyR   U  s    c         C   s1   x* |  j  j j D] } | j | k r | Sq Wd  S(   N(   R   R   t   childrenRi   (   R)   Ri   R   (    (    sI   /usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.pyt   _find_template_from_stringZ  s    c         C   s   t  | t  r! |  j |  } n  x6 |  j j D]( } | j | k r. |  j j |  q. q. Wx6 |  j j D]( } | j | k rg |  j j |  qg qg W|  j	   d S(   s7   Enable a child repo of the distribution main repositoryN(
   t
   isinstanceR8   R   R   R   R   R   t   removeR   R   (   R)   R   R   (    (    sI   /usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.pyt   disable_child_source_  s    c         C   sr   t  | t  r! |  j |  } n  | j d k r? |  j j } n	 | j } |  j j d | d | j  |  j	   d S(   s7   Enable a child repo of the distribution main repositoryR   t   distN(
   R   R8   R   R   R   R   R   t
   add_sourceRi   R   (   R)   R   t	   child_uri(    (    sI   /usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.pyt   enable_child_sourcel  s    	c         C   sa   g  } | j  |  j j  | j  |  j j  x$ |  j j D] } |  j j |  q9 W|  j   d S(   s%   Remove all distro source code sourcesN(   R   R   R   R   R   R   R   R   (   R)   R   R   (    (    sI   /usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.pyt   disable_source_code_sourcesz  s    c      	   C   s  g  } | j  |  j j  | j  |  j j  x$ |  j j D] } |  j j |  q9 WxO | D]G } |  j j d | j | j	 | j
 d |  j j j |  d | j  qZ Wxa |  j j D]S } |  j j d |  j j j |  j j j | j
 d |  j j j |  d | j  q W|  j   d S(   s0   Enable source code source for all distro sourcess   deb-srcs   Added by software-propertiesi   N(   R   R   R   R   R   R   R   R   R   R   R   t   listt   indext   fileR   R   R   Ri   R   (   R)   R   R   (    (    sI   /usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.pyt   enable_source_code_sources  s,    c         C   sO   g  |  _  x? |  j j D]1 } t d | j d | j  } |  j  j |  q Wd S(   s+   Store a backup of the source.list in memoryRn   R   N(   t   sourceslist_backupR   R   R   Rn   R   R   (   R)   R   t
   source_bkp(    (    sI   /usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.pyR"     s    	c         C   s;   |  j    x* |  j j D] } t |  | k r | Sq Wd  S(   N(   R!   R   R   R8   R   (   R)   Rn   R   (    (    sI   /usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.pyt   _find_source_from_string  s
    
c         C   s<   t  | t  r! |  j |  } n  | j | _ |  j   d S(   s&   Enable or disable the selected channelN(   R   R8   R   R   R   (   R)   R   (    (    sI   /usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.pyt   toggle_source_use  s    c         C   ss   xl t  |  j j  D]X \ } } t |  | k r |  j j | j } t | |  |  j j | <|  j   t Sq Wt S(   N(	   R,   R   R   R8   R   R   R   R`   R   (   R)   t	   old_entryt	   new_entryR   t   entryR   (    (    sI   /usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.pyt   replace_source_entry  s    
c         C   s   |  j    |  j   d S(   sN   Revert all settings to the state when software-properties 
       was launchedN(   R:   t   revert_sourceslist(   R)   (    (    sI   /usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.pyt   revert  s    
c         C   sf   g  |  j  _ x? |  j D]4 } t d | j d | j  } |  j  j j |  q W|  j   |  j   d S(   s6   Restore the source list from the startup of the dialogRn   R   N(	   R   R   R   R   Rn   R   R   t   save_sourceslistR!   (   R)   R   t   source_reset(    (    sI   /usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.pyR     s    
c         C   sC   t  |  _ |  j r+ |  j j r+ |  j   n  |  j   |  j   d S(   sC   The sources list was changed and now needs to be saved and reloadedN(   R`   R    R   t   massive_debugR   R   R!   (   R)   (    (    sI   /usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.pyR     s
    	
c         C   s   |  j    d S(   s+   Write the changed apt configuration to fileN(   R9   (   R)   (    (    sI   /usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.pyRC     s    c         C   s  | j  d k r | j r d t | j  | j | j f } t | j  d k rt x" | j D] } | d | 7} qY Wn  | d 7} n8 d | j | j f } x | j D] } | d | 7} q W| j d k r | d t	 d  7} n  | Sd	 | j  j
 } | j d k r| d
 t	 d  7} n  | j r6| d | j 7} n  | j  j t k rxq | j D]c } | j  j |  rxH | j  j D]) } | j | k rw| d | j
 7} qwqwWqR| d | 7} qRWn  | Sd S(   s5   Render a nice output to show the source in a treeviews   <b>%s</b> (%s %si   s    %st   )s   <b>%s %s</b>s   deb-srcs   rpm-srcs   (Source Code)s	   <b>%s</b>s    (%s)s   Source Codes   
%sN(   s   deb-srcs   rpm-src(   s   deb-srcs   rpm-src(   R   R   t   commentR   R   R   R   R   RW   t   _t   descriptiont   childR   t   has_componentt
   componentsRi   (   R)   R   t   contentst   cR   (    (    sI   /usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.pyt   render_source  s6    		c         C   s   d } d } d } d } t  j d d  } | j rf d } | j j } | j j |  j k r d } q n. d | j | j | j f } | j	 r d } n  | j
 j d  r d } n  | | | | | j |  f S(   s&   extract attributes to sort the sourcesi   t
   0123456789t
   9876543210i    s   %s %s %st   src(   Rb   t	   maketransR   R   t   distributionR   R   R   R   R   RW   t   findt	   translate(   R)   R   t   cur_syst   has_templatet   has_commentt	   is_sourcet   revert_numberst   desc(    (    sI   /usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.pyt   get_comparable  s"    				c         C   s   g  } x |  j  j D]z } | j r | |  j j k r | |  j j k r | |  j j k r | |  j j k r | |  j j k r | j	 |  q q W| S(   s>   Return a list of sources that are not part of the distribution(
   R   R   R   R   R   R   R   t   disabled_sourcesR   R   (   R)   t   isv_sourcesR   (    (    sI   /usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.pyt   get_isv_sources  s    
c         C   s
   |  j  j S(   s-   Return the list of CDROM based distro sources(   R   R   (   R)   (    (    sI   /usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.pyt   get_cdrom_sources&  s    c         C   s   | j  |  j j k 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.(   Ri   R   t   download_compsR   (   R)   R   (    (    sI   /usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.pyt   get_comp_download_state*  s    c         C   s   g  } x6 |  j  j D]( } | j | k r | j | j  q q Wt |  d k r} t |  j  j t |  A d k r} t t	 f St |  d k r t |  j  j t |  A d k r t	 t f St	 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   R   R   R   R`   R   (   R)   R   R   R   (    (    sI   /usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.pyt   get_comp_child_state1  s    "
"
c         C   s-   |  j  j   g  |  _ |  j j |  j   d  S(   N(   R   t   refresht   sourceslist_visibleR   t   get_sources(   R)   (    (    sI   /usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.pyR!   F  s    	c         C   s  |  j  d |  j  d |  j  d g } x: | D] } t j j |  r+ Pq+ q+ Wd GHt | d d  d } t j j |  r t j |  t j } | t j @s d | GHt j	 | d	  q n  x | D] } g  } t j j |  r t | d
  j
   } t j j d  } t | d  } xO | D]G } x> | j   D]# }	 | j d |	  d k r0Pq0q0W| j |  qWx4 | j   D]& }
 | j d |
 | j |
  f  quW| j   q q Wd S(   s+   Write the current apt configuration to files   /etc/apt/apt.conf.d/10periodics#   /etc/apt/apt.conf.d/20auto-upgradess+   /etc/apt/apt.conf.d/15adept-periodic-updates   No config found, creating onei    R[   s   /etc/cron.daily/apts    file '%s' not executable, fixingi  R\   s   APT::Periodics   APT::Periodic::%ss   APT::Periodic::%s "%s";
N(   R   RK   RL   t   isfileR^   RM   t   statt   ST_MODEt   S_IXUSRt   chmodRd   R   R   t   subtreeR   R   R_   R5   t   close(   R)   t	   conffilesRl   t   act   permt   periodict   contentt   cnfRn   Rx   Rk   (    (    sI   /usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.pyR9   K  s8    

	$c         C   s!   |  j  j d  |  j  j   d S(   sR   Backup the existing sources.list files and write the current 
       configurations   .saveN(   R   t   backupt   save(   R)   (    (    sI   /usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.pyR   x  s    c         C   s   t  |  } t j j |  j  r x t j d |  j  D]j } xa t |  D]S } | j   j d  rl qK n  | t  |  k rK t j j	 t j j
 |   d SqK Wq8 Wn  d S(   ss   
    helper that checks if a given line is in the source list
    return the channel name or None if not found
    s	   %s/*.listt   #i    N(   R   RK   RL   RM   t   CHANNEL_PATHt   globR^   Rc   Re   t   splitextt   basenameR   (   R)   t   srclinet   srcentryRl   Rn   (    (    sI   /usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.pyt   _is_line_in_whitelisted_channel~  s    +c         C   s   |  j  |  } | r8 d |  j | f } |  j |  n  t t |  j  } | j d k r t | j |  j	 ow |  j	 j
  } | j   | Sd Sd S(   s   
    helper that adds the gpg key of the channel to the apt
    keyring *if* the channel is in the whitelist
    /usr/share/app-install/channels or it is a public Launchpad PPA.
    s	   %s/%s.keys   ppa.launchpad.netN(   R   R   t   add_keyR   R   R   t   netlocR	   RL   R   t	   keyservert   startR   (   R)   R   t   channelt   keypt
   parsed_urit   worker(    (    sI   /usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.pyt*   check_and_add_key_for_whitelisted_channels  s    !
c         C   s   d S(   s)    abstract interface to keep the UI alive N(    (   R)   (    (    sI   /usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.pyt   update_interface  s    c         C   sv   | j  d  s | S| j   d } y | j d d  d } Wn t k
 rX } d } n Xd | |  j j | f } | S(   s   
    short cut - this:
      apt-add-repository http://packages.medibuntu.org free non-free
    same as
      apt-add-repository 'deb http://packages.medibuntu.org/ '$(lsb_release -cs)' free non-free'
    t   httpi    t    i   t   mains   deb %s %s %s(   Re   Rt   t
   IndexErrorR   t   codename(   R)   Rn   t   repot   areast   e(    (    sI   /usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.pyt   expand_http_line  s    
c   	      C   sh  t  | j   |  j j  \ } } |  j |  } d | d } t | |  } t | |  } | j sn | j rr t S| j d  r t	 | j    } t
 j d | j  } | j   n |  j |  } |  j j | j | j | j | j d | j d | j d | j |  j j | j | j | j | j d | j d | j d | j |  j   | rd| j d  n  t S(	   sj   
    Add a source with the given apt line and auto-add
    signing key if we have it in the whitelist
    s   deb-srci   s   cloud-archive:t   targetR   R   t   architecturesi   (   t   expand_shortcut_lineRc   R   R  R  R   R   R   Re   t   ca_shortcut_handlerR+   t   ThreadR   R   R  R   R   RW   R   R   R   R   R   R  R   R/   R`   (	   R)   Rn   t   deb_lineR   t   debsrc_linet   new_deb_entryt   new_debsrc_entryt
   ca_handlerR  (    (    sI   /usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.pyt   add_source_from_line  s<    !			
			

c         C   s   t  | t  r! |  j |  } n  | j t j j d  k ra |  j j j	 t
 d d | j  n  |  j j |  |  j   d S(   s   Remove the given sources   Dir::Etc::sourcelistt    R   N(   R   R8   R   R   R   R   t	   find_fileR   R   R   R   R   R   (   R)   R   (    (    sI   /usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.pyt   remove_source  s    %c         C   sg   t  | t  s t |  } n  t j j |  s4 t Sy$ |  j j |  } |  j   | SWn t SXd S(   s7   Add a gnupg key to the list of trusted software vendorsN(	   R   t   unicodeRK   RL   RM   R   R%   R   t   KeysModified(   R)   RL   R   (    (    sI   /usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.pyR     s    
c         C   s3   t  j   } | j |  | j   |  j | j  S(   s6   Add a gnupg key from a data string (e.g. copy-n-paste)(   t   tempfileR   R_   Rf   R   Ri   (   R)   t   keydatat   tmp(    (    sI   /usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.pyt   add_key_from_data  s    
c         C   s1   y" |  j  j |  |  j   t SWn t SXd S(   s<   Remove a gnupg key from the list of trusted software vendorsN(   R%   t   rmR  R`   R   (   R)   t   keyid(    (    sI   /usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.pyt
   remove_key   s    
c         C   s.   y |  j  j   |  j   t SWn t SXd S(   s    Run apt-key update N(   R%   R~   R  R`   R   (   R)   (    (    sI   /usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.pyt   update_keys	  s    
N(<   t   __name__t
   __module__R   RN   t   rangeRO   t   RELEASE_UPGRADES_LTSt   RELEASE_UPGRADES_NEVERRT   R   R*   R(   R#   R:   RB   RE   RG   RH   RZ   Ro   Ry   R   R   R   R   R   R   R   R   R   R   R   R   R"   R   R   R   R   R   R   RC   R   R   R   R   R   R   R!   R9   R   R   R  R  R  R  R  R   R#  R&  R'  (    (    (    sI   /usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.pyR   8   sr   
$												'									
			
		
						%							-						*					c         C   s8   |  j  d  r( t |   } | j |  St |  d | S(   Ns   cloud-archive:t   distro_codename(   Re   R  t   expandR
   (   t   abrevR  t   handler(    (    sI   /usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.pyR    s    t   __main__i    (+   t   aptR   t   hashlibR    R{   RK   R   t   inspectt   sysRg   t
   subprocessR+   R&   R   Rb   R   R   t   xml.sax.saxutilsR   R   R   R   R   R   t   aptsources.distroR2   R   t   aptsources.sourceslistR   R   t   ppaR	   R
   t   cloudarchiveR   R  t   objectR   R  R(  t   spRZ   Ro   (    (    (    sI   /usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.pyt   <module>   sD     		