HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //proc/self/root/lib/python3/dist-packages/uaclient/__pycache__/apt.cpython-38.pyc
U

��Jh��
@s<ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
mZddlm
Z
mZmZmZmZmZmZddlZddlmZddlmZmZmZmZmZmZmZddlm Z ddl!m"Z"dZ#d	Z$d
Z%dZ&dZ'd
Z(dZ)dZ*dZ+dZ,dZ-dZ.dZ/dZ0dZ1dZ2dZ3dZ4dZ5ej6�7e d�ej6�7e d�gej6�7e d�ej6�7e d�ej6�7e d�ej6�7e d �gd!�Z8d"d#d$gZ9e�:�Z;e�<e�=e>��Z?ej@Gd%d&�d&ejA��ZBed'd(eCfd)eCfd*eCfg�ZDd+d,�ZEeEeCeCd-�d.d/��ZFd0d1�ZGeCeeCd2�d3d4�ZHd�eeCeeCee
eCeCfeCd5�d6d7�ZIe
dd8�d�eeCee
eCeCfeCd9�d:d;��ZJGd<d=�d=�ZKd>d?�ZLd@dA�ZMeCeeCdB�dCdD�ZNd�eCeOeeCdF�dGdH�ZPd�ee
eCeCfeCdI�dJdK�ZQe�RejSejTfe9�eCdL�dMdN��ZUd�eeCeeeCee
eCeCfeCdO�dPdQ�ZVeCeejWdR�dSdT�ZXeeCeejWdR�dUdV�ZYd�ejWeeCeejZdW�dXdY�Z[eeCeCeOeCeCdZ�d[d\�Z\d�eeCeCeOeCeCeOeCd]�d^d_�Z]d�eCeCeCeeCeCeeCeeOdd`�dadb�Z^dcdd�Z_dedf�Z`d�eCeCeeCeeCddg�dhdi�Zadjdk�Zbdldm�Zcdndo�Zddpdq�ZeeCeOdr�dsdt�ZfeeDdu�dvdw�ZgeeCdu�dxdy�ZhddeBjifeeCeeCeeBddz�d{d|�Zjeekdu�d}d~�Zleekdu�dd��Zmeejdu�d�d��Znd�d��Zoddu�d�d��ZpeeCeCd��d�d��ZqeeCeCd��d�d��ZreeCd��d�d��Zsd�d��Ztd�d��ZueeCe
eCeeCeeCffd��d�d��ZveCdu�d�d��ZwdS)��N)�	lru_cache�wraps)�Dict�Iterable�List�
NamedTuple�Optional�Set�Union)�AcquireProgress)�event_logger�
exceptions�gpg�messages�secret_manager�system�util)�ESM_APT_ROOTDIR)�status_cache_filegN@z  # ubuntu-pro-clientzDir::Etc::netrc/zDir::Etc::netrcparts/zDir::State::lists/a�/*
 * Autogenerated by ubuntu-pro-client
 * Do not edit this file directly
 *
 * To change what ubuntu-pro-client sets, use the `pro config set`
 * or the `pro config unset` commands to set/unset either:
 *      global_apt_http_proxy and global_apt_https_proxy
 * for a global apt proxy
 * or
 *      ua_apt_http_proxy and ua_apt_https_proxy
 * for an apt proxy that only applies to Ubuntu Pro related repos.
 */
