
    3LGf}                        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mZ n# e$ r
 ej        ZY nw xY wd dlZ	 d dlZn# e$ r d dlZY nw xY wd dl
mZ d dlmZ 	 d dlmZ n# e$ r	 d dlmZ Y nw xY w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! d dl"m#Z# d dl$m%Z%  G d de&          Z'e(dk    r> e'            Z) e*e)+                                           e),                    d            dS dS )    N)md5)	maketrans)NamedTemporaryFile)escape)ConfigParser)gettext   )AptAuth)SourcesListSourceEntry)InvalidShortcutException)shortcut_handler)Gioc                      e Zd ZdZdZ e ed                    \  ZZZ	edede	diZ
dAd	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. Z0d/ Z1d0 Z2d1 Z3d2 Z4d3 Z5d4 Z6d5 Z7dBd7Z8dBd8Z9dCd:Z:d; Z;d< Z<d= Z=d> Z>d? Z?e@dDd@            ZAdS )ESoftwarePropertiesz /usr/share/app-install/channels/z$/etc/update-manager/release-upgrades   normalltsneverN/c                 j   |dz   | _         || _        |dk    r t          j                            d|           |dk    rd}|| _        || _        t                      | _        t          j
                                        | _
        g | _        d| _        |                                  |                                  |                                  g | _        t%          j                    | _        t+          |          | _        t/          j                    | _        t5          j        | j                   dS )z Provides the core functionality to configure the used software
        repositories, the corresponding authentication keys and
        update automation z/etc/popularity-contest.confr   DirNz/usr/share/software-properties/F)rootdir)
popconfiler   apt_pkgconfigsetoptionsdatadirr   sourceslist
aptsourcesdistro
get_distroseen_servermodified_sourceslistreload_sourceslistbackup_sourceslistbackup_apt_confcustom_mirrorsqueueQueuemyqueuer
   apt_keyr   Cancellablecancellableatexitregisterwait_for_threads)selfr   r   r   s       G/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py__init__zSoftwareProperties.__init__V   s    <<DODL#~~n((( $1gDLDL"}}D#..00DKD %D D ;==DL 7+++DL((D
OD)*****    c                     t          j                    D ]7}|j        t          j                    j        k    r|                                 8dS )z9 wait for all running threads (PPA key fetchers) to exit N)	threading	enumerateidentcurrent_threadjoin)r3   ts     r4   r2   z#SoftwareProperties.wait_for_threads   sK     ""  	
I,..4	4	4	 r6   c                     i | _         t          j                                        D ];}t          j                            t          j        |                   }|| j         |<   <dS )z$Backup all apt configuration optionsN)apt_conf_backupsoftwarepropertiesCONF_MAPkeysr   r   find_i)r3   optionvalues      r4   r(   z"SoftwareProperties.backup_apt_conf   s`    D$-2244 - -%%&8&A&&IJJ',V$$- -r6   c                     | j                                         D ]J}t          j                            t
          j        |         t          | j         |                              K|                                  dS )z$Restore the stored apt configurationN)	r?   rB   r   r   r   r@   rA   strwrite_config)r3   rD   s     r4   restore_apt_confz#SoftwareProperties.restore_apt_conf   su    &++-- > >-6v>t3F;<<	> 	> 	> 	>r6   c                    t           j                            t          j        d                   dk    rDt           j                            t          j        d                   dk    r+t
          j                            d          rt          j        S t           j                            t          j        d                   dk    r?t           j                            t          j        d                   dk    rt          j	        S t           j                            t          j        d                   dk    r?t           j                            t          j        d                   dk    rt          j
        S dS t           j                            t          j        d                   dk    r?t           j                            t          j        d                   dk    rt          j        S dS )z 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 
