Current File : //usr/lib/python3/dist-packages/uaclient/__pycache__/system.cpython-312.pyc
�

��gyp���ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZddl
mZddlmZmZmZmZmZmZmZddlmZmZmZdZdZdZd	Zd
Zej@ejBe"��Z#dZ$dZ%ed
dejLfdejLfde'fde'fde'fg�Z(edde'fde'fdeejfdee'fdee)fdee)fdee)fdee'fdee'fg	�Z*edde'fde'fde'fde'fg�Z+ed d!ee'fd"ee'fd#ee'fd$ee'fd%ee'fd&ee'fd'ee'fd(ee'fd)ee'fd*ee'fd+ee'fd,ee'fd-ee'fd.ee'fg�Z,ed/d0eee'fd1eee'fg�Z-d2Z.d3ej^d4eejfd5�Z0d3ej^d4eejfd6�Z1ed�7�d4e*fd8��Z2d9�Z3ed�7�d4e'fd:��Z4ed�7�d4e'fd;��Z5ed�7�d4e,fd<��Z6ed�7�d4e'fd=��Z7ed�7�d4e+fd>��Z8ed�7�de'd4e9fd?��Z:ed�7�d4e9fd@��Z;ed�7�de'd4e9fdA��Z<ed�7�de'd4e9fdB��Z=ed�7�d4e9fdC��Z>ed�7�dhdDe'd4e9fdE��Z?ed�7�d4e9fdF��Z@ed�7�d4ee'e'ffdG��ZAed�7�de'd4e(fdH��ZBdIe'd4ee'fdJ�ZC		didKeee'dLeee'd4e9fdM�ZDdNe'd4e9fdO�ZEdPe'd4e'fdQ�ZFdjdPe'dRe)d4dfdS�ZG	dkdPe'dTe'dRee)d4dfdU�ZHdVe'd4dfdW�ZI					dldXee'dYeee)dZe9d[eeJd\eee'e'fd]e9d4ee'e'ffd^�ZK						dmdXee'dYeee)dZe9d[eeJd_eeeJd\eee'e'fd]e9d4ee'e'ffd`�ZLdae'd4dfdb�ZMdce'd4e9fdd�ZNdce'd4ee'fde�ZOd4e'fdf�ZPd4ee-fdg�ZQy)n�N)�	lru_cache)�rmtree)�Dict�List�
NamedTuple�Optional�Sequence�Set�Tuple)�defaults�
exceptions�utilz/var/run/reboot-requiredz/var/run/reboot-required.pkgsz/etc/machine-idz/var/lib/dbus/machine-idz!/usr/share/distro-info/ubuntu.csvz5(?P<release>\d+\.\d+) (LTS\s*)?(\((?P<series>\w+))?.*zd^(?P<major>[\d]+)[.-](?P<minor>[\d]+)[.-](?P<patch>[\d]+)-(?P<abi>[\d]+)-(?P<flavor>[A-Za-z0-9_-]+)$�
DistroInfo�eol�eol_esm�series�release�series_codename�
KernelInfo�uname_machine_arch�
uname_release�
build_date�proc_version_signature_version�major�minor�patch�abi�flavor�ReleaseInfo�distribution�pretty_version�CpuInfo�cpuinfo_cpu�cpuinfo_cpu_architecture�cpuinfo_cpu_family�cpuinfo_cpu_implementer�cpuinfo_cpu_part�cpuinfo_cpu_revision�cpuinfo_cpu_variant�
cpuinfo_model�cpuinfo_model_name�cpuinfo_stepping�cpuinfo_vendor_id�"sys_firmware_devicetree_base_model�
sysinfo_model�sysinfo_type�RebootRequiredPkgs�standard_packages�kernel_packagesz(Mon|Tue|Wed|Thu|Fri|Sat|Sun).*�uname�returnc��t�rtjd�ytjd�	tjdj|j��}tjj|jtjj�S#t$rtjd�YywxYw)NzPNot attempting to use timestamp of kernel changelog because we're in a containerz3Falling back to using timestamp of kernel changelogz1/usr/share/doc/linux-image-{}/changelog.Debian.gzzUnable to stat kernel changelog)
�is_container�LOG�warning�os�stat�formatr�datetime�
fromtimestamp�st_mtime�timezone�utc�	Exception)r4�stat_results  �1/usr/lib/python3/dist-packages/uaclient/system.py�_get_kernel_changelog_timestamprEqs����~����
5�	
���K�K�E�F���g�g�?�F�F��
�
�
�
��
� � �.�.�� � �(�"3�"3�"7�"7�
�	
�������5�6���s�A/B'�'C�Cc��tjt|j�}|� tjd�t
|�S|jd�}	tjj|d�}|j�*|jtjj��}|S#t$r#tjd�t
|�cYSwxYw)Nz*Unable to find build date in uname versionrz%a %b %d %H:%M:%S %Z %Yz-Unable to parse build date from uname version)�tzinfo)�re�search�RE_KERNEL_EXTRACT_BUILD_DATE�versionr8r9rE�groupr=�strptime�
ValueErrorrG�replacer@rA)r4�
date_match�date_str�dts    rD�_get_kernel_build_daterS�s������7����G�J������@�A�.�u�5�5�����"�H�6�
�
�
�
'�
'��2K�
L��
�y�y���Z�Z�x�0�0�4�4�Z�
5��
�I���6����C�D�.�u�5�5�6�s� B1�1)C�C)�maxsizec
��d}	td�}|j�d}tj�}|jj�}t|�}|jj�}tjt|�}|�*tj	d|�t||||ddddd��	St||||t|j!d��t|j!d��t|j!d��|j!d	�|j!d
���	S#t$rtj	d�Y��4wxYw)Nz/proc/version_signature�z*failed to process /proc/version_signature.zFailed to parse kernel: %s)	rrrrrrrrrrrrrr)�	load_file�splitrBr8r9r:r4�machine�striprSrrH�match�RE_KERNEL_UNAMEr�intrL)r�proc_version_signature_fullr4rrr�uname_matchs       rD�get_kernel_infor`�sG��%)�"�B�&/�0I�&J�#�)D�)J�)J�)L�Q�)O�&�
�H�H�J�E����,�,�.��'��.�J��M�M�'�'�)�M��(�(�?�M�:�K������0�-�@��1�'�!�+I������

�
	
��1�'�!�+I��k�'�'��0�1��k�'�'��0�1��k�'�'��0�1��!�!�%�(��$�$�X�.�

�
	
��/�B����@�A�B�s�D5�5E�Ec��ddlm}tj�st	d��|�D�cgc]}d|vr|��
}}tj
d�D�cgc]}dt
d|g�dvr|��}}|D�cgc]}|td�d��}}|D�cgc]}|td�d��}}|D�	cgc]}	|	|vr|	��
c}	Scc}wcc}wcc}wcc}wcc}	w)	Nr)�get_installed_packages_namesz9get_installed_ubuntu_kernels needs to be executed as rootzlinux-image-z/boot/vmlinu[x|z]-*zLinux kernel�filez/boot/vmlinu?-)�uaclient.aptrbr�we_are_currently_root�RuntimeError�glob�subp�len)
rb�package�linux_imagerc�vmlinux_kernel_files�package_name�linux_image_versions�	file_name�vmlinuz_versionsrKs
          rD�get_installed_ubuntu_kernelsrq�s$��9��%�%�'��G�
�	
�4�5����W�$�	��K���I�I�3�4����T�6�4�.�1�!�4�4�	
����AL��0<��S��(�*�+����
.���	�#�&�'�)�*����(����*�*�	����'��
������
s�
B<�C�6C�C�,
Cc�B�tddg�\}}|j�S)N�dpkgz--print-architecture)rhrZ)�out�_errs  rD�
get_dpkg_archrv�s"���f�4�5�6�I�C���9�9�;��c���	tdg�\}}|j�S#tj$r/	t	d�}d|vsd|vrYyd|vrYyYy#t
$rYYywxYwwxYw)N�systemd-detect-virtz/proc/1/cgroup�docker�buildkit�buildah�podman�)rhrZr
�ProcessExecutionErrorrWrB)rt�_�
proc_1_cgroups   rD�
get_virt_typer��s|����,�-�.���Q��y�y�{����+�+�
�		�%�&6�7�M��=�(�J�-�,G���m�+�����	��	��
�s,�!�A#�A�
A�	A�A#�A�A#c���d}d}d}i}i}d}	t|�}|jd�}td�|D�d�}|jd�D]=}	d|	vs�|	jdd	�\}
}|j�||
j�<�?		t|�}|jd�D]=}	d|	vs�|	jdd	�\}
}|j�||
j�<�?		t|�}t|jd�|jd�|jd
�|jd�|jd�|jd�|jd�|jd�|jd�|jd�|jd�||jd�|jd���S#t$r(t
j
d
j|��Y��vwxYw#t$r(t
j
d
j|��Y��LwxYw#t$r(t
j
d
j|��Y��twxYw)Nz
/proc/cpuinfoz
/proc/sysinfoz#/sys/firmware/devicetree/base/modelz