z$Acquire::http::Proxy "{proxy_url}";
z%Acquire::https::Proxy "{proxy_url}";
z4Acquire::http::Proxy::esm.ubuntu.com "{proxy_url}";
z5Acquire::https::Proxy::esm.ubuntu.com "{proxy_url}";
z/etc/apt/trusted.gpg.d/z/usr/share/keyringsz/usr/lib/apt/methods/httpsz /usr/sbin/update-ca-certificatesz//etc/apt/apt.conf.d/90ubuntu-advantage-aptproxyz*/var/lib/apt/periodic/update-success-stampz/var/lib/dpkg/status)ZxenialZbionicZfocalZjammyz�# Written by ubuntu-pro-client
Types: deb{deb_src}
URIs: {url}
Suites: {suites}
Components: main
Signed-By: {keyrings_dir}/{keyring_file}
zetc/apt/sources.listzvar/lib/dpkg/statuszetc/apt/apt.conf.dzetc/apt/preferences.dzvar/cache/apt/archives/partialzvar/lib/apt/lists/partial)�files�foldersg�?g@g$@c@seZdZe�Ze�ZdS)�
AptProxyScopeN)�__name__�
__module__�__qualname__�object�GLOBAL�UACLIENT�rr�./usr/lib/python3/dist-packages/uaclient/apt.pyrcsr�InstalledAptPackage�name�version�archcst���fdd��}|S)z*Decorator ensuring apt_pkg is initialized.cs"tj�d�dkrt���||�S)N�Dir�)�apt_pkg�config�get�init)�args�kwargs��frr�new_fqsz"ensure_apt_pkg_init.<locals>.new_f)r)r-r.rr,r�ensure_apt_pkg_initnsr/��a�bcCst�||�S�N)r&�version_comparer0rrrr4|sr4c
Cs|�d�\}}tj�d�sdSzFt���4}tjddd�||||�tj�	|d�gt
td�W5QRXWn�tj
k
r�}znt�dt|��|jd	kr�t|j���}t�d
|�r�tj|d��nt�d|�r�tj|d��tjt|�d
��W5d}~XYn&tjk
�rtjt
|d��YnXdS)aValidate apt credentials for a PPA.

    @param repo_url: private-ppa url path
    @param username: PPA login username.
    @param password: PPA login password or resource token.

    @raises: UbuntuProError for invalid credentials, timeout or unexpected
        errors.
    �://z/usr/lib/apt/apt-helperNz
download-filez{}://{}:{}@{}/pool/zapt-helper-output)Ztimeout�retry_sleepszError running apt-helper: %s�dz401\s+unauthorized|httperror401)�repozconnection timed out�Zdetail)Zsecondsr8)�split�os�path�exists�tempfileZTemporaryDirectoryr�subp�format�join�APT_HELPER_TIMEOUT�APT_RETRIESr
�ProcessExecutionError�LOG�error�strZ	exit_code�stderr�lower�re�searchZAPTInvalidCredentialsZ
APTTimeout�APTUnexpectedError�
subprocessZTimeoutExpiredZAPTCommandTimeout)�repo_url�username�passwordZprotocol�	repo_pathZtmpd�erHrrr�assert_valid_apt_credentials�sB

���
 �rS)�	apt_error�returncCsVt�}|���d�D]<}|rt�d|�}|rd|��d�d�d}|�|�q|S)aAParse apt update errors for invalid apt config in user machine.

    This functions parses apt update errors regarding the presence of
    invalid apt config in the system, for example, a ppa that cannot be
    reached, for example.

    In that scenario, apt will output a message in the following formats:

    The repository 'ppa 404 Release' ...
    Failed to fetch ppa 404 ...

    On some releases, both of these errors will be present in the apt error
    message.

    :param apt_error: The apt error string
    :return: a NamedMessage containing the error message
    �
z2(Failed to fetch |The repository .)(?P<url>[^\s]+)z- �urlz/distsr)�set�stripr:rJrK�	groupdict�add)rT�failed_repos�lineZ
pattern_matchZrepo_url_matchrrr�(_parse_apt_update_for_invalid_apt_config�s��r^)�cmd�	error_msg�override_env_varsrUc
Cs�ztj|dt|d�\}}Wn�tjk
r�}zrt�dt|�t|��dt|j�kr\t�	��n$t
|j�}|r�tjd�t
|��d��|r�|nt|�}tj|d��W5d}~XYnX|S)	a�Run an apt command, retrying upon failure APT_RETRIES times.

    :param cmd: List containing the apt command to run, passed to subp.
    :param error_msg: The string to raise as UbuntuProError when all retries
       are exhausted in failure.
    :param override_env_vars: Passed directly as subp's override_env_vars arg

    :return: stdout from successful run of the apt command.
    :raise UbuntuProError: on issues running apt-cache policy.
    T)Zcapturer6raz Error running apt command %s: %sz%Could not get lock /var/lib/dpkg/lockrV)r\r9N)rr?rCr
