Hcf!8ddlZddlZddlmZddlmZddlmZddlm Z m Z m Z m Z m Z eje jeZe j$ZedgdZGdd eeZGd d Zdad Zd eddfdZd eddfdZdeefdZy)N) namedtuple)Enum)List)defaults event_loggermessagessystemutilNoticeFileDetails)order_idlabel is_permanentmessageceZdZedddej ZeddddZed d dejZed d dejZ ed ddejZ edddejZ edddejZ edddejZedddejj Zedddej"Zedddej&Zedddej*Zedddej,Zedddd Zed!d"dej2Zed#d$dej6Zy%)&Noticecontract_expired5T)r r rrreboot_required10FzSystem reboot requiredenable_reboot_required11reboot_script_failed12fips_reboot_required20fips_system_reboot_required21fips_install_out_of_date22fips_disable_reboot_required23fips_proc_file_error24fips_manual_disable_url25wrong_fips_metapackage_on_cloudlp_lts_reboot_required30contract_refresh_warning40operation_in_progress60z"Operation in progress: {operation}auto_attach_retry_full_notice70auto_attach_total_failure71N)__name__ __module__ __qualname__r rCONTRACT_EXPIREDREBOOT_REQUIREDENABLE_REBOOT_REQUIRED_TMPLENABLE_REBOOT_REQUIREDREBOOT_SCRIPT_FAILEDFIPS_REBOOT_REQUIRED_MSGFIPS_REBOOT_REQUIREDFIPS_SYSTEM_REBOOT_REQUIREDFIPS_INSTALL_OUT_OF_DATEFIPS_DISABLE_REBOOT_REQUIREDFIPS_PROC_FILE_ERRORtmpl_msgNOTICE_FIPS_MANUAL_DISABLE_URLFIPS_MANUAL_DISABLE_URL&NOTICE_WRONG_FIPS_METAPACKAGE_ON_CLOUDWRONG_FIPS_METAPACKAGE_ON_CLOUDLIVEPATCH_LTS_REBOOT_REQUIREDNOTICE_REFRESH_CONTRACT_WARNINGCONTRACT_REFRESH_WARNINGOPERATION_IN_PROGRESSAUTO_ATTACH_RETRY_NOTICEAUTO_ATTACH_RETRY_FULL_NOTICE&AUTO_ATTACH_RETRY_TOTAL_FAILURE_NOTICEAUTO_ATTACH_RETRY_TOTAL_FAILURE8/usr/lib/python3/dist-packages/uaclient/files/notices.pyrrs( ))  (( O /&44  -$--  -$11  #4+44 # 1(11   $5,55 $ -$--66  0'77  '8/?? '# %6&66 %! 1(88   .%4  %6-11 %! '8)?? '#rMrcteZdZdedefdZdefdZdedeefdZdedede fd Z dedefd Z deefd Z y ) NoticesManagernotice_details descriptionctjs+tjd|jj y|jj rtjntj}dj|jj|jj }tjtjj!|||y)zAdds a notice file. If the notice is found, it overwrites it. :param notice_details: Holds details concerning the notice file. :param description: The content to be written to the notice file. z.NoticesManager.add(%s) called as non-root userN{}-{})r we_are_currently_rootLOGwarningvaluer rrNOTICES_PERMANENT_DIRECTORYNOTICES_TEMPORARY_DIRECTORYformatr r write_fileospathjoin)selfrQrR directoryfilenames rNaddzNoticesManager.addts))+ KK@$$**  ##00  0 055  >>  ) )>+?+?+E+E   GGLLH -  rMctjs+tjd|jj y|jj rtjntj}dj|jj|jj }tjtjj!||y)ziDeletes a notice file. :param notice_details: Holds details concerning the notice file. z1NoticesManager.remove(%s) called as non-root userNrT)r rUrVrWrXr rrrYrZr[r r ensure_file_absentr]r^r_)r`rQrarbs rNremovezNoticesManager.removes ))+ KKC$$**  ##00  0 055  >>  ) )>+?+?+E+E  !!"'',,y("CDrMrareturnc tj|Dcgc]S}tjjtjj ||r|j ||r|Uc}Scc}w)zGets the list of notice file names in the given directory. :param directory: The directory to search for notice files. :returns: List of notice file names. )r]listdirr^isfiler__is_valid_notice_file)r`ra file_names rN_get_notice_file_namesz%NoticesManager._get_notice_file_namess\ ZZ 2 ww~~bggll9i@A**9i@    sAA3rlc|tjk(}tDchc]7}|j|k(r&dj |j |j 9}}||vScc}w)zChecks if the notice file is valid. :param file_name: The name of the notice file. :returns: True if the file is valid, False otherwise. rT)rrYrrr[r r )r`rarlis_permanent_dirnvalid_file_namess rNrkz$NoticesManager._is_valid_notice_filesh %(L(LL ~~!11 NN1::qww /  ,,,  s>"23 $ ; ;EVE,    S   -s -s -t - c c  d3i rMrPc.t tatSN) _notice_clsrPrLrMrN get_noticers$& rMrQrgc tt}|jjdi|}|j||y)NrL)rrr[rc)rQkwargsrvrRs rNrcrcs2 \F/.((//9&9K JJ~{+rMc:t}|j|yr)rrf)rQrvs rNrfrfs \F MM.!rMc6t}|jSr)rr)rvs rNrr s \F ;;=rM)loggingr] collectionsrenumrtypingruaclientrrrr r getLoggerreplace_top_level_logger_namer1rVget_event_loggereventr rrPrrrcrfrrrLrMrNrs "CCg:::8DE% %%'I ` `F}}@ ,,T, "6"d" d3irM