autoupdater   
unattendedr	   /usr/bin/unattended-upgradeautodownloadN)r   r   rC   r@   rA   ospathexistsUPDATE_INST_SECUPDATE_DOWNLOADUPDATE_NOTIFYUPDATE_MANUALr3   s    r4   get_update_automation_levelz.SoftwareProperties.get_update_automation_level   sn    ~/8FGG!KK>  !3!<\!JKKqPPw~~;<< Q%55^""#5#>~#NOOSTTT^""#5#>|#LMMQRRR%55^""#5#>|#LMMQRRR^""#5#>~#NOOSTTT%334			1:<H	I	IQ	N	N			1:>J	K	Kq	P	P!//tr6   c                    |t           j        k    r|t          j                            t           j        d         t          d                     t          j                            t           j        d         t          d                     n|t           j        k    r|t          j                            t           j        d         t          d                     t          j                            t           j        d         t          d                     nB|t           j        k    r{t          j                            t           j        d         t          d                     t          j                            t           j        d         t          d                     nt          j                            t           j        d         t          d                     t          j                            t           j        d         t          d                     t          j                            t           j        d         t          d                     | 	                                 dS )z 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. rL   r	   rN   r   rK   N)
r@   rR   r   r   r   rA   rG   rS   rT   set_modified_config)r3   states     r4   set_update_automation_levelz.SoftwareProperties.set_update_automation_level   s   
 "222-6|Dc!ffMMM-6~FAOOOO	$4	4	4-6~FAOOO-6|Dc!ffMMMM	$2	2	2-6~FAOOO-6|Dc!ffMMMM-6|Dc!ffMMM-6|Dc!ffMMM-6~FAOOOr6   c                    |t           j                            t          j        d                   k    sSt           j                            t          j        d         t          |                     |                                  dS dS )z8Set the interval in which we check for available updatesrK   N)r   r   rC   r@   rA   r   rG   rY   )r3   dayss     r4   set_update_intervalz&SoftwareProperties.set_update_interval   sp     W^**+=+F|+TUUUU
.

/8FD		
R
R
R

