HEX
Server: Apache/2.4.65 (Debian)
System: Linux kubikelcreative 5.10.0-35-amd64 #1 SMP Debian 5.10.237-1 (2025-05-19) x86_64
User: www-data (33)
PHP: 8.4.13
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/softwareproperties/__pycache__/SoftwareProperties.cpython-39.pyc
a

���V�{�@s�ddlmZmZddlZddlZddlmZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
zddlmZWney�ejZYn0ddlZddl
mZddlmZzddlmZWney�ddlmZYn0ddlmZddlZddlZddlZd	d
lmZddlmZm Z d	dl!m"Z"d	d
l!m#Z#d	dl!m$Z$e#j%e$j%e"j%gZ&Gdd�de'�Z(dd�Z%e)dk�r�e(�Z*e+e*�,��e*�-d�dS)�)�absolute_import�print_functionN)�md5)�	maketrans)�NamedTemporaryFile)�escape)�ConfigParser)�gettext�)�AptAuth)�SourcesList�SourceEntry)�	shortcuts)�ppa)�cloudarchivec@s�eZdZdZdZeed��\ZZZ	edede	diZ
dsd	d
�Zdd�Zd
d�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Z d5d6�Z!d7d8�Z"d9d:�Z#d;d<�Z$d=d>�Z%d?d@�Z&dAdB�Z'dCdD�Z(dEdF�Z)dGdH�Z*dIdJ�Z+dKdL�Z,dMdN�Z-dOdP�Z.dQdR�Z/dSdT�Z0dUdV�Z1dWdX�Z2dYdZ�Z3d[d\�Z4d]d^�Z5d_d`�Z6dadb�Z7dtddde�Z8dudfdg�Z9dvdidj�Z:dkdl�Z;dmdn�Z<dodp�Z=dqdr�Z>dS)w�SoftwarePropertiesz /usr/share/app-install/channels/z$/etc/update-manager/release-upgrades�ZnormalZlts�neverN�/cCs�|d|_||_|dkr&tj�d|�|dkr2d}||_||_t�|_t	j
��|_
g|_d|_
|��|��|��g|_t|d�|_t�|j�dS)z� Provides the core functionality to configure the used software 
        repositories, the corresponding authentication keys and 
        update automation z/etc/popularity-contest.confrZDirNz/usr/share/software-properties/F)�rootdir)�
popconfiler�apt_pkg�config�set�options�datadirr�sourceslist�
aptsources�distro�
get_distroZseen_server�modified_sourceslist�reload_sourceslist�backup_sourceslist�backup_apt_confZcustom_mirrorsr�apt_key�atexit�register�wait_for_threads)�selfrrr�r)�G/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py�__init__Ws$
zSoftwareProperties.__init__cCs*t��D]}|jt��jkr|��qdS)z9 wait for all running threads (PPA key fetchers) to exit N)�	threading�	enumerateZidentZcurrent_thread�join)r(�tr)r)r*r'{sz#SoftwareProperties.wait_for_threadscCs6i|_tj��D] }tj�tj|�}||j|<qdS)z$Backup all apt configuration optionsN)�apt_conf_backup�softwareproperties�CONF_MAP�keysrr�find_i)r(�option�valuer)r)r*r#�sz"SoftwareProperties.backup_apt_confcCs:|j��D]"}tj�tj|t|j|��q
|��dS)z$Restore the stored apt configurationN)	r0r3rrrr1r2�str�write_config)r(r5r)r)r*�restore_apt_conf�s
�z#SoftwareProperties.restore_apt_confcCs�tj�tjd�dkr�tj�tjd�dkr>tj�d�r>tjStj�tjd�dkrptj�tjd�dkrptj	Stj�tjd�dkr�tj�tjd�dkr�tj
SdSn6tj�tjd�dkr�tj�tjd�dkr�tjSdSdS)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
z/usr/bin/unattended-upgrade�autodownloadN)rrr4r1r2�os�path�exists�UPDATE_INST_SEC�UPDATE_DOWNLOAD�
UPDATE_NOTIFY�
UPDATE_MANUAL�r(r)r)r*�get_update_automation_level�s&
����z.SoftwareProperties.get_update_automation_levelcCs|tjkr<tj�tjdtd��tj�tjdtd��n�|tjkrxtj�tjdtd��tj�tjdtd��n�|tjkr�tj�tjdtd��tj�tjdtd��nHtj�tjdtd��tj�tjdtd��tj�tjdtd��|�	�dS)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. r;r
r<rr:N)
r1r@rrrr2r7rArB�set_modified_config)r(�stater)r)r*�set_update_automation_level�s