rDrErFrGrH�APTProcessConflictErrorr^�APTInvalidRepoErrorrA�sortedrL)r_r`ra�out�_errrRr\�msgrrr�run_apt_command�s&�

�rh)�maxsize)r`rarUcCstddg||d�S)N�	apt-cache�policy)r_r`ra)rh)r`rarrr�get_apt_cache_policy�s
�rlc@s$eZdZdd�Zdd�Zdd�ZdS)�PreserveAptCfgcCs||_i|_dSr3)�apt_func�current_apt_cfg)�selfrnrrr�__init__	szPreserveAptCfg.__init__cs&tj��fdd����D�|_|��S)Ncsi|]}|t���|���qSr)�copy�deepcopyr()�.0�key��cfgrr�
<dictcomp>sz,PreserveAptCfg.__enter__.<locals>.<dictcomp>)r&r'�keysrorn)rprrvr�	__enter__
s

�zPreserveAptCfg.__enter__cCs4tj}|j��D]}|�||j|�qt��dSr3)r&r'roryrXZinit_system)rp�type�value�	tracebackrwrurrr�__exit__szPreserveAptCfg.__exit__N)rrrrqrzr~rrrrrmsrmcCs.tj��D]}tj�|�q
t��t�d�Sr3)r&r'ry�clearr)�Cache�rurrr�get_apt_pkg_cachesr�cCsnzPt�tj��D]}t�d|�stj�|�qtj�dt�t�	�t�
d�WStk
rhiYSXdS)Nz^Acquirer$)�_ensure_esm_cache_structurer&r'ryrJrKrrXrr)r��	Exceptionr�rrr�get_esm_apt_pkg_cache&sr�)�pkg_namerUc	CsTtt��4}z||}Wn tk
r6YW5QR�dSXW5QRX|jrP|jjSdSr3)rmr��KeyError�current_ver�ver_str)r��cache�packagerrr�get_pkg_version>s
r�F)r��check_esm_cacherUc
Cstt��`}z||}Wn tk
r6YW5QR�dSXt�|�}|�|�}|s^W5QR�dS|j}W5QRX|sv|Stt���}|�rz||}Wn$tk
r�|YW5QR�SXt�|�}	|	�|�}
|
s�|W5QR�S|
j}t�||�dk�r|W5QR�SW5QRX|S)Nr)	rmr�r�r&�DepCache�get_candidate_verr�r�r4)r�r�r�r��	dep_cache�	candidateZcandidate_versionZ	esm_cacheZesm_packageZ
esm_dep_cacheZ
esm_candidateZesm_candidate_versionrrr�get_pkg_candidate_versionKs@





���r�)rarUc
Cs�z�ztddg|d�}Wn�tjk
rR}zt�dt|��t���W5d}~XYnbtj	k
r�}ztj
|jd��W5d}~XYn2tjk
r�}ztj
|jd��W5d}~XYnXW5t��X|S)N�apt-get�update�r_raz Error running apt-get update: %s�Zrepo_msgr9)rl�cache_clearrhr
rbrErFrGZAPTUpdateProcessConflictErrorrcZAPTUpdateInvalidRepoErrorrgZUbuntuProError�APTUpdateFailed)rarerRrrr�run_apt_update_commandws�
$
r�)�sources_list_pathcCs*tt���}tj�dtj�|��tj�dd�tj�dd�t��}|�	�t
�}tj�tj�d�d�}t�
|�}z�z"|�|�||d�W5QRXWntttd	d
�k
r�}zt�dt|��t���W5d}~XYn4tk
�r}ztjt|�d��W5d}~XYnXW5t��XW5QRXdS)
NzDir::Etc::sourcelistzDir::Etc::sourcepartszN.O.F.O.L.D.E.RzAPT::List-Cleanup�0zDir::State::Lists�lockr�ErrorrzError updating apt cache: %sr9)rmr�r&r'rXr;r<�abspath�
SourceList�read_main_listrrAZfind_dirZFileLockrlr�r��getattrrErFrGr
rb�SystemErrorr�)r�r��sources_list�fetch_progressZ	lock_filer�rRrrr�update_sources_list�s0
�
�
&r�)�packages�apt_optionsrarUc
Cs�|dkrg}ztdddg|||d�}WnZtjk
rTt�d|�t���Yn2tjk
r�}ztj|jd��W5d}~XYnX|S)Nr��install�--assume-yesr�z)Error running apt install for packages %sr�)	rhr
rbrErFZAPTInstallProcessConflictErrorrcZAPTInstallInvalidRepoErrorrg)r�r�rarerRrrr�run_apt_install_command�s"���
 r�)�originrUc	Cs\t�}tt��@}|jD]2}|j}|r|jD]\}}|j|kr*|�|�q*qW5QRXt|�Sr3)	rXrmr�r�r��	file_listr�r[�list)r��resultr�r��installed_version�file�_rrr� get_installed_packages_by_origin�s


r�c		Cs�|dkrgSt�}tt��`}t�|�}|jD]H}|j}|r,|�|�}|r,||kr,|jD]\}}|j	|krV|�
|�qVq,W5QRXt|�Sr3)rXrmr�r&r�r�r�r�r�r�r[r�)	r�r�r�r�r�r�r�r�r�rrr�;get_installed_packages_with_uninstalled_candidate_in_origin�s




