o
    ÙKÕiyp  ã                   @   sÌ  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Zd dlZd dl	Z	d dl
Z
d dlmZ d dlmZ d dlmZmZmZmZmZmZmZ d dlmZmZmZ dZdZdZd	Zd
Ze  e !e"¡¡Z#dZ$dZ%edde j&fde j&fde'fde'fde'fgƒZ(edde'fde'fdee j  fdee' fdee) fdee) fdee) fdee' fdee' fg	ƒZ*edde'fde'fde'fde'fgƒZ+ed d!ee' fd"ee' fd#ee' fd$ee' fd%ee' fd&ee' fd'ee' fd(ee' fd)ee' fd*ee' fd+ee' fd,ee' fd-ee' fd.ee' fgƒZ,ed/d0eee'  fd1eee'  fgƒZ-d2Z.d3ej/d4ee j  fd5d6„Z0d3ej/d4ee j  fd7d8„Z1edd9�d4e*fd:d;„ƒZ2d<d=„ Z3edd9�d4e'fd>d?„ƒZ4edd9�d4e'fd@dA„ƒZ5edd9�d4e,fdBdC„ƒZ6edd9�d4e'fdDdE„ƒZ7edd9�d4e+fdFdG„ƒZ8edd9�de'd4e9fdHdI„ƒZ:edd9�d4e9fdJdK„ƒZ;edd9�de'd4e9fdLdM„ƒZ<edd9�de'd4e9fdNdO„ƒZ=edd9�d4e9fdPdQ„ƒZ>edd9�dŒdSe'd4e9fdTdU„ƒZ?edd9�d4e9fdVdW„ƒZ@edd9�d4ee'e'f fdXdY„ƒZAedd9�de'd4e(fdZd[„ƒZBd\e'd4ee' fd]d^„ZC		d�d_eee'  d`eee'  d4e9fdadb„ZDdce'd4e9fddde„ZEdfe'd4e'fdgdh„ZFdŽdfe'dje)d4dfdkdl„ZG	d�dfe'dme'djee) d4dfdndo„ZHdpe'd4dfdqdr„ZI		s			td�duee' dveee)  dwe9dxeeJ dyeee'e'f  dze9d4ee'e'f fd{d|„ZK		s				td‘duee' dveee)  dwe9dxeeJ d}eeeJ  dyeee'e'f  dze9d4ee'e'f fd~d„ZLd€e'd4dfd�d‚„ZMdƒe'd4e9fd„d…„ZNdƒe'd4ee' fd†d‡„ZOd4e'fdˆd‰„ZPd4ee- fdŠd‹„ZQdS )’é    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                 C   sf   t ƒ r
t d¡ d S t d¡ zt d | j¡¡}tj |j	tj
j¡W S  ty2   t d¡ Y d S w )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.gzzUnable to stat kernel changelog)Úis_containerÚLOGÚwarningÚosÚstatÚformatr   ÚdatetimeÚfromtimestampÚst_mtimeÚtimezoneÚutcÚ	Exception)r3   Ústat_result© rB   ú1/usr/lib/python3/dist-packages/uaclient/system.pyÚ_get_kernel_changelog_timestampq   s&   ÿ
ÿÿ
ÿ
þrD   c                 C   sˆ   t  t| j¡}|d u rt d¡ t| ƒS | d¡}z	tj 	|d¡}W n t
y4   t d¡ t| ƒ Y S w |jd u rB|jtjjd�}|S )Nz*Unable to find build date in uname versionr   z%a %b %d %H:%M:%S %Z %Yz-Unable to parse build date from uname version)Útzinfo)ÚreÚsearchÚRE_KERNEL_EXTRACT_BUILD_DATEÚversionr6   r7   rD   Úgroupr;   ÚstrptimeÚ
ValueErrorrE   Úreplacer>   r?   )r3   Ú
date_matchÚdate_strÚdtrB   rB   rC   Ú_get_kernel_build_date‹   s   