z.SoftwareProperties.set_update_automation_levelcCs:|tj�tjd�ks6tj�tjdt|��|��dS)z8Set the interval in which we check for available updatesr:N)rrr4r1r2rr7rF)r(Zdaysr)r)r*�set_update_interval�sz&SoftwareProperties.set_update_intervalcCstj�tjd�S)z3 Returns the interval of the apt periodic cron job r:)rrr4r1r2rDr)r)r*�get_update_interval�sz&SoftwareProperties.get_update_intervalcCsltj�|j�s|jSt�}|�|j�|�dd�rf|�dd��	�}|j
��D]\}}||krL|SqL|jS)z�
    return the release upgrade policy:
     RELEASE_UPGRADES_NORMAL,
     RELEASE_UPGRADES_LTS,
     RELEASE_UPGRADES_NEVER
    ZDEFAULTZPrompt)r=r>r?�RELEASE_UPGRADES_CONF�RELEASE_UPGRADES_NORMALr�readZ
has_option�get�lower�release_upgrades_policy_map�items)r(�parser�type�k�vr)r)r*�get_release_upgrades_policy�s
z.SoftwareProperties.get_release_upgrades_policycCs�tj�|j�s2t|jd�}|�d|j|�dSt|jd�}tdd�}|D]>}|��}|�	��
d�r||�d|j|�qL|�|d	�qL|��t�
|j|j�t�|j|j�dS)
z
    set the release upgrade policy:
     RELEASE_UPGRADES_NORMAL,
     RELEASE_UPGRADES_LTS,
     RELEASE_UPGRADES_NEVER
     �wz[DEFAULT]
Prompt=%s
T�rzw+)�mode�promptz
Prompt=%s
�
)r=r>r?rK�open�writerPr�striprO�
startswith�flush�shutilZcopymode�name�copy)r(�i�f�out�liner)r)r*�set_release_upgrades_policy�s
z.SoftwareProperties.set_release_upgrades_policyc	Cs�tj�|j�r|t|j����d�}d}|D]L}z0|�d�\}}|dkr\|�d���dkr\d}Wq*t	ytYq*Yq*0q*|SdSdS)	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 r[F�=ZPARTICIPATE�"�yesTN)
r=r>r?rr\rM�splitr^rO�
ValueError)r(�linesZactiverg�keyr6r)r)r*�get_popcon_participation�sz+SoftwareProperties.get_popcon_participationcs�|dkrd�nd�tj�|j�r`t|jd��"}�fdd�|D�}Wd�q�1sT0YnRt�}|�tdd	��d
��|��}g}|�	d|�|�	dt
���|�	d
�t|jd��|�dS)z? Enable or disable the participation in the popularity contest Trk�norXcsg|]}t�dd�|��qS)z^(PARTICIPATE=)(".+?")z\1"%s")�re�sub)�.0rg�r6r)r*�
<listcomp>
s�z@SoftwareProperties.set_popcon_pariticipation.<locals>.<listcomp>Nz/dev/urandom�rbizMY_HOSTID="%s"
zPARTICIPATE="%s"
zUSE_HTTP="yes"
rW)r=r>r?rr\r�updaterMZ	hexdigest�appendr7�
writelines)r(Z
is_helpfulrrn�m�idr)rur*�set_popcon_pariticipations 
�&
z,SoftwareProperties.set_popcon_pariticipationcCst|jj�dkrd|j_dSd|j_i}g}|�|jj�|�|jj�|D]<}|j|vrx|jD]}||j�	|�q`qLt
|j�||j<qLt|jj�dkr�|jj||jj
<|jjD]b}|j|v�s|j|vr�tt
||j�t
|j�A�dks�tt
|j�|jjA�dks�d|j_dSq�dS)z�Return True if all distro componets are also available as 
       source code. Otherwise return Flase. Special case: If the
       configuration cannot be represented return Noner
FTrN)�lenr�source_code_sourcesZget_source_code�extend�main_sources�
child_sources�template�comps�addr�
cdrom_sourcesZcdrom_comps�source_template�
enabled_comps)r(Z	templates�sources�source�compr)r)r*�get_source_code_states6

