
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
3
;j                 @   s   d dl Z d dlZd dlZd dlZddlmZmZmZmZ ddl	m
Z
 dZddd	Zdd
dZdd Zdd Zdd Zdd Zdd Zdd ZdS )    N   )config	constants	log_utilsutils)json_loads_nstr   <   .kcarestatusc             C   s$   t jjtj| }tj|tj  d S )N)ospathjoinr   PATCH_CACHEr   atomic_writetimestamp_str)filenamestatus_filepath r   2/usr/libexec/kcare/python/kcarectl/update_utils.pytouch_status_gap_file   s    r   c             C   sz   t jjtj| }t jj|rvt|dJ}y.t|j }t|t	j
 t tj krTdS W n tk
rj   Y nX W d Q R X dS )NrFT)r   r   r   r   r   isfileopenintreadr   STATUS_CHANGE_GAPSTATUS_CHANGE_GAP_DELAYtime	Exception)r   r   sfile	timestampr   r   r   status_gap_passed   s    r!   c             C   s   | dkrt dj| d S )Nkernellibcarez$Unknown update status component: {0})r"   r#   )
ValueErrorformat)	componentr   r   r   _check_component%   s    r'   c              C   sN   t jtj} | d kri S yt| }|S  ttfk
rH   tjj	d i S X d S )Nz"Failed to parse update status file)
r   	read_filer   UPDATE_STATUS_PATHr   r$   	TypeErrorr   kcarelogwarning)contentresultr   r   r   _load_update_status+   s    r/   c             C   sf   t |  y4t }|ttj d|| < tjtjtj	| W n$ t
k
r`   tjjddd Y nX d S )N)errorr    zFailed to save update statusT)exc_info)r'   r/   r   r   r   r   r   r)   jsondumpsr   r   r+   r,   )r&   r0   datar   r   r   save_update_status9   s    r5   c             C   s>   t | }t t| dd}|r:||kr:|j r6dj|S |S |S )Nstatus zHTTP Error: {0})strgetattrisdigitr%   )errmessager6   r   r   r   _error_statusG   s    
r=   c                s   t    fdd}|S )Nc                s   t j  fdd}|S )Nc                 sT   y| |}W n4 t k
rB } zt t|d  W Y d d }~X nX t dd |S )N)r0   r7   )r   r5   r=   )argskwargsr.   r;   )r&   fnr   r   inner_   s    z5track_update_status.<locals>.decorator.<locals>.inner)	functoolswraps)r@   rA   )r&   )r@   r   	decorator^   s    z&track_update_status.<locals>.decorator)r'   )r&   rD   r   )r&   r   track_update_statusZ   s    rE   c             C   s^   t |  y,t }|j| i jdd}t|d tj S  tk
rX   tjj	ddd dS X d S )Nr0   r7   zFailed to read update statusT)r1   )
r'   r/   getr8   r   UPDATE_ERROR_MAX_LENGTHr   r   r+   r,   )r&   r4   r0   r   r   r   read_update_erroro   s    rH   i,  )r
   )r
   )rB   r2   r   r   r7   r   r   r   r   py23r   r   r   r!   r'   r/   r5   r=   rE   rH   r   r   r   r   <module>   s   