þ
rQ   )Úmaxsizec                  C   sÜ   d } zt dƒ}| ¡ d } W n ty   t d¡ Y nw t ¡ }|j ¡ }t	|ƒ}|j
 ¡ }t t|¡}|d u rLt d|¡ t|||| d d d d d d�	S t|||| t| d¡ƒt| d¡ƒt| d¡ƒ| d	¡| d
¡d�	S )Nz/proc/version_signatureé   z*failed to process /proc/version_signature.zFailed to parse kernel: %s)	r   r   r   r   r   r   r   r   r   r   r   r   r   r   )Ú	load_fileÚsplitr@   r6   r7   r8   r3   ÚmachineÚstriprQ   r   rF   ÚmatchÚRE_KERNEL_UNAMEr   ÚintrJ   )r   Úproc_version_signature_fullr3   r   r   r   Úuname_matchrB   rB   rC   Úget_kernel_infoŸ   sH   ÿ

÷÷r]   c                     sn   ddl m}  t ¡ stdƒ‚dd„ | ƒ D ƒ}dd„ t d¡D ƒ}dd„ |D ƒ‰ d	d„ |D ƒ}‡ fd
d„|D ƒS )Nr   )Úget_installed_packages_namesz9get_installed_ubuntu_kernels needs to be executed as rootc                 S   s   g | ]}d |v r|‘qS )úlinux-image-rB   )Ú.0ÚpackagerB   rB   rC   Ú
<listcomp>Ô   ó
    þz0get_installed_ubuntu_kernels.<locals>.<listcomp>c                 S   s$   g | ]}d t d|gƒd v r|‘qS )zLinux kernelÚfiler   ©Úsubp)r`   rd   rB   rB   rC   rb   Ù   s
    þz/boot/vmlinu[x|z]-*c                 S   ó   g | ]
}|t d ƒd… ‘qS )r_   N©Úlen)r`   Úpackage_namerB   rB   rC   rb   ß   s    ÿc                 S   rg   )z/boot/vmlinu?-Nrh   )r`   Ú	file_namerB   rB   rC   rb   â   s    ÿÿc                    s   g | ]}|ˆ v r|‘qS rB   rB   )r`   rI   ©Úlinux_image_versionsrB   rC   rb   ç   rc   )Úuaclient.aptr^   r   Úwe_are_currently_rootÚRuntimeErrorÚglob)r^   Úlinux_imageÚvmlinux_kernel_filesÚvmlinuz_versionsrB   rl   rC   Úget_installed_ubuntu_kernelsË   s(   ÿþþÿþ
þru   c                  C   s   t ddgƒ\} }|  ¡ S )NÚdpkgz--print-architecture)rf   rW   )ÚoutÚ_errrB   rB   rC   Úget_dpkg_archî   ó   ry   c                  C   sz   zt dgƒ\} }|  ¡ W S  tjy<   ztdƒ}d|v s!d|v r%W Y dS d|v r-W Y dS W Y dS  ty;   Y Y dS w w )Núsystemd-detect-virtz/proc/1/cgroupÚdockerÚbuildkitÚbuildahÚpodmanÚ )rf   rW   r   ÚProcessExecutionErrorrT   r@   )rw   Ú_Úproc_1_cgrouprB   rB   rC   Úget_virt_typeô   s   
ÿôr„   c                  C   s¨  d} d}d}i }i }d }zt | ƒ}W n ty#   t d | ¡¡ Y n,w | d¡}tdd„ |D ƒdƒ}| d	¡D ]}	d
|	v rN|	 d
d¡\}
}| ¡ ||
 ¡ < q8zt |ƒ}W n tyf   t d |¡¡ Y nw | d	¡D ]}	d