c3�DK�|]}|jd�s�|���y�w)�	processorN)�
startswith)�.0�ss  rD�	<genexpr>zget_cpu_info.<locals>.<genexpr>s����F�1�A�L�L��,E�Q�F�s� � r~�
�:rVzcould not open {}�cpuzCPU architecturez
cpu familyzCPU implementerzCPU partzCPU revisionzCPU variant�modelz
model name�stepping�	vendor_id�Model�Type)r#r$r%r&r'r(r)r*r+r,r-r.r/r0)
rWrX�nextrZ�FileNotFoundErrorr8�infor<r"�get)
�CPUINFO_FILE�SYSINFO_FILE�DEVICETREE_FILE�cpuinfo_values�sysinfo_values�devicetree_base_model�cpuinfo_content�cpuinfo_sections�first_cpu_content�line�key�value�sysinfo_contents
             rD�get_cpu_infor�	sU��"�L�"�L�;�O��N��N� ��<�#�L�1��+�0�0��8�� �F�(�F��
��&�+�+�D�1�	<�D��d�{�!�Z�Z��Q�/�
��U�.3�k�k�m��s�y�y�{�+�	<�
<�#�L�1��$�)�)�$�/�	<�D��d�{�!�Z�Z��Q�/�
��U�.3�k�k�m��s�y�y�{�+�	<�
>� )�/� :���"�&�&�u�-�!/�!3�!3�4F�!G�)�-�-�l�;� .� 2� 2�3D� E�'�+�+�J�7�+�/�/��?�*�.�.�}�=�$�(�(��1�)�-�-�l�;�'�+�+�J�7�(�,�,�[�9�+@�$�(�(��1�#�'�'��/����?�;����$�+�+�L�9�:�;��$�;����$�+�+�L�9�:�;���>����$�+�+�O�<�=�>�s5�G�H	�.H=�-H�H�	-H:�9H:�=-I.�-I.c���ddlm}ddlm}|j	�}|jr/|jjdi�jd�}|r|S|j
�}ttfD]B}tjj|�s�#t|�jd�}|s�@|cS|r|Sttj ��}|j#|�|S)z�
    Get system's unique machine-id or create our own in data_dir.
    We first check for the machine-id in machine-token.json before
    looking at the system file.
    r)�
machine_token)�machine_id_file�machineTokenInfo�	machineIdr�)�uaclient.filesr��uaclient.files.state_filesr��get_machine_token_filer��read�ETC_MACHINE_ID�DBUS_MACHINE_IDr:�path�existsrW�rstrip�str�uuid�uuid4�write)�cfgr�r��machine_token_file�
machine_id�fallback_machine_idr��contents        rD�get_machine_idr�Fs���-�:�&�=�=�?���'�'�'�5�5�9�9���
�

