Your IP : 216.73.216.182


Current Path : /usr/lib/python3/dist-packages/uaclient/__pycache__/
Upload File :
Current File : //usr/lib/python3/dist-packages/uaclient/__pycache__/apt.cpython-38.pyc

U

��Kj��
@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
Csztj�d�sdS|�d�\}}t�}|d}|�d�s@|d}n|}dj|||d�}�zzRtj	||dd	�t
���0}	tjdd
d�||�tj�
|	d�gttd
�W5QRXWn�tjk
�r@}
ztt�dt|
��|
jdk�r t|
j���}t�d|��rtj|d��nt�d|��r tj|d��tjt|
�d��W5d}
~
XYn&tjk
�rdtjt|d��YnXW5t�|�XdS)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-helperN�://z-validation�/z9machine {repo_path} login {username} password {password}
)�	repo_path�username�password���modez
download-filez
{}://{}/pool/zapt-helper-output)Ztimeout�retry_sleepszError running apt-helper: %s�dz401\s+unauthorized|httperror401)�repozconnection timed out�Zdetail)Zsecondsr?) �os�path�exists�split�!get_apt_auth_file_from_apt_config�endswith�formatr�ensure_file_absent�
write_file�tempfileZTemporaryDirectory�subp�join�APT_HELPER_TIMEOUT�APT_RETRIESr
�ProcessExecutionError�LOG�error�strZ	exit_code�stderr�lower�re�searchZAPTInvalidCredentialsZ
APTTimeout�APTUnexpectedError�
subprocessZTimeoutExpiredZAPTCommandTimeout)�repo_urlr8r9Zprotocolr7�
apt_auth_fileZ	auth_pathZrepo_path_slashZ	auth_lineZtmpd�erSrrr�assert_valid_apt_credentials�sR


��

��
 �r\)�	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�striprDrUrV�	groupdict�add)r]�failed_repos�lineZ
pattern_matchZrepo_url_matchrrr�(_parse_apt_update_for_invalid_apt_config�s��rg)�cmd�	error_msg�override_env_varsr^c
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)Zcapturer=rjz Error running apt command %s: %sz%Could not get lock /var/lib/dpkg/lockr_)rer@N)rrKrNr
rOrPrQrRrS�APTProcessConflictErrorrg�APTInvalidRepoErrorrL�sortedrW)rhrirj�out�_errr[re�msgrrr�run_apt_command�s&�

�rq)�maxsize)rirjr^cCstddg||d�S)N�	apt-cache�policy)rhrirj)rq)rirjrrr�get_apt_cache_policys
�ruc@s$eZdZdd�Zdd�Zdd�ZdS)�PreserveAptCfgcCs||_i|_dSr3)�apt_func�current_apt_cfg)�selfrwrrr�__init__szPreserveAptCfg.__init__cs&tj��fdd����D�|_|��S)Ncsi|]}|t���|���qSr)�copy�deepcopyr()�.0�key��cfgrr�
<dictcomp>sz,PreserveAptCfg.__enter__.<locals>.<dictcomp>)r&r'�keysrxrw)ryrrr�	__enter__s

�zPreserveAptCfg.__enter__cCs4tj}|j��D]}|�||j|�qt��dSr3)r&r'rxr�raZinit_system)ry�type�value�	tracebackr�r~rrr�__exit__$szPreserveAptCfg.__exit__N)rrrrzr�r�rrrrrvsrvcCs.tj��D]}tj�|�q
t��t�d�Sr3)r&r'r��clearr)�Cache�r~rrr�get_apt_pkg_cache.sr�cCsnzPt�tj��D]}t�d|�stj�|�qtj�dt�t�	�t�
d�WStk
rhiYSXdS)Nz^Acquirer$)�_ensure_esm_cache_structurer&r'r�rUrVr�rarr)r��	Exceptionr�rrr�get_esm_apt_pkg_cache5sr�)�pkg_namer^c	CsTtt��4}z||}Wn tk
r6YW5QR�dSXW5QRX|jrP|jjSdSr3)rvr��KeyError�current_ver�ver_str)r��cache�packagerrr�get_pkg_versionMs
r�F)r��check_esm_cacher^c
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)	rvr�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_versionZs@