|	v r‚|	 d
d¡\}
}| ¡ ||
 ¡ < qlzt |ƒ}W n tyš   t d |¡¡ Y nw t| 	d¡| 	d¡| 	d¡| 	d¡| 	d¡| 	d¡| 	d¡| 	d¡| 	d¡| 	d¡| 	d¡|| 	d¡| 	d¡d�S )Nz/proc/cpuinfoz/proc/sysinfoz#/sys/firmware/devicetree/base/modelzcould not open {}z

c                 s   s   � | ]
}|  d ¡r|V  qdS )Ú	processorN)Ú
startswith)r`   ÚsrB   rB   rC   Ú	<genexpr>  s   € zget_cpu_info.<locals>.<genexpr>r€   Ú
ú:rS   ÚcpuzCPU architecturez
cpu familyzCPU implementerzCPU partzCPU revisionzCPU variantÚmodelz
model nameÚsteppingÚ	vendor_idÚModelÚType)r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   )
rT   ÚFileNotFoundErrorr6   Úinfor:   rU   ÚnextrW   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_contentrB   rB   rC   Úget_cpu_info	  sf   ÿ
ÿ€ÿ€ÿòr¢   c                 C   s    ddl m} ddlm} | ¡ }|jr!|j di ¡ d¡}|r!|S | ¡ }ttfD ]}t	j
 |¡r>t|ƒ d¡}|r>|  S q)|rC|S tt ¡ ƒ}| |¡ |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_IDr8   ÚpathÚexistsrT   ÚrstripÚstrÚuuidÚuuid4Úwrite)Úcfgr£   r¤   Úmachine_token_fileÚ
machine_idÚfallback_machine_idr­   ÚcontentrB   rB   rC   Úget_machine_idF  s.   ÿþ€
r¹   c                  C   sº   t ƒ } |  dd¡}t dd|  dd¡¡}|  dd¡}|  dd¡}|r$|sSt t|¡}|s7tj|  dd¡|d	�‚| ¡ }|pB| d
d¡}|sKtj	|d�‚|pR| dd¡}t
||| ¡ |d�S )NÚNAMEÚUNKNOWNz\.\d LTSz LTSÚVERSIONr€   ÚVERSION_CODENAMEÚ
VERSION_ID)Úorig_verÚmod_verr   )rI   r   )r   r   r   r    )Ú_parse_os_releaser”   rF   ÚsubrX   ÚREGEX_OS_RELEASE_VERSIONr   ÚParsingErrorOnOSReleaseFileÚ	groupdictÚMissingSeriesOnOSReleaseFiler   Úlower)Ú
os_releaser   r    r   r   rX   Ú
match_dictrB   rB   rC   Úget_release_infoh  s0   ÿÿürÊ   c                 C   ó   t ddgƒ\}}| |v S )Nú/usr/bin/ubuntu-distro-infoz--supported-esmre   ©r   rw   rx   rB   rB   rC   Úis_ltsˆ  rz   rÎ   c                   C   ó   t tƒ jƒS ©N)rÎ   rÊ   r   rB   rB   rB   rC   Úis_current_series_ltsŽ  ó   rÑ   c                 C   rË   )NrÌ   z--supportedre   rÍ   rB   rB   rC   Úis_supported“  rz   rÓ   c                 C   s,   t | ƒsdS tdd| dgƒ\}}t|ƒdkS )zCReturn True when Ubuntu series supports ESM and is actively in ESM.FrÌ   z--seriesz-yeolr   )rÎ   rf   rZ   rÍ   rB   rB   rC   Úis_active_esm™  s   
ÿrÔ   c                   C   rÏ   rÐ   )rÔ   rÊ   r   rB   rB   rB   rC   Úis_current_series_active_esm¤  rÒ   rÕ   ú/runÚrun_pathc              	   C   s~   zt dgƒ W dS  tjy   Y nw z	t g d¢ƒ W dS  ttfy'   Y nw dD ]}tj | |¡}tj |¡r< dS q*dS )z>Checks to see if this code running in a container of some sortÚischrootF)r{   ú--quietz--containerT)Úcontainer_typezsystemd/container)	rf   r   r�   ÚIOErrorÚOSErrorr8   r­   Újoinr®   )r×   Úfilenamer­   rB   rB   rC   r5   ©  s$   
ÿÿÿr5   c                  C   s.   ddl m}  |  ¡ D ]
}d|jv r dS q
dS )z�Returns True if any package installed has "ubuntu-desktop" in the name.

    This includes ubuntu-desktop, ubuntu-desktop-minimal, kubuntu-desktop, etc.
    r   )Úaptzubuntu-desktopTF)Úuaclientrß   Úget_installed_packagesÚname)rß   ra   rB   rB   rC   Ú
is_desktopÄ  s   
ÿrã   c                  C   sd   zt dƒ} W n ty   t dƒ} Y nw i }|  ¡ D ]}| dd¡\}}|r/| ¡  d¡||< q|S )Nz/etc/os-releasez/usr/lib/os-releaseú=rS   ú")rT   r‘   Ú
splitlinesrU   rW   )Úfile_contentsÚdatarž   rŸ   r    rB   rB   rC   rÁ   Ò  s   ÿ€rÁ   c              
   C   sÀ   zt tƒ ¡ }W n ty   t ¡ ‚w |D ]C}| d¡}|d | krY| dkr*d}nd|d v r4|d n|d }t|d |d	 |d tj 	|d d
¡ 
¡ tj 	|d
¡ 
¡ d�  S qtj| d�‚)Nú,é   Úxenialz
2026-04-23ÚLTSr   é   é   rS   z%Y-%m-%d)r   r   r   r   r   )r   )rT   ÚDISTRO_INFO_CSVræ   r‘   r   ÚMissingDistroInfoFilerU   r   r;   rK   ÚdateÚMissingSeriesInDistroInfoFile)r   Úlinesrž   Úvaluesr   rB   rB   rC   Úget_distro_infoà  s(   ÿ

ûûrõ   Úprogramc                 C   sr   t jj| v rt| ƒr| S dd„ t j dd¡ t j¡D ƒ}dd„ |D ƒ}|D ]}t j || ¡}t|ƒr6|  S q%dS )z;Find whether the provided program is executable in our PATHc                 S   s   g | ]}|  d ¡‘qS )rå   )rW   ©r`   ÚprB   rB   rC   rb   þ  s    
ÿzwhich.<locals>.<listcomp>ÚPATHr€   c                 S   s   g | ]}t j |¡‘qS rB   )r8   r­   Úabspathr÷   rB   rB   rC   rb     s    N)	r8   r­   ÚsepÚis_exeÚenvironr”   rU   ÚpathseprÝ   )rö   ÚpathsÚnormalized_pathsr­   Úprogram_pathrB   rB   rC   Úwhichø  s   ÿÿr  Úinstalled_pkgsÚinstalled_pkgs_regexc                 C   s¢   t j t¡sdS | du r|du rdS ztttƒ d¡ƒ}W n
 ty'   Y dS w | dur7t	|  