r�)r��exclude_originrUcs6g}|jD]&}�fdd�|jD�}|r
|�|�q
|S)Ncs(g|] \}}|jdkr|j�kr|�qS)Znow)Z	componentr�)rtr�r��r�rr�
<listcomp>�s

�z3get_remote_versions_for_package.<locals>.<listcomp>)Zversion_listr��append)r�r�Zvalid_versionsr"Z
valid_originsrr�r�get_remote_versions_for_package�s

�r�)�suites�series�updates_enabledrNrUcCsRd}|D]D}||krqd}d|kr8|s8t�d||�d}|dj|||d�7}q|S)Nr%�-updatesz?Not enabling apt suite "%s" because "%s-updates" is not enabledz# zC{maybe_comment}deb {url} {suite} main
# deb-src {url} {suite} main
)�
maybe_commentrW�suite)rE�warningr@)r�r�r�rN�contentr�r�rrr�_get_list_file_content	s(���r�)r�r�r�rN�keyring_file�include_deb_srcrUc	sZ�fdd�|D�}|s0t�d��dd�|D�}|r8dnd}tj|d�|�t||d�}|S)	Ncsg|]}�|kr|�qSrr�rtr��r�rrr�+sz-_get_sources_file_content.<locals>.<listcomp>zPNot enabling service-related -updates suites because "%s-updates" is not enabledcSsg|]}d|kr|�qS)r�rr�rrrr�2sz deb-srcr%� )rWr�Zkeyrings_dirr��deb_src)rEr��DEB822_REPO_FILE_CONTENTr@rA�KEYRINGS_DIR)	r�r�r�rNr�r�Zappliable_suitesr�r�rr�r�_get_sources_file_content#s$���r�)�
repo_filenamerN�credentialsr�r��
snapshot_urls�check_updates_pocketrUcCs2z|�d�\}}Wntk
r.d}|}YnXtj�|�t��j}	|�d�r\|dd�}t	|||�d}
|r�d}
t
dd	gtj�}|�
�D]&}d
�|	�|kr�q�d|kr�q�d}
q�q�|g|D]}
t|
||�q�|	tk�rtj�t|�}tj�t|�}t�||�t||	|
|�}nt||	|
||�}t�||�dS)z�Add an authenticated apt repo and credentials to the system.

    @raises: InvalidAPTCredentialsError when the token provided can't access
        the repo PPA.
    �:Zbearer�/N���TFrjrkza={}-updatesz	o=Ubuntu,)r:�
ValueErrorrZsecretsZ
add_secretrZget_release_infor��endswithrSrhrZAPT_POLICY_FAILED�
splitlinesr@�add_apt_auth_conf_entry�SERIES_NOT_USING_DEB822r;r<rAr��APT_KEYS_DIRrZexport_gpg_keyr�r��
write_file)r�rNr�r�r�r�r�rOrPr�r�rkr]rWZsource_keyring_fileZdestination_keyring_filer�rrr�add_auth_apt_repoCsX