�#�k�
�	����)�.�.�0����1���
�7�7�>�>�$����o�,�,�T�2�G����	��"�"��T�Z�Z�\�"�J����*�%��rwc�@�t�}|jdd�}tjdd|jdd��}|jdd�}|jdd�}|r|s�tjt
|�}|s't
j|jdd�|�	��|j�}|xs|jd
d�}|st
j|���|xs|jdd�}t|||j�|�
�S)N�NAME�UNKNOWNz\.\d LTSz LTS�VERSIONr~�VERSION_CODENAME�
VERSION_ID)�orig_ver�mod_verr)rKr)r rrr!)�_parse_os_releaser�rH�subr[�REGEX_OS_RELEASE_VERSIONr
�ParsingErrorOnOSReleaseFile�	groupdict�MissingSeriesOnOSReleaseFiler�lower)�
os_releaser r!rrr[�
match_dicts       rD�get_release_infor�hs��"�$�J��>�>�&�)�4�L��V�V�K�����	�2�1N�O�N�
�^�^�.��
3�F��n�n�\�2�.�G������1�>�B����8�8�#���	�2�6���
��_�_�&�
��7�:�>�>�(�B�7����9�9�&��
��:�Z�^�^�I�r�:���!���|�|�~�%�	�rwc�*�tddg�\}}||vS)N�/usr/bin/ubuntu-distro-infoz--supported-esm�rh�rrtrus   rD�is_ltsr��s!���3�5F�G�H�I�C���S�=�rwc�<�tt�j�S�N)r�r�r�rwrD�is_current_series_ltsr��s���"�$�+�+�,�,rwc�*�tddg�\}}||vS)Nr�z--supportedr�r�s   rD�is_supportedr��s ���3�]�C�D�I�C���S�=�rwc�Z�t|�sytdd|dg�\}}t|�dkS)zCReturn True when Ubuntu series supports ESM and is actively in ESM.Fr�z--seriesz-yeolr)r�rhr]r�s   rD�
is_active_esmr��s8���&�>���	&�
�F�G�D��I�C���s�8�q�=�rwc�<�tt�j�Sr�)r�r�rr�rwrD�is_current_series_active_esmr��s���)�+�2�2�3�3rw�run_pathc�*�	tdg�y#tj$rYnwxYw	tgd��y#ttf$rYnwxYwdD]C}t
jj||�}t
jj|�s�Cyy)z>Checks to see if this code running in a container of some sort�ischrootF)ry�--quietz--containerT)�container_typezsystemd/container)	rhr
r�IOError�OSErrorr:r��joinr�)r��filenamer�s   rDr7r7�s���
��j�\�����+�+�
��
��
��
>�?����W��
��
��<����w�w�|�|�H�h�/��
�7�7�>�>�$����s��%�%�
7�A	�A	c�Z�ddlm}|j�D]}d|jvs�yy)z�Returns True if any package installed has "ubuntu-desktop" in the name.

    This includes ubuntu-desktop, ubuntu-desktop-minimal, kubuntu-desktop, etc.
    r)�aptzubuntu-desktopTF)�uaclientr��get_installed_packages�name)r�rjs  rD�
is_desktopr��s3����-�-�/����w�|�|�+���rwc���	td�}i}|j�D]<}|jdd�\}}|s�|j	�j	d�||<�>|S#t$rtd�}Y�iwxYw)Nz/etc/os-releasez/usr/lib/os-release�=rV�")rWr��
splitlinesrXrZ)�
file_contents�datar�r�r�s     rDr�r��s���9�!�"3�4�
��D��(�(�*�1���Z�Z��Q�'�
��U�����
�+�+�C�0�D��I�1��K���9�!�"7�8�
�9�s�A � A7�6A7c�
�	tt�j�}|D]�}|j
d�}|d|k(s�|dk(rd}nd|dvr|dn|d}t|d|d	|dtjj|dd
�j�tjj|d
�j���cSt	j|���#t$rt	j
��wxYw)
N�,��xenialz
2026-04-23�LTSr��rVz%Y-%m-%d)rrrrr)r)rW�DISTRO_INFO_CSVr�r�r
�MissingDistroInfoFilerXrr=rM�date�MissingSeriesInDistroInfoFile)r�linesr��valuesrs     rD�get_distro_infor��s��1��/�*�5�5�7���
�����C����!�9�����!�&��',��q�	�'9�&��)�v�a�y����q�	� &�q�	��a�y��%�%�.�.�v�a�y�*�E�J�J�L� �)�)�2�2�7�J�G�L�L�N��
�
��
2�
2�&�
A�A��#�1��.�.�0�0�1�s�C$�$D�programc���tjj|vr
t|�r|Stjjdd�j
tj�D�cgc]}|jd���}}|D�cgc]!}tjj|���#}}|D]1}tjj||�}t|�s�/|cSycc}wcc}w)z;Find whether the provided program is executable in our PATH�PATHr~r�N)r:r��sep�is_exe�environr�rX�pathseprZ�abspathr�)r�p�paths�normalized_pathsr��program_paths      rD�whichr�s���	�w�w�{�{�g���'�?��N� �j�j�n�n�V�R�8�>�>�r�z�z�J�
�������
�E�
�5:�:�q�������*�:��:� � ���w�w�|�|�D�'�2���,���� ���
��;s�)C&�&C+�installed_pkgs�installed_pkgs_regexc�V�tjjt�sy|�|�y	t	tt�jd��}|�t|j|��dk7ry|�'|D]"}|D]}tj||�s�y�$y#t$rYywxYw)a�Check if the system needs to be rebooted.

    :param installed_pkgs: If provided, verify if the any packages in
        the list are present on /var/run/reboot-required.pkgs. If that
        param is provided, we will only return true if we have the
        reboot-required marker file and any package in reboot-required.pkgs
        file. When both installed_pkgs and installed_pkgs_regex are
        provided, they act as an OR, so only one of the two lists must have
        a match to return True.
    :param installed_pkgs_regex: If provided, verify if the any regex in
        the list matches any line in /var/run/reboot-required.pkgs. If that
        param is provided, we will only return true if we have the
        reboot-required marker file and any match in reboot-required.pkgs
        file. When both installed_pkgs and installed_pkgs_regex are
        provided, they act as an OR, so only one of the two lists must have
        a match to return True.
    FTr�r)
r:r�r��REBOOT_FILE_CHECK_PATH�setrW�REBOOT_PKGS_FILE_PATHrXr�ri�intersectionrHrI)r
r�reboot_required_pkgs�pkg_name�	pkg_regexs     rD�
should_rebootr	s���0�7�7�>�>�0�1����"6�">���"��+�,�2�2�4�8� 
���!��~�*�*�+?�@�A�Q�F���'�,�	 �H�1�
 �	��9�9�Y��1��
 �	 �
������s�'B�	B(�'B(r�c��tjj|�xr$tj|tj�Sr�)r:r��isfile�access�X_OK)r�s rDrr?s)��
�7�7�>�>�$��<�B�I�I�d�B�G�G�$<�<rwr�c��t|d�5}tjd|�|j�}ddd�	j	d�S#1swY�xYw#t
$rt
j|d���wxYw)z!Read filename and decode content.�rbzReading file: %sN�utf-8)ro�
file_encoding)�openr8�debugr��decode�UnicodeDecodeErrorr
�InvalidFileEncodingError)r��streamr�s   rDrWrWDsy��	
�h��	� ���	�	�$�h�/��+�+�-�� �
��~�~�g�&�&�	 � ��
�
��1�1��g�
�	
�
�s�'A�A�A�!A;�modec�
�tjd|�tjtjj|�d��t
j|�j�tj||�y)NzCreating file: %sT��exist_ok)
r8r!r:�makedirsr��dirname�pathlib�Path�touch�chmod)r�r&s  rD�create_filer0QsO���I�I�!�8�,��K�K�������)�D�9��L�L��� � �"��H�H�X�t�rwr�c���d}tjj|�}|rGtj|�j�}tj|j�}|�|}n|�d}	tjtjj|�d��tjddtjj|���}tjd||j�|j|j!d	��|j#�|j%�tj&|j|�|r5tj(|jj*|j,�tj.|j|�y#t0$r(}|�tj2|j�|�d}~wwxYw)
a_Write content to the provided filename encoding it if necessary.

    We preserve the file ownership and permissions if the file is present
    and no mode argument is provided.

    @param filename: The full path of the file to write.
    @param content: The content to write to the file.
    @param mode: The filesystem mode to set on the file.
    N�Tr(�wbF)r&�delete�dirz*Writing file %s atomically via tempfile %sr)r:r�rr,r-r;�S_IMODE�st_moder*r+�tempfile�NamedTemporaryFiler8r!r�r��encode�flush�closer/�chown�st_uid�st_gid�renamerB�unlink)r�r�r&�tmpf�is_file_present�	file_stat�f_mode�es        rD�
write_filerGXsU���D��g�g�n�n�X�.�O���L�L��*�/�/�1�	����i�/�/�0���<��D�	
�����
���B�G�G�O�O�H�-��=��*�*��e�������)B�
��	�	�	�8�(�D�I�I�	
�	
�
�
�7�>�>�'�*�+��
�
���
�
��
������D�!���H�H�T�Y�Y�	� 0� 0�)�2B�2B�C�
�	�	�$�)�)�X�&�������I�I�d�i�i� �����s�0EF2�2	G#�;#G�G#�	file_pathc��	tj|�tjd|�y#t$rtjd|�YywxYw)z<Remove a file if it exists, logging a message about removal.zRemoved file: %sz*Tried to remove %s but file does not existN)r:rAr8r!r�)rHs rD�ensure_file_absentrJ�sC��K�
�	�	�)���	�	�$�i�0���K��	�	�>�	�J�K�s�+.�A�A�args�rcs�capture�timeout�override_env_vars�pipe_stdouterrc��|D�cgc]%}t|t�r|n|jd���'}}d}d}	i}
|r%tj}tj}	ddd�}
|�i}it
j�|
�|�}|�dg}tjdj|��}	tj|||	|��}
|
j|��\}}|r|jdd	�
�nd}|r|jdd	�
�nd}|
j |vr#tj||
j ||���|r"t$j'd||
j |�||fScc}w#t$rv	r|jdd	�
�nd}r|jdd	�
�nd}tj|
j ||���#t"$rtj|�
��wxYwwxYw)a�Run a command and return a tuple of decoded stdout, stderr.

    @param args: A list of arguments to feed to subprocess.Popen
    @param rcs: A list of allowed return_codes. If returncode not in rcs
        raise a ProcessExecutionError.
    @param capture: Boolean set True to log the command and response.
    @param timeout: Optional float indicating number of seconds to wait for
        subp to return.
    @param override_env_vars: Optional dictionary of environment variables.
        If None, the current os.environ is used for the subprocess.
        If defined, these env vars get merged with the current process'
        os.environ for the subprocess, overriding any values that already
        existed in os.environ.

    @return: Tuple of utf-8 decoded stdout, stderr
    @raises ProcessExecutionError on invalid command or returncode not in rcs.
    @raises subprocess.TimeoutError when timeout specified and the command
        exceeds that number of seconds.
    rNzC.UTF-8)�LANG�LC_ALLr� )�stdout�stderr�env)rN�ignore)�errorsr~)�cmd�	exit_coderUrV)rZzRan cmd: %s, rc: %s stderr: %s)�
isinstance�bytesr:�
subprocess�PIPEr:rr�redact_sensitive_logsr��Popen�communicater�r"r
r�
returncode�UnboundLocalErrorr8r!)rKrLrMrNrOrP�x�
bytes_argsrUrV�set_lang�
merged_env�redacted_cmd�procrt�err�
out_result�
err_results                  rD�_subprn�s��8CG��=>�Z��5�
!��q�x�x��'8�8��J���F�
�F��H����������%��;��� ���@�B�J�J�@�(�@�.?�@�J�
�{��c���-�-�c�h�h�t�n�=�L�E��������	
���%�%�g�%�6�
��c�:=����G�H��5�"�J�9<����G�H��5�"�J����c�!��.�.���o�o���	
�	
���	�	�,���O�O��		
��z�!�!��u��:�E�
	E�AD����G�H��=�"�J�AD����G�H��=�"�J��2�2� ��/�/�!�!�	�
��!�	E��2�2�|�D�D�	E��E�s$�*E�".E�	G�&AF7�7 G�G�retry_sleepsc��|�|j�nd}		t||||||��\}}	||fS#tj$r�}	|rItjt
|	��tjd|	j|	j�|s�tjt
|	��tjdt|��tj|jd��Yd}	~	nd}	~	wwxYw��)a�Run a command and return a tuple of decoded stdout, stderr.

     @param subp: A list of arguments to feed to subprocess.Popen
     @param rcs: A list of allowed return_codes. If returncode not in rcs
         raise a ProcessExecutionError.
     @param capture: Boolean set True to log the command and response.
     @param timeout: Optional float indicating number of seconds to wait for a
         subp call to return.
     @param retry_sleeps: Optional list of sleep lengths to apply between
        retries. Specifying a list of [0.5, 1] instructs subp to retry twice
        on failure; sleeping half a second before the first retry and 1 second
        before the next retry.
     @param override_env_vars: Optional dictionary of environment variables.
        If None, the current os.environ is used for the subprocess.
        If defined, these env vars get merged with the current process'
        os.environ for the subprocess, overriding any values that already
        existed in os.environ.

    @return: Tuple of utf-8 decoded stdout, stderr
    @raises ProcessExecutionError on invalid command or returncode not in rcs.
    @raises subprocess.TimeoutError when timeout specified and the command
        exceeds that number of seconds.
    N)rOrPzStderr: %s
Stdout: %szRetrying %d more times.r)�copyrnr
rr8r!r�r9rVrUri�time�sleep�pop)
rKrLrMrNrorOrPrtrkrFs
          rDrhrh�s���@+7�*B�<�$�$�&��L�
�	,������"3�-�
�H�C��
���8�O���/�/�	,���	�	�#�a�&�!����4�a�h�h����I����I�I�c�!�f���I�I�/��\�1B�C��J�J�|�'�'��*�+�+��	,��s�0�C<�B/C7�7C<�folder_pathc��	t|�tjd|�y#t$rtjd|�YywxYw)NzRemoved folder: %sz,Tried to remove %s but folder does not exist)rr8r!r�)rus rD�ensure_folder_absentrws?��O��{���	�	�&��4���O��	�	�@�+�N�O�s�!$�A�A�service_namec�V�	tddd|g�y#tj$rYywxYw)a^
    Get if the systemd job is active in the system. Note that any status
    different from "active" will make this function return False.
    Additionally, if the system doesn't exist we will also return False
    here.

    @param service_name: Name of the systemd job to look at

    @return: A Boolean specifying if the job is active or not
    �	systemctlz	is-activer�FT)rhr