|¡ƒdkr7dS |durO|D ]}|D ]}t ||¡rM  dS qAq=dS )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.
    FNTr‰   r   )r8   r­   r®   ÚREBOOT_FILE_CHECK_PATHÚsetrT   ÚREBOOT_PKGS_FILE_PATHrU   r‘   ri   ÚintersectionrF   rG   )r  r  Úreboot_required_pkgsÚpkg_nameÚ	pkg_regexrB   rB   rC   Úshould_reboot	  s,   ÿýÿÿr  r­   c                 C   s   t j | ¡ot  | t j¡S rÐ   )r8   r­   ÚisfileÚaccessÚX_OK)r­   rB   rB   rC   rü   ?  s   rü   rÞ   c                 C   sh   t | dƒ�}t d| ¡ | ¡ }W d  ƒ n1 sw   Y  z| d¡W S  ty3   tj| dd�‚w )z!Read filename and decode content.ÚrbzReading file: %sNúutf-8)rk   Úfile_encoding)Úopenr6   Údebugrª   ÚdecodeÚUnicodeDecodeErrorr   ÚInvalidFileEncodingError)rÞ   Ústreamr¸   rB   rB   rC   rT   D  s   
þÿÿrT   é¤  Úmodec                 C   s@   t  d| ¡ tjtj | ¡dd� t | ¡ ¡  t 	| |¡ d S )NzCreating file: %sT©Úexist_ok)
r6   r  r8   Úmakedirsr­   ÚdirnameÚpathlibÚPathÚtouchÚchmod)rÞ   r  rB   rB   rC   Úcreate_fileQ  s   r#  r¸   c              
   C   s  d}t j | ¡}|rt | ¡ ¡ }t |j¡}|du r|}n|du r$d}zLt jt j 	| ¡dd� t