"
"
$
$
$
$
$ VUr6   c                 `    t           j                            t          j        d                   S )z3 Returns the interval of the apt periodic cron job rK   )r   r   rC   r@   rA   rV   s    r4   get_update_intervalz&SoftwareProperties.get_update_interval   s!    >  !3!<\!JKKKr6   c                    t           j                            | j                  s| j        S t                      }|                    | j                   |                    dd          rQ|                    dd          	                                }| j
                                        D ]\  }}||k    r|c S | j        S )z
    return the release upgrade policy:
     RELEASE_UPGRADES_NORMAL,
     RELEASE_UPGRADES_LTS,
     RELEASE_UPGRADES_NEVER
    DEFAULTPrompt)rO   rP   rQ   RELEASE_UPGRADES_CONFRELEASE_UPGRADES_NORMALr   read
has_optiongetlowerrelease_upgrades_policy_mapitems)r3   parsertypekvs        r4   get_release_upgrades_policyz.SoftwareProperties.get_release_upgrades_policy   s     7>>$455 *))^^F
KK*+++8,, ZZ	(++1133d288::  $!Q99((( ''r6   c                 8   t           j                            | j                  sRt	          | j        d          5 }|                    d| j        |         z             ddd           n# 1 swxY w Y   dS t	          | j        d          5 }t          d          5 }|D ]y}|                                }|	                                
                    d          r$|                    d	| j        |         z             a|                    |d
z              z|                                 t          j        | j        |j                   t          j        |j        | j                   ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   dS )z
    set the release upgrade policy:
     RELEASE_UPGRADES_NORMAL,
     RELEASE_UPGRADES_LTS,
     RELEASE_UPGRADES_NEVER
     wz[DEFAULT]
Prompt=%s
NTrzw+)modepromptz
Prompt=%s

)rO   rP   rQ   rd   openwriterj   r   stripri   
startswithflushshutilcopymodenamecopy)r3   ifoutlines        r4   set_release_upgrades_policyz.SoftwareProperties.set_release_upgrades_policy   s7    7>>$455 *3// O1	($*J1*MMNNNO O O O O O O O O O O O O O OT	d(	-	- 	84FD4Q4Q4Q 	8UX  $zz||::<<""8,, 	
))MD$DQ$GG
H
H
H
H
))DI



	iikkkod0#(;;;k#(D6777	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 4sH   $A**A.1A.FCE8,F8E<	<F?E<	 FFFc                    t           j                            | j                  rt	          | j                  5 }|                                                    d          }ddd           n# 1 swxY w Y   |D ]_}	 |                    d          \  }}|dk    r.|                    d                                          dk    r dS P# t          $ r Y \w xY wdS )	z 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 rv   N=PARTICIPATE"yesTF)
rO   rP   rQ   r   rw   rf   splitry   ri   
ValueError)r3   r   linesr   keyrE   s         r4   get_popcon_participationz+SoftwareProperties.get_popcon_participation   s    
w~~do&& 	$/"" 	'a&&((..&&%	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	 	D"jjooU-''EKK,<,<,B,B,D,D,M,M44   5s$   (A--A14A1=A	C


CCc                    |dk    rdndt           j                            | j                  r<t	          | j        d          5 }fd|D             }ddd           n# 1 swxY w Y   nt                      }t	          dd          5 }|                    |                    d	                     ddd           n# 1 swxY w Y   |                                }g }|	                    d
|z             |	                    dt                    z             |	                    d           t	          | j        d          5 }|                    |           ddd           dS # 1 swxY w Y   dS )z? Enable or disable the participation in the popularity contest Tr   nors   c                 B    g | ]}t          j        d dz  |          S )z^(PARTICIPATE=)(".+?")z\1"%s")resub).0r   rE   s     r4   
<listcomp>z@SoftwareProperties.set_popcon_pariticipation.<locals>.<listcomp>  s=     - - - V5y57H$OO - - -r6   Nz/dev/urandomrbi   zMY_HOSTID="%s"
zPARTICIPATE="%s"
zUSE_HTTP="yes"
rr   )rO   rP   rQ   r   rw   r   updaterf   	hexdigestappendrG   
writelines)r3   
is_helpfulr   r   mr   idrE   s          @r4   set_popcon_pariticipationz,SoftwareProperties.set_popcon_pariticipation  s*   T	w~~do&& + $/3'' 	-:- - - -!+- - -E	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-
 EE.$'' 	#1HHQVVD\\"""	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	#[[]])B.///+c%jj8999)***	dos	#	# q	U                 s6   A!!A%(A%)C  CCE++E/2E/c                 @    t           j                            d          S )NrM   )rO   rP   isfilerV   s    r4   have_unattended_upgradesz+SoftwareProperties.have_unattended_upgrades  s    W^^9:::r6   c                 R   t          | j        j                  dk     rd| j        _        dS d| j        _        i }g }|                    | j        j                   |                    | j        j                   |D ]R}|j        |v r+|j        D ]"}||j                 	                    |           #6t          |j                  ||j        <   St          | j        j                  dk    r| j        j        || j        j        <   | j        j        D ]}|j        |vs{|j        |v rt          t          ||j                           t          |j                  z            dk    sAt          t          |j                  | j        j        z            dk    sd| j        _         dS dS )zReturn True if all distro componets are also available as
       source code. Otherwise return Flase. Special case: If the
       configuration cannot be represented return Noner	   FTr   N)lenr"   source_code_sourcesget_source_codeextendmain_sourceschild_sourcestemplatecompsaddr   cdrom_sourcescdrom_compssource_templateenabled_comps)r3   	templatessourcessourcecomps        r4   get_source_code_statez(SoftwareProperties.get_source_code_state   s   
 4;*++a// ',#u '+# 	t{/000t{0111 	? 	?F)++"L 9 9Dfo.22488889 .1->->	&/** t{())A--59[5LIdk12k5 	 	Fi//9,,S6?344s6<7H7HHIIQNNV\**T[-FFGG1LL.3+tt4r6   c                    d|j         fd|j        fd|j         fd|j         ffD ]\  }}t	          d|d|           |j        r7d|j        j        fd|j        j        ffD ]\  }}t	          d|d|           t	          d           d	S )
z4Print the data of a source entry to the command linezURI:zComps:zEnabled:zValid: z	MatchURI:zBaseURI:rv   N)urir   disabledinvalidprintr   	match_uribase_uri)r3   r   labelrE   s       r4   print_source_entryz%SoftwareProperties.print_source_entryG  s    "FJ/$fl3&FO(;<$&.&89; ) ) 	%%%'(((( - +V_-FG *FO,DEG 	- 	-NUEEeeeUU+,,,,	$KKKKKr6   c                     t          d           | j        D ]#}t          |                                           $t          d           dS )zPrint the complete sources.listzSTART SOURCES.LIST:zEND SOURCES.LIST
N)r   r    rG   r3   r   s     r4   massive_debug_outputz'SoftwareProperties.massive_debug_outputT  sQ    	
   "  fjjll	
r6   c                 z    || j         _        | j                             |          }|                                  |S )z! change the main download server )r"   default_serverchange_serverset_modified_sourceslist)r3   serverress      r4   change_main_download_serverz.SoftwareProperties.change_main_download_server[  s8    !'DK
+
#
#F
+
+C!!###Jr6   c                 b    | j                             |           |                                  dS )z Enable a component of the distroN)r"   enable_componentr   r3   r   s     r4   r   z#SoftwareProperties.enable_componentb  s0    K  &&&!!#####r6   c                 b    | j                             |           |                                  dS )z!Disable a component of the distroN)r"   disable_componentr   r   s     r4   r   z$SoftwareProperties.disable_componentg  s0    K!!$'''!!#####r6   c                 L    | j         j        j        D ]}|j        |k    r|c S d S N)r"   r   childrenr~   )r3   r~   r   s      r4   _find_template_from_stringz-SoftwareProperties._find_template_from_stringl  s>    K/8  	$		 
 r6   c                 R   t          |t                    r|                     |          }| j        j        D ]'}|j        |k    r| j                            |           (| j        j        D ]'}|j        |k    r| j                            |           (| 	                                 dS )7Enable a child repo of the distribution main repositoryN)

isinstancerG   r   r"   r   r   r    remover   r   )r3   r   r   s      r4   disable_child_sourcez'SoftwareProperties.disable_child_sourceq  s    (C   ;00::h++ , ,?h&&##F++++1 , ,?h&&##F+++!!#####r6   c                    t          |t                    r|                     |          }|j        dk    r| j        j        }n|j        }| j                            ||j                   |                                  dS )r   N)r   dist)	r   rG   r   r   r"   r   
add_sourcer~   r   )r3   r   	child_uris      r4   enable_child_sourcez&SoftwareProperties.enable_child_source~  s    (C   ;00::h D  K.		%	Kyx}===!!#####r6   c                     g }|                     | j        j                   |                     | j        j                   | j        j        D ]}| j                            |           |                                  dS )z%Remove all distro source code sourcesN)r   r"   r   r   r   r    r   r   r3   r   r   s      r4   disable_source_code_sourcesz.SoftwareProperties.disable_source_code_sources  s{    GNN4;+,,,NN4;,---+1 ( (''''!!#####r6   c                    g }|                     | j        j                   |                     | j        j                   | j        j        D ]}| j                            |           |D ]V}| j                            d|j        |j	        |j
        d| j        j                            |          dz   |j                   W| j        j        D ]j}| j                            d| j        j        j        | j        j        j        |j
        d| j        j                            |          dz   |j                   k|                                  dS )z0Enable source code source for all distro sourcesdeb-srczAdded by software-propertiesr	   N)r   r"   r   r   r   r    r   r   r   r   r   listindexfiler   r   r   r~   r   r   s      r4   enable_source_code_sourcesz-SoftwareProperties.enable_source_code_sources  sZ   GNN4;+,,,NN4;,--- +1 ( ('''' * *Y#Z#[#\;!-288@@B#[	* 	* 	* 	* ++ * *Y![8A![8=#\;!-288@@B#[	* 	* 	* 	* 	!!#####r6   c                     g | _         | j        j        D ]7}t          |j        |j                  }| j                             |           8dS )z+Store a backup of the source.list in memoryr   r   N)sourceslist_backupr    r   r   r   r   r   )r3   r   
source_bkps      r4   r'   z%SoftwareProperties.backup_sourceslist  sY     D"' 3 3 fkv{CCC
&&z22223 3r6   c                 z    |                                   | j        j        D ]}t          |          |k    r|c S d S r   )r&   r    r   rG   )r3   r   r   s      r4   _find_source_from_stringz+SoftwareProperties._find_source_from_string  sO     	"'  	V		 
4r6   c                     t          |t                    r|                     |          }|j         |_        |                                  dS )z&Enable or disable the selected channelN)r   rG   r   r   r   r   s     r4   toggle_source_usez$SoftwareProperties.toggle_source_use  sM     &# 5,,V44f /)FO!!#####r6   c                     t          | j        j                  D ]c\  }}t          |          |k    rK| j        j        |         j        }t          ||          | j        j        |<   |                                   dS ddS )NTF)r9   r    r   rG   r   r   r   )r3   	old_entry	new_entryr   entryr   s         r4   replace_source_entryz'SoftwareProperties.replace_source_entry  s    #D$4$9::  	Uy	 	 $U+0'29d'C'Ce$%%'''tt	 
!
 5r6   c                 V    |                                   |                                  dS )zMRevert all settings to the state when software-properties
       was launchedN)rI   revert_sourceslistrV   s    r4   revertzSoftwareProperties.revert  s.     	r6   c                     g | j         _        | j        D ]<}t          |j        |j                  }| j         j                            |           =|                                  |                                  dS )z6Restore the source list from the startup of the dialogr   N)	r    r   r   r   r   r   r   save_sourceslistr&   )r3   r   source_resets      r4   r   z%SoftwareProperties.revert_sourceslist  s|    D) 3 3"EEE$$\2222r6   c                     d| _         | j        r | j        j        r|                                  |                                  |                                  dS )zCThe sources list was changed and now needs to be saved and reloadedTN)r%   r   massive_debugr   r   r&   rV   s    r4   r   z+SoftwareProperties.set_modified_sourceslist  s\     $D| $2 $!!###r6   c                 .    |                                   dS )z+Write the changed apt configuration to fileN)rH   rV   s    r4   rY   z&SoftwareProperties.set_modified_config  s    r6   c                    |j         dk    r|j        rdt          |j                                                  d|j        }t          |j                  dk    r|j        D ]
}|d|z  z  }|j        dv r|dt          d          z  z  }|d|j	        z  z  }nCd|j	        d	|j        d
}|j        D ]
}|d|z  z  }|j        dv r|dt          d          z  z  }|S d|j         j
        z  }|j        dv r|dt          d          z  z  }|j        r|d|j        z  z  }|j         j        dk    rT|j        D ]L}|j                             |          r(|j         j        D ]}|j        |k    r|d|j
        z  z  }D|d|z  z  }M|S )z5Render a nice output to show the source in a treeviewNz<b>z</b> r	   z %s)r   zrpm-srcz(Source Code)z
%sr   z</b>z	<b>%s</b>z (%s)zSource CodeF)r   commentr   ry   r   r   r   rm   _r   descriptionchildhas_component
componentsr~   )r3   r   contentscr   s        r4   render_sourcez SoftwareProperties.render_source  s   $> 	7 	7)/)?)?)E)E)G)G)G)G)/6H 6<  1$$ * *A	)HH{444EAo$6$666++HH	7 *0V[[[AH\ & &EAI%{444EAo$6$666 !<<;000!M"2"222H> 	.uv~--H? E)) . .?0066 . $_7 ? ?6T>>$(>>H? -HHr6   c                 <   d}d}d}d}t          dd          }|j        r&d}|j        j        }|j        j        | j        k    rd}n"|j        d|j        d|j        }|j        rd}|j	        
                    d          rd}|||||                    |          fS )z&extract attributes to sort the sourcesr	   
0123456789
9876543210r   r   src)r   r   r   distributionr"   r   r   r   r   rm   find	translate)r3   r   cur_syshas_templatehas_comment	is_sourcerevert_numbersdescs           r4   get_comparablez!SoftwareProperties.get_comparable  s    glki |<<n	 *?'4;66G%zzz6;;;E$^ k			%	 	  )|[)nn^,,. .r6   c                     g }| j         j        D ]d}|j        s[|| j        j        vrM|| j        j        vr?|| j        j        vr1|| j        j        vr#|| j        j        vr|	                    |           e|S )z>Return a list of sources that are not part of the distribution)
r    r   r   r"   r   r   r   disabled_sourcesr   r   )r3   isv_sourcesr   s      r4   get_isv_sourcesz"SoftwareProperties.get_isv_sources-  s    K"' ' '~ 	'$+222$+333$+333$+666888v&&&r6   c                     | j         j        S )z-Return the list of CDROM based distro sources)r"   r   rV   s    r4   get_cdrom_sourcesz$SoftwareProperties.get_cdrom_sources:  s    ;$$r6   c                 ,    |j         | j        j        v dfS )zReturn 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.F)r~   r"   download_compsr   s     r4   get_comp_download_statez*SoftwareProperties.get_comp_download_state>  s    
 I33U;;r6   c                 z   g }| j         j        D ]'}|j        |k    r|                    |j                   (t          |          dk    r/t          | j         j        t          |          z            dk    rdS t          |          dk    r/t          | j         j        t          |          z            dk    rdS dS )zReturn 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.r   )TF)FT)FF)r"   r   r   r   r   r   r   r   )r3   r   r   r   s       r4   get_comp_child_statez'SoftwareProperties.get_comp_child_stateE  s     E* & &>X%%LL%%%
5zzA~~DK%E

233q88}	UaDK%E

233q88 m ~r6   c                     | j                                          g | _        | j                            | j                    d S r   )r    refreshsourceslist_visibler"   get_sourcesrV   s    r4   r&   z%SoftwareProperties.reload_sourceslistZ  s>    DKD,-----r6   c                    | j         dz   | j         dz   | j         dz   g}|D ]#}t          j                            |          r nS$t	          d           t          |d         d          5 }|                    d           ddd           n# 1 swxY w Y   d	}t          j                            |          rZt          j        |          t          j	                 }|t          j
        z  s't	          d
|z             t          j        |d           |D ]>}g }t          j                            |          rt          |d          5 }|                                }ddd           n# 1 swxY w Y   t          j                            d          }t          |d          5 }|D ]L}|                                D ] }	|                    d|	z            dk    r n!|                    |           M|                                D ]1}
|                    d|
d|                    |
          d           2	 ddd           n# 1 swxY w Y   @dS )z+Write the current apt configuration to filez/etc/apt/apt.conf.d/10periodicz#/etc/apt/apt.conf.d/20auto-upgradesz+/etc/apt/apt.conf.d/15adept-periodic-updatezNo config found, creating oner   rr    Nz/etc/cron.daily/aptz file '%s' not executable, fixingi  rs   zAPT::PeriodiczAPT::Periodic::%szAPT::Periodic::z "z";
)r   rO   rP   r   r   rw   rx   rQ   statST_MODES_IXUSRchmod	readlinesr   r   subtreer   r
  rC   )r3   	conffilesr   acpermperiodiccontentcnfr   r   r   s              r4   rH   zSoftwareProperties.write_config_  s,    >>CCKKMI
   			  +,,,	!c"" a	               
B	w~~b WR[[&dT\! 025666
U  H Hg		!	! H(C   	"AKKMM'	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"n$$_55 (C   
	HA  dxxzz  .#6771<< = ggdmmm 88:: H HaGGGQQQ

1FGGGGH
	H 
	H 
	H 
	H 
	H 
	H 
	H 
	H 
	H 
	H 
	H 
	H 
	H 
	H 
	HH Hs7   )BBBE))E-	0E-	#BII
	I
	c                 l    | j                             d           | j                                          dS )zQBackup the existing sources.list files and write the current
       configurationz.saveN)r    backupsaverV   s    r4   r   z#SoftwareProperties.save_sourceslist  s6     	G$$$r6   c                    t          |          }t          j                            | j                  rt          j        d| j        z            D ]}t          |          5 }|D ]}|                                                    d          r*|t          |          k    rRt          j        	                    t          j        
                    |                    d         c cddd           c S 	 ddd           n# 1 swxY w Y   dS )zs
    helper that checks if a given line is in the source list
    return the channel name or None if not found
    z	%s/*.list#r   N)r   rO   rP   rQ   CHANNEL_PATHglobrw   ry   rz   splitextbasename)r3   srclinesrcentryfilenamer   r   s         r4   _get_channel_from_linez)SoftwareProperties._get_channel_from_line  s~   
 7##H	w~~d'(( Eid.? ?@@ E E((^^ 	Eq E Edzz||&&s++ ;t,,,,W%%bg&6&6x&@&@AA!DDD	E 	E 	E 	E 	E 	E 	E 	E 	E 	E -E	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 4s   !BD3DD	D	c                     |                                 j        }|                     |          }|r$| j        d|d}|                     |           dS dS )z
    helper that adds the gpg key of the channel to the apt
    keyring *if* the channel is in /usr/share/app-install/channels
    r   z.keyTF)r   r   r<  r5  add_key)r3   shortcutr9  channelkeyps        r4   &check_and_add_key_for_channel_shortcutz9SoftwareProperties.check_and_add_key_for_channel_shortcut  sf    
 ""$$)G))'22G  ---www7d
ll4T5r6   c                     dS )z) abstract interface to keep the UI alive N rV   s    r4   update_interfacez#SoftwareProperties.update_interface  s      r6   c                     |                     d          s|S |                                d         }	 |                    dd          d         }n# t          $ r d}Y nw xY wd|d| j        j        d|}|S )z
    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'
    httpr   r   r	   mainzdeb )rz   r   
IndexErrorr"   codename)r3   r   repoareass       r4   expand_http_linez#SoftwareProperties.expand_http_line  s     ??6"" k::<<?D

3q!!!$   "ddDK$8$8$8%%ADKs   A AAFc                     	 t          |                                          }n# t          $ r Y dS w xY w|                     ||          S )z*
    Add a source for the given line.
    F)r   ry   r   add_source_from_shortcut)r3   r   enable_source_coder?  s       r4   add_source_from_linez'SoftwareProperties.add_source_from_line  sY    #DJJLL11#   UU ((3EFFFs   !$ 
22c           	         |                                 j        }|j        }|                     |          }|rdnd}||dd         z   }t          ||          }t          ||          }|j        s|j        rdS |                     |          s|                                 | j                            |j	        |j
        |j        |j        |j        |j        |j                   | j                            ||j
        |j        |j        |j        |j        |j                   |                                  | j        r?| j        j        r3ddl}	|	                                }
|
                    |j                   d	S )
z
    Add a source with the given shortcut and add the signing key if the
    site is a known channel or the shortcut implementer adds it.
    r   z	# deb-srcr   NF)r   r   architecturesr   )sources_listT)r   r   sourceparts_filerM  r   rB  r>  r    r   rm   r   r   r   r   r   rS  r   r   r   aptCache)r3   r?  rP  deb_liner   debsrc_entry_typedebsrc_linenew_deb_entrynew_debsrc_entryrV  caches              r4   rO  z+SoftwareProperties.add_source_from_shortcut  s    ##%%*H$D$$X..H%7H		[#hqrrl2K$//M";55  0 8 U66x@@ +&*&+&,!.!6+0'4'B  D D D 	*)-).)/!1!9.3'7'E  G G G 	!!###| 9+ 9


		"2"78884r6   Tc                    |rt          |t                    r,|                     |          }|                     |d           nm|k|                     |d           t	          j        |          }d|_        d|_        |                     |d           d|_        |                     |d           dS t          |t                    r|                     |          }|dS |j        t          j	        
                    d          k    r3| j        j                            t          d|j                             	 | j                            |           n# t           $ r Y nw xY w|                                  dS )zRemove the given sourceTNFr   zDir::Etc::sourcelistr#  )r   )r   rG   r   remove_sourcer   rm   r   r   r   r   	find_filer    r   r   r   r   r   r   )r3   r   remove_source_codes      r4   r_  z SoftwareProperties.remove_source  s    	FC	 	  *..v6664((((65))) 6""65)))65)))f &# 5,,V44f~f
 {gn../EFFFF
"";r#D#D#DEEE
f%%%%   
 d 	!!#####s   =E 
E%$E%c                     t           j                            |          sdS 	 | j                            |          }|S #  Y dS xY w)z7Add a gnupg key to the list of trusted software vendorsF)rO   rP   rQ   r-   r   )r3   rP   r   s      r4   r>  zSoftwareProperties.add_key  sL    7>>$ ult$$
uus	   ? Ac                     t          j                    }|                    |                    d                     |                                 |                     |j                  S )z<Add a gnupg key from a utf-8 data string (e.g. copy-n-paste)zutf-8)tempfiler   rx   encoder{   r>  r~   )r3   keydatatmps      r4   add_key_from_dataz$SoftwareProperties.add_key_from_data'  sO    

%
'
'CIIgnnW%%&&&IIKKK<<!!!r6   c                 L    	 | j                             |           dS #  Y dS xY w)z<Remove a gnupg key from the list of trusted software vendorsTF)r-   rm)r3   keyids     r4   
remove_keyzSoftwareProperties.remove_key.  s0    tuus    #c                 J    	 | j                                          dS #  Y dS xY w)z Run apt-key update TF)r-   r   rV   s    r4   update_keyszSoftwareProperties.update_keys6  s0    
lTUUs    "c                     t          |t          j                  sJ |j        }|r|j        }|j        }n7t          j        |          }|                    |          }|j        }|j        }|j        d|d|dS )z" Return the PackageKit package id ;)	r   r   Packagecurrent_verver_strarchDepCacheget_candidate_verr~   )r3   	apt_cachepkgcur_ververrt  depcache	candidates           r4   get_package_idz!SoftwareProperties.get_package_id>  s    c7?+++++oG o|#I....s33	~(((CCC..r6   c                 F   t          j        |           }|                    |          }g }	 |j                            d          D ]?}|D ]:\  }}}	|                    |          dk    r|                    | |                    ;@n# t          t          f$ r g cY S w xY w|S )zF Get the package dependencies, which can be filtered out by a pattern Depends)	r   ru  rv  depends_list_strrh   r
  r   KeyError	TypeError)
rw  packagepatternr{  r|  dependenciesdep_listdep_namedep_verdep_ops
             r4   get_dependenciesz#SoftwareProperties.get_dependenciesL  s     	**H**733IL!266yAA 	= 	=H-5 = =)'6==))R// ''	((;<<<=	= i    			 s   AB BB)NNr   )F)Tr   )B__name__
__module____qualname__r5  rd   r   rangere   RELEASE_UPGRADES_LTSRELEASE_UPGRADES_NEVERrj   r5   r2   r(   rI   rW   r[   r^   r`   rp   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r'   r   r   r   r   r   r   rY   r  r  r  r  r  r  r&   rH   r   r<  rB  rE  rM  rQ  rO  r_  r>  rh  rl  rn  r}  staticmethodr  rD  r6   r4   r   r   C   s        2, A d5588nn	 heg!'+ '+ '+ '+R  - - -    .  (% % %L L L( ( (&  0     2; ; ;% % %N         $ $ $
$ $ $
  
$ $ $$ $ $$ $ $$ $ $83 3 3  $ $ $          % % %N. . .*  % % %< < <  *. . .
,H ,H ,H\       0 0 0  "	G 	G 	G 	G$ $ $ $L&$ &$ &$ &$P  " " "    / / /    <  r6   r   __main__)-r   r   hashlibr   r   rO   r6  r|   r8   r0   rd  stringr   ImportErrorrG   r$  r*   r+   r   xml.sax.saxutilsr   configparserr   r   r   r!   aptsources.distror@   r
   aptsources.sourceslistr   r   "softwareproperties.shortcuthandlerr   softwareproperties.shortcutsr   gi.repositoryr   objectr   r  spr   rp   r   rD  r6   r4   <module>r     s  4         				 				           m))) ,,,,    ( ' ' ' ' ' # # # # # #(''''''' ( ( (''''''''(                               = = = = = = = = G G G G G G 9 9 9 9 9 9      X X X X X X X Xv z"%&&(()))  ##### s3   3 AA
A 	AA+A2 2B ?B 