�
,w�gc@sddlZddlZddlZddlZddlZddlZddlmZddlmZddlm Z ddlm
Z
ddlmZddlm
Z
dd lmZer�dd
lmZmZndZd�Zd
�Zd�Zd�Zd�Zd�Zd�Zdefd��YZdefd��YZdefd��YZd�Z d�Z!ej"d��Z#ej"d��Z$ej"d��Z%d�Z&d�Z'd �Z(d!�Z)d"�Z*d#�Z+ej"d$��Z,d%�Z-d&�Z.d'�Z/d(�Z0dS()i����Ni(tconfig(t constants(t log_utils(t
process_utils(tutils(tSafeExceptionWrapper(tjson_loads_nstr(tOptionaltTuplesuname: cCstj|�p|dkS(Ns.-_+(tstrtisalnum(tc((s+/usr/libexec/kcare/python/kcarectl/kcare.pyt
is_uname_charscCs�t�}tt||tj�d�}zPxI|j�D];}|jt�r7djt t
|tt�j���Sq7WWd|j
�XdS(Ntrt(tget_kernel_hashtopentget_cache_pathRt
PATCH_INFOt readlinest
startswithtUNAME_LABELtjointfilterRtlentstriptclose(tpatch_leveltkhashtftline((s+/usr/libexec/kcare/python/kcarectl/kcare.pytparse_unames .cCsatjjtj�r]y1ttjd�}|j|�|j�tSWq]t k
rYq]Xnt
S(Ntw(tostpathtexistsRtKCARE_UNAME_FILERtwriteRtTruet ExceptiontFalse(tnew_versionR((s+/usr/libexec/kcare/python/kcarectl/kcare.pytkcare_update_effective_version*s
cCsAttjd�}ztj|j��j�SWd|j�XdS(Ntrb(RRtKERNEL_VERSION_FILEthashlibtsha1treadt hexdigestR(R((s+/usr/libexec/kcare/python/kcarectl/kcare.pyR6sc Cs�tjjtjd�}tjj|�r�t|d��i}|j�j�}yt |�Wn;t
k
r�tt tjj|���St
k
r�dSX|SWdQXndS(s:Returns timestamp from PATCH_CACHE/stoped.at if its exsitss
stopped.atR
terrorNs-1(R!R"RRtPATCH_CACHER#RR/trstriptintt
ValueErrorR tgetctimeR'(tstopped_at_filenametfhtvalue((s+/usr/libexec/kcare/python/kcarectl/kcare.pyt
get_last_stopAs
cCswtjpd}tjpd}dj||t|�|g�}tjd|f}|rg||f7}ntjj|�S(Ntnonetdefaultt-tpatches( RtPREFIXt
PATCH_TYPERR RR2R!R"(Rtpleveltfnametprefixtptypet patch_dirtresult((s+/usr/libexec/kcare/python/kcarectl/kcare.pyRRs!cGstjtj|�S(N(Rtget_patch_server_urlRR?(tparts((s+/usr/libexec/kcare/python/kcarectl/kcare.pytget_kernel_prefixed_url\stBaseKernelPatchLevelcBseZd�Zd�ZRS(cGst|jt|�|�S(N(RRR (tselfRH((s+/usr/libexec/kcare/python/kcarectl/kcare.pyt
cache_pathascCs,i|jd6|jd6|jd6|jd6S(NtlevelRtbaseurltrelease(RMRRNRO(RK((s+/usr/libexec/kcare/python/kcarectl/kcare.pytas_dictds
(t__name__t
__module__RLRP(((s+/usr/libexec/kcare/python/kcarectl/kcare.pyRJ`s tKernelPatchLevelcBs2eZdd�Zdd�Zd�Zd�ZRS(cCst||�j||�S(N(tsupert__new__(tclsRRMRNRO((s+/usr/libexec/kcare/python/kcarectl/kcare.pyRUnscCs(||_||_||_||_dS(N(RMRRNRO(RKRRMRNRO((s+/usr/libexec/kcare/python/kcarectl/kcare.pyt__init__qs cGstj|j|j|�S(N(RRGRNR(RKRH((s+/usr/libexec/kcare/python/kcarectl/kcare.pytkmod_urlwscGs"tj|j|jt|�|�S(N(RRGRNRR (RKRH((s+/usr/libexec/kcare/python/kcarectl/kcare.pytfile_urlzsN(RQRRtNoneRURWRXRY(((s+/usr/libexec/kcare/python/kcarectl/kcare.pyRSms tLegacyKernelPatchLevelcBs5eZd�Zd�Zd�Zd�Zd�ZRS(cCsCyt||�j||�SWntk
r>}t|��nXdS(N(RTRUR5R(RVRRMtexc((s+/usr/libexec/kcare/python/kcarectl/kcare.pyRUscCs(||_||_d|_d|_dS(N(RMRRZRNRO(RKRRM((s+/usr/libexec/kcare/python/kcarectl/kcare.pyRW�s cGs8dtjkr(t|jt|�|�St|j|�S(Nspatches.kernelcare.com(RtPATCH_SERVERRIRR (RKRH((s+/usr/libexec/kcare/python/kcarectl/kcare.pyRX�scGst|jt|�|�S(N(RIRR (RKRH((s+/usr/libexec/kcare/python/kcarectl/kcare.pyRY�scCst|jt|�|�S(N(RSRR4(RKRN((s+/usr/libexec/kcare/python/kcarectl/kcare.pytupgrade�s(RQRRRURWRXRYR^(((s+/usr/libexec/kcare/python/kcarectl/kcare.pyR[~s
cCsoyDttjjtjd�d��}tj|j�|�WdQXWn$t k
rjt
jddt�nXdS(Nskernel_patch_level.jsonR s!failed to dump kernel patch levelt print_msg(
RR!R"RRR2tjsontdumpRPR'RtlogexcR((tkernel_patch_levelR((s+/usr/libexec/kcare/python/kcarectl/kcare.pytdump_kernel_patch_level�s
$
cCsfy;ttjjtjd���}t|j��SWdQXWn$tk
rat j
ddt�nXdS(Nskernel_patch_level.jsons(failed to read dumped kernel patch levelR_(RR!R"RRR2RR/R'RRbR((R((s+/usr/libexec/kcare/python/kcarectl/kcare.pytread_dumped_kernel_patch_level�s
!
cCs�d}d}tjjd�r�tdd��N}xD|D]<}|j�}|jd�r7|jdd�\}}q7q7WWdQXntjj|�r�t j tjj
|d��}|r�td�|D��}q�n|S(Ns
/var/crashs/etc/kdump.confR
spath is*/vmcorecss!|]}tjj|�VqdS(N(R!R"R6(t.0tit((s+/usr/libexec/kcare/python/kcarectl/kcare.pys <genexpr>�s(RZR!R"tisfileRRRtsplittisdirtglobRtmax(t
kdump_pathRFt
kdump_confRt_tvmcore_list((s+/usr/libexec/kcare/python/kcarectl/kcare.pytkdumps_latest_event_timestamp�s
(cCs\tjstjjtj�rXtjtjddgdtdt�\}}}|j �SdS(Ns is-activetkdumptcatch_stdouttcatch_stderrssystemd-absent(
RtSKIP_SYSTEMCTL_CHECKR!R"Rht SYSTEMCTLRtrun_commandR&R(Rotstdout((s+/usr/libexec/kcare/python/kcarectl/kcare.pytkdump_status�s0
cCsItjjtj�sdStjtj�}|s5dStd�|D��S(Ncss3|])}tjjtjjtj|��VqdS(N(R!R"R6RRt
KDUMPS_DIR(RfRg((s+/usr/libexec/kcare/python/kcarectl/kcare.pys <genexpr>�s(R!R"RjRRzRZtlistdirRl(t
files_list((s+/usr/libexec/kcare/python/kcarectl/kcare.pyt$crashreporter_latest_event_timestamp�scCsJd}tjj|�sdSt|d��}|j�j�}WdQX|S(Ns/sys/module/kcare/versionR
(R!R"R#RR/R(tkmod_version_fileRtversion((s+/usr/libexec/kcare/python/kcarectl/kcare.pytget_current_kmod_version�scCsMt�}|stStjdddt||tj�g�j�}||kS(Ns
/sbin/modinfos-FR(R�R&Rtcheck_outputRRtKMOD_BINR(RRAtold_versionR)((s+/usr/libexec/kcare/python/kcarectl/kcare.pytis_kmod_version_changed�s *cCs#t�}|stj�St|�S(N(tloaded_patch_leveltplatformROR(R((s+/usr/libexec/kcare/python/kcarectl/kcare.pytkcare_uname_su�s
cCs<tjjtj�r1ttjd�j�j�St�SdS(NR
( R!R"R#RR$RR/RR�(((s+/usr/libexec/kcare/python/kcarectl/kcare.pytkcare_uname�scCsftt��d}|rbyt|�Wn(tk
rQ}t|dt���nXtt�|�SdS(Nspatch-levelsUnexpected patch state(tparse_patch_descriptiontloaded_patch_descriptionR4R5Rt_patch_infoR[R(tplte((s+/usr/libexec/kcare/python/kcarectl/kcare.pyR��scCstjtjdg�S(Ntinfo(RR�Rt
KPATCH_CTL(((s+/usr/libexec/kcare/python/kcarectl/kcare.pyR��scCsiy+gtd�D]}|j�d^qSWn7ttfk
rd}tjdt|�dt�gSXdS(Ns
/proc/modulesis#Error getting loaded modules list: R_(RRitOSErrortIOErrorRtlogerrorR R((Rtex((s+/usr/libexec/kcare/python/kcarectl/kcare.pytget_loaded_moduless
+cCs#dt�krdStt�d�S(Ntkcareskpatch-description(R�RZtget_patch_valueR�(((s+/usr/libexec/kcare/python/kcarectl/kcare.pyR�
scCstj|�j|�S(N(Rtdata_as_dicttget(R�tlabel((s+/usr/libexec/kcare/python/kcarectl/kcare.pyR�sc Cs�idd6dd6dd6dd6}|s,|S|jd�\}}}|jd�\}}}|jd �\}}}|p}d|d<|p�d|d<||d<||d<|S(
Nspatch-levelR<s
patch-typeRslast-updateskernel-versiont;t:R=(RZt partition( tdescRFtlevel_type_timestampRotkernelt
level_typet timestampRt
patch_type((s+/usr/libexec/kcare/python/kcarectl/kcare.pyR�s"
c
Cs�tjjtjd�}tjj|�r�t|d��G}y|j�}tj |�SWn t
ttt
tfk
r{nXWdQXndS(Nskcare.stateR
(R!R"RRR2R#RR/tasttliteral_evaltSyntaxErrorR�R5t TypeErrortUnicodeDecodeError(t
state_fileRtstate((s+/usr/libexec/kcare/python/kcarectl/kcare.pyt get_state*s(1R�R`R!R-RkR�RRRRRRterrorsRtpy23RR(ttypingRRRRRR*RR:RRIR4RJRSR[RdRetcachedRqRyR}R�R�R�R�R�R�R�R�R�R�R�(((s+/usr/libexec/kcare/python/kcarectl/kcare.pyt<module>sR
|