r)rxs rD�is_systemd_unit_activer{$s7����k�;�	�<�
@�A����+�+����s��(�(c�4�	tdddd|g�\}}|r3|jd�r"|jd�dj�Stjd|�	y#tj$r"}tjd	||�
�Yd}~yd}~wwxYw)Nrz�showz--property=ActiveStatez
--no-pagerzActiveState=r�rVz9Couldn't find ActiveState in systemctl show output for %sz-Failed to get ActiveState for systemd unit %s)�exc_info)rhr�rXrZr8r9r
r)rxrtr�rFs    rD�get_systemd_unit_active_stater6s���
����(���
�
���Q��3�>�>�.�1��9�9�S�>�!�$�*�*�,�,��K�K�K��
���
�+�+�
����;���	�	
�	
�
��

�s�AA"�
A"�"B�5B�Bc��tj�rtjStj
j
d�}|r.tjj|tj�Stjjtjjd�dtj�S)N�XDG_CACHE_HOME�~z.cache)rrer�UAC_RUN_PATHr:rr�r�r��USER_CACHE_SUBDIR�
expanduser)�xdg_cache_homes rD�get_user_cache_dirr�Qs|���!�!�#��$�$�$��Z�Z�^�^�$4�5�N���w�w�|�|�N�H�,F�,F�G�G�
�7�7�<�<�
�����3���8�+E�+E��rwc�&�	tt�}g}g}d}|j�D];}t	j
||�r|j
|��+|j
|��=tt|�t|���S#t$rYywxYw)Nz^(linux-image|linux-base).*)r2r3)	rWrr�rXrHr[�appendr1�sorted)�pkg_list_strr2r3�kernel_regex�pkgs     rD�get_reboot_required_pkgsr�^s���� �!6�7�����O�0�L��!�!�#�*��
�8�8�L�#�&��"�"�3�'��$�$�S�)�	*�� �!2�3���/��������s�B�	B�B)z/run)NN)r2r�)NFNNT)NFNNNT)Rr=rg�loggingr:r,rHr;r^r8rrr��	functoolsr�shutilr�typingrrrrr	r
rr�rr
rrrr�r�r��	getLogger�replace_top_level_logger_name�__name__r8r�r\r�r�rr]rrr"r1rJ�uname_resultrErSr`rqrvr�r�r�r��boolr�r�r�r�r�r7r�r�r�rrrrWr0rGrJ�floatrnrhrwr{rr�r�r�rwrD�<module>r�s+�����	��	��������I�I�I�/�/�3��7��"��,��5���g���:��:�:�8�D�E��=��

	����	��
�
��	�H�M�M�"�	�3��	�C��	�C� ��	�
���	�s�#�	�#��	�x�� 1� 1�2�3�	)�8�C�=�9�	�(�3�-� �	�(�3�-� �	�(�3�-� �	���
��	�8�C�=�!�
�
�
���	���	�C��	�3��	�3��	����
�	���
�&�	#�X�c�]�3�	�x��}�-�	"�H�S�M�2�	�X�c�]�+�	��#��/�	���
�.�	�(�3�-�(�	�x��}�-�	�X�c�]�+�	�h�s�m�,�	-�x��}�=�	�(�3�-�(�	��#��'����( ��	�h�t�C�y�1�2�	�H�T�#�Y�/�0���� B���
�?�?��
�h��� ��4�
�?�?��
�h��� ��(�4��&
��&
��&
�V �F�4���s����
�4���s����(�4��9�g�9��9�x�4���3����B�4���+����>�4���3��4����
�4��-�t�-��-��4���������
�4���#��$�����4��4�d�4��4��4���3��D����4�4��
�D�
��
��4��
�4��S��>�
��
��4��B�C�B�J�B��B�.�3��8�C�=��$*.�/3�3��S��X�&�3�"�3�s�8�,�3�
�3�l=��=��=�


��

��

��#��S��T��8<�(��(��(�'/��}�(�	�(�VK�#�K�$�K� $��#�26��
U"�
�3�-�U"�	�$�s�)�	�U"��U"��e�_�	U"�
 ��S�#�X��/�U"��
U"��3��8�_�U"�t $��#�*.�26��5�
�3�-�5�	�$�s�)�	�5��5��e�_�	5�
�4��;�'�5� ��S�#�X��/�
5��5��3��8�_�5�pO�c�O�d�O������$�����
��6
�C�
��(�+=�">�rw