�
��r�c
Cst�}d|kr|�d�\}}n|}|�d�s4|d7}tj�|�rLt�|�}nd}dj|||t	d�}d}g}	|�
�D]\}
|s�|
��}t|�dkr�|d}||kr�|	�|�d	}qr||kr�|	�|�d	}|	�|
�qr|s�|	�|�|	�d�tj
|d
�|	�dd�d
S)zBAdd or replace an apt auth line in apt's auth.conf file or conf.d.r5r�r%z:machine {repo_path} login {login} password {password}{cmt})rQ�loginrPZcmtF��TrV���modeN)�!get_apt_auth_file_from_apt_configr:r�r;r<r=r�	load_filer@�APT_AUTH_COMMENTr��lenr�r�rA)
rNr�rP�
apt_auth_file�	_protocolrQZorig_contentZrepo_auth_lineZadded_new_authZ	new_linesr]Z
split_lineZcurr_line_reporrrr��sF
��	



r�cs�d|kr|�d�\}}n|}|�d�r2|dd�}t�}tj�|�r�t�|�}dj|d��d�	�fdd	�|�
�D��}|s�t�|�ntj||d
d�dS)z+Remove a repo from the shared apt auth filer5r�Nr�zmachine {repo_path}/ login)rQrVcsg|]}�|kr|�qSrr)rtr]�Zauth_prefixrrr��sz2remove_repo_from_apt_auth_file.<locals>.<listcomp>r�r�)
r:r�r�r;r<r=rr�r@rAr��ensure_file_absentr�)rNr�rQr�Zapt_authr�rr�r�remove_repo_from_apt_auth_file�s

�r�)r�rNr�r�rUcCs^t�|�|�d�r&t�t�|d��|rBtj�t|�}t�|�|g|D]}t	|�qLdS)z>Remove an authenticated apt repo and credentials to the systemz.sourcesr�N)
rr�r�rZset_filename_extensionr;r<rAr�r�)r�rNr�r�rWrrr�remove_auth_apt_repo�s


�
r�cCsB|�d�\}}|�d�r$|dd�}dj||d�}t�||�dS)z.Add an apt preferences file and pin for a PPA.r5r�Nr�z<Package: *
Pin: release o={origin}
Pin-Priority: {priority}
)r��priority)r:r�r@rr�)Zapt_preference_filerNr�r�r�rQr�rrr�add_ppa_pinning�s
��r�cCsZt�dddtg�\}}|r,|�d�ddSt�dddtg�\}}|�d�d�d�SdS)	z7Return to patch to the system configured APT auth file.�
apt-config�shellru�'r�z90ubuntu-advantager�N)rr?�APT_CONFIG_AUTH_PARTS_DIRr:�APT_CONFIG_AUTH_FILE�rstrip)rerfrrrr��s
�
�r�c
Cs~|�d�\}}|�d�r$|dd�}d}t�dddtg�\}}|rP|�d	�d
}|�dd�}tt�tj	�
||d�|����S)
zEList any apt files in APT_CONFIG_LISTS_DIR given repo_url and series.r5r�Nr�z/var/lib/apt/listsr�r�rur�r�r�z
_dists_{}*)r:r�rr?�APT_CONFIG_LISTS_DIR�replacerd�globr;r<rAr@)rNr�r�rQZ	lists_dirrerfZaptlist_filenamerrr�find_apt_list_files�s$

����r�cCst||�D]}t�|�q
dS)z?Remove any apt list files present for this repo_url and series.N)r�rr�)rNr�r<rrr�remove_apt_list_filessr�)�pkgrUcCs
|t�kSr3)�get_installed_packages_names)r�rrr�is_installedsr�)rUc	CsLg}tt��6}|jD](}|j}|r|�t|j|j|jd��qW5QRX|S)N)r!r"r#)	rmr�r�r�r�r r!r�r#)Z	installedr�r�r�rrr�get_installed_packagess