jddt j 	| ¡d�}t d| |j¡ | | d	¡¡ | ¡  | ¡  t  |j|¡ |rgt  |j|j|j¡ t  |j| ¡ W dS  tyˆ } z|dur‚t  |j¡ |‚d}~ww )
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.
    Nr  Tr  ÚwbF)r  ÚdeleteÚdirz*Writing file %s atomically via tempfile %sr  )r8   r­   r  r  r   r9   ÚS_IMODEÚst_moder  r  ÚtempfileÚNamedTemporaryFiler6   r  râ   r³   ÚencodeÚflushÚcloser"  ÚchownÚst_uidÚst_gidÚrenamer@   Úunlink)rÞ   r¸   r  ÚtmpfÚis_file_presentÚ	file_statÚf_modeÚerB   rB   rC   Ú
write_fileX  s>   €ÿÿ€ýr8  Ú	file_pathc                 C   s>   zt  | ¡ t d| ¡ W dS  ty   t d| ¡ Y dS w )z<Remove a file if it exists, logging a message about removal.zRemoved file: %sz*Tried to remove %s but file does not existN)r8   r2  r6   r  r‘   )r9  rB   rB   rC   Úensure_file_absentƒ  s   
ÿr:  FTÚargsÚrcsÚcaptureÚtimeoutÚoverride_env_varsÚpipe_stdouterrc                 C   sj  dd„ | D ƒ}d}d}i }	|rt j}t j}dddœ}	|du r i }i tj¥|	¥|¥}
|du r0dg}t d | ¡¡}zt j||||
d�}|j|d	�\}}W n5 t	y€   z |r\|j
d
dd�nd}|rg|j
d
dd�nd}tj||j||d�‚ ty   tj|d�‚w w |rŠ|j
d
dd�nd}|r•|j
d
dd�nd}|j|vr¦tj||j||d�‚|r±t d||j|¡ ||fS )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.
    c                 S   s$   g | ]}t |tƒr|n| d ¡‘qS )r  )Ú