���r�)rjr^c
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�rhrjz Error running apt-get update: %s�Zrepo_msgr@)ru�cache_clearrqr
rkrPrQrRZAPTUpdateProcessConflictErrorrlZAPTUpdateInvalidRepoErrorrpZUbuntuProError�APTUpdateFailed)rjrnr[rrr�run_apt_update_command�s�
$
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: %sr@)rvr�r&r'rarArB�abspath�
SourceList�read_main_listrrLZfind_dirZFileLockrur�r��getattrrPrQrRr
rk�SystemErrorr�)r�r��sources_list�fetch_progressZ	lock_filer�r[rrr�update_sources_list�s0
�
�
&r�)�packages�apt_optionsrjr^c
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�)	rqr
rkrPrQZAPTInstallProcessConflictErrorrlZAPTInstallInvalidRepoErrorrp)r�r�rjrnr[rrr�run_apt_install_command�s"���
 r�)�originr^c	Cs\t�}tt��@}|jD]2}|j}|r|jD]\}}|j|kr*|�|�q*qW5QRXt|�Sr3)	rarvr�r�r��	file_listr�rd�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)rarvr�r&r�r�r�r�r�r�rdr�)	r�r�r�r�r�r�r�r�r�rrr�;get_installed_packages_with_uninstalled_candidate_in_origin�s




r�)r��exclude_originr^cs6g}|jD]&}�fdd�|jD�}|r
|�|�q
|S)Ncs(g|] \}}|jdkr|j�kr|�qS)Znow)Z	componentr�)r}r�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_packages

�r�)�suites�series�updates_enabledrYr^cCsRd}|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_commentr`�suite)rP�warningrG)r�r�r�rY�contentr�r�rrr�_get_list_file_contents(���r�)r�r�r�rY�keyring_file�include_deb_srcr^c	sZ�fdd�|D�}|s0t�d��dd�|D�}|r8dnd}tj|d�|�t||d�}|S)	Ncsg|]}�|kr|�qSrr�r}r��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�Asz deb-srcr%� )r`r�Zkeyrings_dirr��deb_src)rPr��DEB822_REPO_FILE_CONTENTrGrL�KEYRINGS_DIR)	r�r�r�rYr�r�Zappliable_suitesr�r�rr�r�_get_sources_file_content2s$���r�)�
repo_filenamerY�credentialsr�r��
snapshot_urls�check_updates_pocketr^cCs2z|�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.
    �:Zbearerr6N���TFrsrtza={}-updatesz	o=Ubuntu,)rD�
ValueErrorrZsecretsZ
add_secretrZget_release_infor�rFr\rqrZAPT_POLICY_FAILED�
splitlinesrG�add_apt_auth_conf_entry�SERIES_NOT_USING_DEB822rArBrLr��APT_KEYS_DIRrZexport_gpg_keyr�r�rI)r�rYr�r�r�r�r�r8r9r�r�rtrfr`Zsource_keyring_fileZdestination_keyring_filer�rrr�add_auth_apt_repoRsX


�
��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.r5r6r%z:machine {repo_path} login {login} password {password}{cmt})r7�loginr9ZcmtF��Tr_r:r;N)rErDrFrArBrCr�	load_filerG�APT_AUTH_COMMENTr��lenr�rIrL)
rYr�r9rZ�	_protocolr7Zorig_contentZrepo_auth_lineZadded_new_authZ	new_linesrfZ
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 filer5r6Nr�zmachine {repo_path}/ login)r7r_csg|]}�|kr|�qSrr)r}rf�Zauth_prefixrrr��sz2remove_repo_from_apt_auth_file.<locals>.<listcomp>r:r;)
rDrFrErArBrCrr�rGrLr�rHrI)rYr�r7rZZapt_authr�rr�r�remove_repo_from_apt_auth_file�s

�r�)r�rYr�r�r^cCs^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)
rrHrFrZset_filename_extensionrArBrLr�r�)r�rYr�r�r`rrr�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.r5r6Nr�z<Package: *
Pin: release o={origin}
Pin-Priority: {priority}
)r��priority)rDrFrGrrI)Zapt_preference_filerYr�r�r�r7r�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�shellr~�'r�z90ubuntu-advantager6N)rrK�APT_CONFIG_AUTH_PARTS_DIRrD�APT_CONFIG_AUTH_FILE�rstrip)rnrorrrrE�s
�
�rEc
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.r5r6Nr�z/var/lib/apt/listsr�r�r~r�r�r�z
_dists_{}*)rDrFrrK�APT_CONFIG_LISTS_DIR�replacerm�globrArBrLrG)rYr�r�r7Z	lists_dirrnroZaptlist_filenamerrr�find_apt_list_filess$