���z(SoftwareProperties.get_source_code_statecCs�d|jfd|jfd|jfd|jffD]\}}td||f�q(|jrzd|jjfd|jjffD]\}}td||f�q`td�d	S)
z4Print the data of a source entry to the command linezURI:zComps:zEnabled:zValid:z %s %sz	MatchURI:zBaseURI:r[N)�urir��disabled�invalid�printr�Z	match_uri�base_uri)r(r�Zlabelr6r)r)r*�print_source_entryAs

�

�z%SoftwareProperties.print_source_entrycCs,td�|jD]}t|���qtd�dS)zPrint the complete sources.listzSTART SOURCES.LIST:zEND SOURCES.LIST
N)r�rr7�r(r�r)r)r*�massive_debug_outputNs
z'SoftwareProperties.massive_debug_outputcCs ||j_|j�|�}|��|S)z! change the main download server )r�default_serverZ
change_server�set_modified_sourceslist)r(Zserver�resr)r)r*�change_main_download_serverUsz.SoftwareProperties.change_main_download_servercCs|j�|�|��dS)z Enable a component of the distroN)r�enable_componentr��r(r�r)r)r*r�\sz#SoftwareProperties.enable_componentcCs|j�|�|��dS)z!Disable a component of the distroN)r�disable_componentr�r�r)r)r*r�asz$SoftwareProperties.disable_componentcCs&|jjjD]}|j|kr
|Sq
dS�N)rr�Zchildrenrb)r(rbr�r)r)r*�_find_template_from_stringfs
z-SoftwareProperties._find_template_from_stringcCsht|t�r|�|�}|jjD]}|j|kr|j�|�q|jjD]}|j|kr@|j�|�q@|�	�dS)�7Enable a child repo of the distribution main repositoryN)
�
isinstancer7r�rr�r�r�removerr�)r(r�r�r)r)r*�disable_child_sourceks



z'SoftwareProperties.disable_child_sourcecCsLt|t�r|�|�}|jdkr(|jj}n|j}|jj||jd�|��dS)r�N)r��dist)	r�r7r�r�rr�Z
add_sourcerbr�)r(r�Z	child_urir)r)r*�enable_child_sourcexs



z&SoftwareProperties.enable_child_sourcecCsFg}|�|jj�|�|jj�|jjD]}|j�|�q(|��dS)z%Remove all distro source code sourcesN)r�rr�r�rrr�r��r(r�r�r)r)r*�disable_source_code_sources�sz.SoftwareProperties.disable_source_code_sourcescCs�g}|�|jj�|�|jj�|jjD]}|j�|�q(|D]2}|j�d|j|j	|j
d|jj�|�d|j
�q>|jjD]:}|j�d|jjj|jjj|j
d|jj�|�d|j
�qz|��dS)z0Enable source code source for all distro sources�deb-srczAdded by software-propertiesr
N)r�rr�r�rrr�r�r�r�r��list�index�filer�r�r�rbr�r�r)r)r*�enable_source_code_sources�s0��z-SoftwareProperties.enable_source_code_sourcescCs4g|_|jjD] }t|j|jd�}|j�|�qdS)z+Store a backup of the source.list in memory�rgr�N)�sourceslist_backuprr�r
rgr�ry)r(r�Z
source_bkpr)r)r*r"�sz%SoftwareProperties.backup_sourceslistcCs.|��|jjD]}t|�|kr|SqdSr�)r!rr�r7)r(rgr�r)r)r*�_find_source_from_string�s

z+SoftwareProperties._find_source_from_stringcCs*t|t�r|�|�}|j|_|��dS)z&Enable or disable the selected channelN)r�r7r�r�r�r�r)r)r*�toggle_source_use�s


z$SoftwareProperties.toggle_source_usecCsTt|jj�D]B\}}t|�|kr|jj|j}t||�|jj|<|��dSqdS)NTF)r-rr�r7r�r
r�)r(Z	old_entryZ	new_entryr��entryr�r)r)r*�replace_source_entry�sz'SoftwareProperties.replace_source_entrycCs|��|��dS)zNRevert all settings to the state when software-properties 
       was launchedN)r9�revert_sourceslistrDr)r)r*�revert�szSoftwareProperties.revertcCsFg|j_|jD]"}t|j|jd�}|jj�|�q|��|��dS)z6Restore the source list from the startup of the dialogr�N)	rr�r�r
rgr�ry�save_sourceslistr!)r(r�Zsource_resetr)r)r*r��s
z%SoftwareProperties.revert_sourceslistcCs0d|_|jr|jjr|��|��|��dS)zCThe sources list was changed and now needs to be saved and reloadedTN)r r�
massive_debugr�r�r!rDr)r)r*r��s
z+SoftwareProperties.set_modified_sourceslistcCs|��dS)z+Write the changed apt configuration to fileN)r8rDr)r)r*rF�sz&SoftwareProperties.set_modified_configcCsb|jdkr�|jrxdt|j���|jf}t|j�dkrN|jD]}|d|7}q<|jdvrh|dtd�7}|d|j	7}nBd|j	|jf}|jD]}|d|7}q�|jdvr�|dtd�7}|Sd	|jj
}|jdvr�|d
td�7}|jr�|d|j7}|jjdk�rZ|jD]L}|j�|��rJ|jj
D] }|j|k�r&|d|j
7}�q&n|d|7}�q|SdS)
z5Render a nice output to show the source in a treeviewNz<b>%s</b> %sr
z %s)r�zrpm-srcz
(Source Code)z
%sz<b>%s %s</b>z	<b>%s</b>z (%s)zSource CodeF)r��commentrr^r�r~r�rS�_r��description�childZ
has_component�
componentsrb)r(r��contents�cr�r)r)r*�
render_source�s<
�





z SoftwareProperties.render_sourcecCs�d}d}d}d}tdd�}|jr@d}|jj}|jj|jkr^d}nd|j|j|jf}|jr^d}|j	�
d�rnd}|||||�|�fS)z&extract attributes to sort the sourcesr
�
0123456789Z
9876543210rz%s %s %s�src)rr�r�Zdistributionrr�r�r�r�rS�find�	translate)r(r�Zcur_sysZhas_templateZhas_commentZ	is_sourceZrevert_numbersZdescr)r)r*�get_comparables$
�z!SoftwareProperties.get_comparablecCsbg}|jjD]P}|js||jjvr||jjvr||jjvr||jjvr||jjvr|�	|�q|S)z>Return a list of sources that are not part of the distribution)
rr�r�rr�r�r�Zdisabled_sourcesrry)r(Zisv_sourcesr�r)r)r*�get_isv_sources's
�
�
�
�
�z"SoftwareProperties.get_isv_sourcescCs|jjS)z-Return the list of CDROM based distro sources)rr�rDr)r)r*�get_cdrom_sources4sz$SoftwareProperties.get_cdrom_sourcescCs|j|jjvdfS)z�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.F)rbrZdownload_compsr�r)r)r*�get_comp_download_state8sz*SoftwareProperties.get_comp_download_statecCs�g}|jjD]}|j|kr|�|j�qt|�dkrPt|jjt|�A�dkrPdSt|�dkrxt|jjt|�A�dkrxdSdSdS)z�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.r)TF)FT)FFN)rr�r�r�r�r~r�r)r(r�r�r�r)r)r*�get_comp_child_state?s
��z'SoftwareProperties.get_comp_child_statecCs"|j��g|_|j�|j�dSr�)rZrefreshZsourceslist_visibler�get_sourcesrDr)r)r*r!Ts
z%SoftwareProperties.reload_sourceslistc	Cs8|jd|jd|jdg}|D]}tj�|�r qLq td�t|dd�d}tj�|�r�t�|�tj}|tj	@s�td|�t�
|d	�|D]�}g}tj�|�r�t|d
���}tj
�d�}t|d�}|D]2}|��D]}	|�d|	�dkr�q�q�|�|�q�|��D]}
|�d
|
|�|
�f��q
|��q�dS)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-updatezNo config found, creating onerrWz/etc/cron.daily/aptz file '%s' not executable, fixingi�rXz
APT::PeriodiczAPT::Periodic::%szAPT::Periodic::%s "%s";
N)rr=r>�isfiler�r\r?�stat�ST_MODE�S_IXUSR�chmod�	readlinesrrZsubtreer�r�r]r4�close)r(Z	conffilesreZacZpermZperiodicZcontentZcnfrgrordr)r)r*r8Ys:�

zSoftwareProperties.write_configcCs|j�d�|j��dS)zRBackup the existing sources.list files and write the current 
       configurationz.saveN)rZbackup�saverDr)r)r*r��sz#SoftwareProperties.save_sourceslistcCszt|�}tj�|j�rvt�d|j�D]N}t|�D]@}|���d�rFq2|t|�kr2tj�	tj�
|��dSq2q&dS)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�#rN)r
r=r>r?�CHANNEL_PATH�globr\r^r_�splitext�basename)r(�srclineZsrcentryrergr)r)r*�_is_line_in_whitelisted_channel�s$z2SoftwareProperties._is_line_in_whitelisted_channelcCs|�t|��Sr�)�*check_and_add_key_for_whitelisted_shortcut�shortcut_handler)r(r�r)r)r*�*check_and_add_key_for_whitelisted_channels�sz=SoftwareProperties.check_and_add_key_for_whitelisted_channelscs�|j|jj|jj��d�\}}|�|�}|rDd|j|f}|�|�|jd|joV|jj	if��fdd�}t
j|d�}|��|S)z�
    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.
    ��codenamerz	%s/%s.key�	keyservercs�\}}|fi|��dSr�r))�func�kwargs�Zcdatar)r*�addkey_func�szRSoftwareProperties.check_and_add_key_for_whitelisted_shortcut.<locals>.addkey_func)�target)
�expandrr�r|rOr�r��add_keyrr�r,ZThread�start)r(�shortcutr�Z_fnameZchannelZkeypr��workerr)r�r*r��s�


�z=SoftwareProperties.check_and_add_key_for_whitelisted_shortcutcCsdS)z) abstract interface to keep the UI alive Nr)rDr)r)r*�update_interface�sz#SoftwareProperties.update_interfacecCs\|�d�s|S|��d}z|�dd�d}WntyDd}Yn0d||jj|f}|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'
    Zhttpr� r
�mainzdeb %s %s %s)r_rl�
IndexErrorrr�)r(rgZrepoZareasr)r)r*�expand_http_line�s

z#SoftwareProperties.expand_http_lineFcCs|jt|���|d�S)z*
    Add a source for the given line.
    )r��enable_source_code)�add_source_from_shortcutr�r^)r(rgr�r)r)r*�add_source_from_line�s
�z'SoftwareProperties.add_source_from_linec	Cs
|j|jj|jj��d�\}}|�|�}|r0dnd}||dd�}t||�}t||�}|jsd|jrhdS|�|�}	|j	j
|j|j|j
|j|j|j|jd�|j	j
||j|j
|j|j|j|jd�|��|	r�|	�d�|j�r|jj�rd	dl}
|
��}|j|jd
�dS)z�
    Add a source with the given shortcut and add the signing key if the
    site is in whitelist or the shortcut implementer adds it.
    r�r�z	# deb-srcrNF)r�r��
architectures�r)Zsources_listT)r�rr�r|rOr�r
r�r�rr�rSr�r�r�r�r�r�r�r.rrx�aptZCache)r(r�r��deb_liner�Zdebsrc_entry_type�debsrc_lineZ
new_deb_entryZnew_debsrc_entryr�r��cacher)r)r*r��sF�





��
z+SoftwareProperties.add_source_from_shortcutTcCs�|rrt|t�r&|�|�}|�|d�nH|durn|�|d�t�|�}d|_d|_|�|d�d|_|�|d�dSt|t�r�|�|�}|dur�dS|jtj	�
d�kr�|jj�
td|jd��z|j�|�Wnty�Yn0|��dS)zRemove the given sourceTNFr�zDir::Etc::sourcelist�)r�)r�r7r��
remove_sourcercrSr�r�rrZ	find_filerr�ryr
r�rmr�)r(r�Zremove_source_coder)r)r*r��s0




z SoftwareProperties.remove_sourcecCs>tj�|�sdSz|j�|�}|��|WSYdS0dS)z7Add a gnupg key to the list of trusted software vendorsFN)r=r>r?r$r��KeysModified)r(r>r�r)r)r*r�"szSoftwareProperties.add_keycCs,t��}|�|�d��|��|�|j�S)z<Add a gnupg key from a utf-8 data string (e.g. copy-n-paste)zutf-8)�tempfilerr]�encoder`r�rb)r(Zkeydata�tmpr)r)r*�add_key_from_data-sz$SoftwareProperties.add_key_from_datacCs.z|j�|�|��WdSYdS0dS)z<Remove a gnupg key from the list of trusted software vendorsTFN)r$Zrmr�)r(Zkeyidr)r)r*�
remove_key4szSoftwareProperties.remove_keycCs,z|j��|��WdSYdS0dS)z Run apt-key update TFN)r$rxr�rDr)r)r*�update_keys=s
zSoftwareProperties.update_keys)NNr)F)F)T)?�__name__�
__module__�__qualname__r�rKr��rangerLZRELEASE_UPGRADES_LTSZRELEASE_UPGRADES_NEVERrPr+r'r#r9rErHrIrJrVrhrpr}r�r�r�r�r�r�r�r�r�r�r�r"r�r�r�r�r�r�rFr�r�r�r�r�r�r!r8r�r�r�r�r�r�r�r�r�r�r�r�r�r)r)r)r*rDs~
��
$'




	'
-

(
(	rcCs4tD]}||�}|dur|Sqt�d|��dS)NzUnable to handle input '%s')�_SHORTCUT_FACTORIESr�ShortcutException)r�Zfactory�retr)r)r*r�Gs

r��__main__).�
__future__rrrrcZhashlibrrrr=r�rar,r%r��stringr�ImportErrorr7r�rZxml.sax.saxutilsrZconfigparserrr	r�rZaptsources.distror1r�aptsources.sourceslistrr
r�rrrr�r�objectrr��spr�rVrhr)r)r)r*�<module>s\