isinstanceÚbytesr+  )r`   ÚxrB   rB   rC   rb   §  s    ÿz_subp.<locals>.<listcomp>NzC.UTF-8)ÚLANGÚLC_ALLr   ú )ÚstdoutÚstderrÚenv)r>  r  Úignore)Úerrorsr€   )ÚcmdÚ	exit_coderG  rH  )rL  zRan cmd: %s, rc: %s stderr: %s)Ú
subprocessÚPIPEr8   rý   r   Úredact_sensitive_logsrÝ   ÚPopenÚcommunicaterÜ   r  r   r�   Ú
returncodeÚUnboundLocalErrorr6   r  )r;  r<  r=  r>  r?  r@  Ú
bytes_argsrG  rH  Úset_langÚ
merged_envÚredacted_cmdÚprocrw   ÚerrÚ
out_resultÚ
err_resultrB   rB   rC   Ú_subpŒ  sn   ÿ
üüÿö
üür]  Úretry_sleepsc           
   
   C   sº   |dur|  ¡ nd}	 zt| |||||d�\}}W ||fS  tjy[ }	 z2|r7t t|	ƒ¡ t d|	j|	j	¡ |s:‚ t t|	ƒ¡ t dt
|ƒ¡ t | d¡¡ W Y d}	~	nd}	~	ww q)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.
    NT)r?  r@  zStderr: %s
Stdout: %szRetrying %d more times.r   )Úcopyr]  r   r�   r6   r  r°   r7   rH  rG  ri   ÚtimeÚsleepÚpop)
r;  r<  r=  r>  r^  r?  r@  rw   rZ  r7  rB   rB   rC   rf   ä  s2    
ú
÷€øõrf   Úfolder_pathc                 C   s<   zt | ƒ t d| ¡ W d S  ty   t d| ¡ Y d S w )NzRemoved folder: %sz,Tried to remove %s but folder does not exist)r   r6   r  r‘   )rc  rB   rB   rC   Úensure_folder_absent  s   ÿrd  Úservice_namec                 C   s.   zt ddd| gƒ W dS  tjy   Y dS w )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)rf   r   r�   )re  rB   rB   rC   Úis_systemd_unit_active$  s   þÿrg  c              
   C   s„   z%t dddd| gƒ\}}|r| d¡r| d¡d  ¡ W S t d| ¡ W d S  tjyA } ztjd	| |d
� W Y d }~d S d }~ww )Nrf  Úshowz--property=ActiveStatez
--no-pagerzActiveState=rä   rS   z9Couldn't find ActiveState in systemctl show output for %sz-Failed to get ActiveState for systemd unit %s)Úexc_info)rf   r†   rU   rW   r6   r7   r   r�   )re  rw   r‚   r7  rB   rB   rC   Úget_systemd_unit_active_state6  s2   ûÿ	þ
úý€úrj  c                  C   sH   t  ¡ rtjS tj d¡} | rtj | tj	¡S tj tj 
d¡dtj	¡S )NÚXDG_CACHE_HOMEú~z.cache)r   ro   r   ÚUAC_RUN_PATHr8   rý   r”   r­   rÝ   ÚUSER_CACHE_SUBDIRÚ
expanduser)Úxdg_cache_homerB   rB   rC   Úget_user_cache_dirQ  s   ÿrq  c                  C   sr   zt tƒ} W n
 ty   Y d S w g }g }d}|  ¡ D ]}t ||¡r)| |¡ q| |¡ qtt|ƒt|ƒd�S )Nz^(linux-image|linux-base).*)r1   r2   )	rT   r  r‘   rU   rF   rX   Úappendr0   Úsorted)Úpkg_list_strr1   r2   Úkernel_regexÚpkgrB   rB   rC   Úget_reboot_required_pkgs^  s    ÿþrw  )rÖ   )NN)r  rÐ   )NFNNT)NFNNNT)Rr;   rq   Úloggingr8   r  rF   r9   rN  r)  r`  r±   Ú	functoolsr   Úshutilr   Útypingr   r   r   r   r   r	   r
   rà   r   r   r   r  r  r«   r¬   rï   Ú	getLoggerÚreplace_top_level_logger_nameÚ__name__r6   rÃ   rY   rñ   r°   r   rZ   r   r   r!   r0   rH   Úuname_resultrD   rQ   r]   ru   ry   r„   r¢   r¹   rÊ   ÚboolrÎ   rÑ   rÓ   rÔ   rÕ   r5   rã   rÁ   rõ   r  r  rü   rT   r#  r8  r:  Úfloatr]  rf   rd  rg  rj  rq  rw  rB   rB   rB   rC   Ú<module>   s‚   $ÿÿûþ





÷þüþ














òþþþ	ÿ
þÿ
þ+#<!
þ
ÿ
þ
ý6ÿÿÿÿ
þ+úÿ
þýüûú

ùZùÿ
þýü
ûúù

ø8