����r�cCst||�D]}t�|�q
dS)z?Remove any apt list files present for this repo_url and series.N)r�rrH)rYr�rBrrr�remove_apt_list_filessr�)�pkgr^cCs
|t�kSr3)�get_installed_packages_names)r�rrr�is_installed#sr�)r^c	CsLg}tt��6}|jD](}|j}|r|�t|j|j|jd��qW5QRX|S)N)r!r"r#)	rvr�r�r�r�r r!r�r#)Z	installedr�r�r�rrr�get_installed_packages's

��r�cCst�}dd�|D�}|S)NcSsg|]
}|j�qSr)r!)r}r�rrrr�9sz0get_installed_packages_names.<locals>.<listcomp>)r�)Zpackage_listZ	pkg_namesrrrr�7sr�)�
http_proxy�https_proxy�proxy_scoper^cCs�|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_SCOPErG�APT_CONFIG_UA_PROXY_HTTP�APT_CONFIG_GLOBAL_PROXY_HTTP�APT_CONFIG_UA_PROXY_HTTPS�APT_CONFIG_GLOBAL_PROXY_HTTPS�APT_PROXY_CONFIG_HEADERrrH�APT_PROXY_CONF_FILErI)r�r�r��messageZapt_proxy_configrrr�setup_apt_proxy=sD

�
�

�
�

�rcCs d}tj�t�rt�t�j}|Sr3)rArBrC�APT_UPDATE_SUCCESS_STAMP_PATH�stat�st_mtime�Z
cache_timerrr�get_apt_cache_timeusr
cCs d}tj�t�rt�t�j}|Sr3)rArBrC�DPKG_STATUS_PATHr
r)Zstatus_timerrr�get_dpkg_status_time|srcCs$t�}|dkrdStj�|tjj�Sr3)r
�datetimeZ
fromtimestamp�timezoneZutcrrrr�get_apt_cache_datetime�srcs�tjtj�td�dd��tdtd}t�fdd�|D��rBdSt�t�tdD]}t�	|�qTtdD]}tj
|ddd	�qldS)
Nz**/*T)�	recursiverrc3s|]}|�kVqdSr3r)r}r��Zexisting_filesrr�	<genexpr>�sz._ensure_esm_cache_structure.<locals>.<genexpr>i�)�exist_okr<)r�rArBrLr�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: {})rP�debugrG�uri�ryrrrr�done�sz2update_esm_caches.<locals>.EsmAcquireProgress.donecSst�d�|j��dS)Nz&Failed to fetch ESM Apt Cache item: {})rPr�rGr!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_esmrvr�r&r�r�rr�r�rPr�rGrR)r�rrrrZapps_availableZinfra_availableZcurrent_status�serviceZappsZinfrar�r�r%r�r[rrr�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�rjN�rqr�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�rjN)r�r5rrr�reinstall_packagess��r6cCs*tj��D]}tj�|�q
t��tjSr3)r&r'r�r�Zinit_configr�rrr�_get_apt_config-sr7c	Cs"tt��}|�|�}W5QRX|Sr3)rvr7r�)Zbase_key�apt_cfgZapt_cfg_keysrrr�get_apt_config_keys7s
r9)�	cfg_namesr^c	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)rvr7r(rRZ
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)rArBrC)Zold_sources_pathZnew_sources_pathrrr�get_system_sources_fileTs
��r<)NN)NN)F)N)NN)N)F)F)N)xr{r�enumr�ZloggingrArUrXrJ�	functoolsrr�typingrrrrrr	r
r&Zapt.progress.baserZuaclientrr
rrrrrZuaclient.defaultsrZuaclient.files.state_filesrrMr�r�r�r�rrrrrr�r�ZAPT_METHOD_HTTPS_FILEZCA_CERTIFICATES_FILErr	rr�r�rBrLrrNZget_event_loggerr�Z	getLoggerZreplace_top_level_logger_namerrP�unique�EnumrrRr r/r4r\rgrqrurvr�r�r��boolr�r�Zretryrkr�r�r�ZPackager�r�ZVersionr�r�r�r�r�r�r�r�rEr�r�r�r�r�rr�floatr
rrr�r(r2r4r6r7r9r;r<rrrr�<module>sl$$	�����
�:�(��+����-��
�(�
����� ��'��A/��
��8E