��r�cCst�}dd�|D�}|S)NcSsg|]
}|j�qSr)r!)rtr�rrrr�*sz0get_installed_packages_names.<locals>.<listcomp>)r�)Zpackage_listZ	pkg_namesrrrr�(sr�)�
http_proxy�https_proxy�proxy_scoperUcCs�|s|rB|rBd}|tjkr d}n|tjkr.d}t�tjj|d��d}|r�|tjkrf|tj|d�7}n|tjkr�|t	j|d�7}|r�|tjkr�|t
j|d�7}n|tjkr�|tj|d�7}|dkr�t|}|dkr�t
�t�nt
�t|�dS)a�
    Writes an apt conf file that configures apt to use the proxies provided as
    args.
    If both args are None, then no apt conf file is written. If this function
    previously wrote a conf file, and was run again with both args as None,
    the existing file is removed.

    :param http_proxy: the url of the http proxy apt should use, or None
    :param https_proxy: the url of the https proxy apt should use, or None
    :return: None
    r%z	UA-scoped�global)Zscope)Z	proxy_urlN)rrr�event�inforZSETTING_SERVICE_PROXY_SCOPEr@�APT_CONFIG_UA_PROXY_HTTP�APT_CONFIG_GLOBAL_PROXY_HTTP�APT_CONFIG_UA_PROXY_HTTPS�APT_CONFIG_GLOBAL_PROXY_HTTPS�APT_PROXY_CONFIG_HEADERrr��APT_PROXY_CONF_FILEr�)r�r�r��messageZapt_proxy_configrrr�setup_apt_proxy.sD

�
�

�
�

�rcCs d}tj�t�rt�t�j}|Sr3)r;r<r=�APT_UPDATE_SUCCESS_STAMP_PATH�stat�st_mtime�Z
cache_timerrr�get_apt_cache_timefsr
cCs d}tj�t�rt�t�j}|Sr3)r;r<r=�DPKG_STATUS_PATHr
r)Zstatus_timerrr�get_dpkg_status_timemsrcCs$t�}|dkrdStj�|tjj�Sr3)r
�datetimeZ
fromtimestamp�timezoneZutcrrrr�get_apt_cache_datetimetsrcs�tjtj�td�dd��tdtd}t�fdd�|D��rBdSt�t�tdD]}t�	|�qTtdD]}tj
|ddd	�qldS)
Nz**/*T)�	recursiverrc3s|]}|�kVqdSr3r)rtr��Zexisting_filesrr�	<genexpr>�sz._ensure_esm_cache_structure.<locals>.<genexpr>i�)�exist_okr�)r�r;r<rAr�ESM_BASIC_FILE_STRUCTURE�allrZensure_folder_absentZcreate_file�makedirs)Z
desired_filesr�Zfolderrrrr�{s��
r�cCs�t��sdSt�ddlm}ddlm}ddlm}m	}d}d}t
��}|dkr^||�d}|�dg�D]D}|�dd�d	kr�|�d
d�dk}|�dd�d
krj|�d
d�dk}qj||�}	|r�|	�
�d|jkr�|	��n|	��t���r||�}
|�r|
�
�d|jk�r|
��n|
��tt��x}t��}|��Gdd�dt�}
|
�}z|�||d�Wn8tk
�r�}zt�d�t|���W5d}~XYnXW5QRXdS)Nr)�status)�ApplicationStatus)�ESMAppsEntitlement�ESMInfraEntitlementF�servicesr!r%zesm-appsZ	availableZnoZyesz	esm-infrac@s,eZdZejd�dd�Zejd�dd�ZdS)z-update_esm_caches.<locals>.EsmAcquireProgress)�itemcSst�d�|j��dS)NzFetched ESM Apt Cache item: {})rE�debugr@�uri�rprrrr�done�sz2update_esm_caches.<locals>.EsmAcquireProgress.donecSst�d�|j��dS)Nz&Failed to fetch ESM Apt Cache item: {})rEr�r@r!r"rrr�fail�s
�z2update_esm_caches.<locals>.EsmAcquireProgress.failN)rrrr&ZAcquireItemDescr#r$rrrr�EsmAcquireProgress�sr%z%Failed to fetch the ESM Apt Cache: {})rZis_current_series_ltsr�Zuaclient.actionsrZ(uaclient.entitlements.entitlement_statusrZuaclient.entitlements.esmrrr�readr(Zapplication_statusZDISABLEDZsetup_local_esm_repoZdisable_local_esm_repoZis_current_series_active_esmrmr�r&r�r�rr�r�rEr�r@rG)rwrrrrZapps_availableZinfra_availableZcurrent_status�serviceZappsZinfrar�r�r%r�rRrrr�update_esm_caches�sP��

��

	r(��
package_namesZ
error_messagecCs(tdddddgt|�|ddid�d	S)
a�
    Remove APT packages from the system.

    Setting DEBIAN_FRONTEND to noninteractive makes sure no prompts will
    appear during the operation. In this case, --force-confdef will
    automatically pick the default option when some debconf should appear.
    In the absence of a default option, --force-confold will automatically
    choose to keep the old configuration file.
    r��remover��$-o Dpkg::Options::="--force-confdef"�$-o Dpkg::Options::="--force-confold"�DEBIAN_FRONTEND�noninteractive�raN�rhr�r)rrr�remove_packages�s
���r2cCs(tdddddgt|�|ddid�d	S)
a�
    Purge APT packages from the system - remove everything.

    Setting DEBIAN_FRONTEND to noninteractive makes sure no prompts will
    appear during the operation. In this case, --force-confdef will
    automatically pick the default option when some debconf should appear.
    In the absence of a default option, --force-confold will automatically
    choose to keep the old configuration file.
    r��purger�r,r-r.r/r0Nr1r)rrr�purge_packages�s
���r4�r*cCst|dddgddid�dS)a6
    Install packages, allowing downgrades.

    The --allow downgrades flag is needed because sometimes we need to
    reinstall the packages to a lower version (passed in the package_name
    string, as package=version).

    Setting DEBIAN_FRONTEND to noninteractive makes sure no prompts will
    appear during the operation. In this case, --force-confdef will
    automatically pick the default option when some debconf should appear.
    In the absence of a default option, --force-confold will automatically
    choose to keep the old configuration file.
    z--allow-downgradesr,r-r.r/)r�raN)r�r5rrr�reinstall_packagess��r6cCs*tj��D]}tj�|�q
t��tjSr3)r&r'ryrZinit_configr�rrr�_get_apt_configsr7c	Cs"tt��}|�|�}W5QRX|Sr3)rmr7r�)Zbase_key�apt_cfgZapt_cfg_keysrrr�get_apt_config_keys(s
r9)�	cfg_namesrUc	CsNi}tt��8}|D],}|�|�}t|�s6|�|�p4d}|||<qW5QRX|S)z�
    Get all APT configuration values for the given config names. If
    one of the config names is not present on the APT config, that
    config name will have a value of None
    N)rmr7r(rGZ
value_list)r:Zapt_cfg_dictr8Zcfg_nameZ	cfg_valuerrr�get_apt_config_values/s

r;cCsd}d}tj�|�r|S|S)Nz/etc/apt/sources.listz&/etc/apt/sources.list.d/ubuntu.sources)r;r<r=)Zold_sources_pathZnew_sources_pathrrr�get_system_sources_fileEs
��r<)NN)NN)F)N)NN)N)F)F)N)xrrr�enumr�Zloggingr;rJrMr>�	functoolsrr�typingrrrrrr	r
r&Zapt.progress.baserZuaclientrr
rrrrrZuaclient.defaultsrZuaclient.files.state_filesrrBr�r�r�r�rrrrrr�r�ZAPT_METHOD_HTTPS_FILEZCA_CERTIFICATES_FILErr	rr�r�r<rArrCZget_event_loggerr�Z	getLoggerZreplace_top_level_logger_namerrE�unique�EnumrrGr r/r4rSr^rhrlrmr�r�r��boolr�r�Zretryrbr�r�r�ZPackager�r�ZVersionr�r�r�r�r�r�r�r�r�r�r�r�r�r�rr�floatr
rrr�r(r2r4r6r7r9r;r<rrrr�<module>sl$$	�����
�+�(��+����-��
�(�
����� ��'��A/��
��8E
