
    f                     8   d dl Z d dlZd dlmZ d dlmZ d dlmZ d dlm	Z	m
Z
mZmZmZ  e j                   ej                  e            Z e
j$                         Z edg d      Z G d d	ee      Z G d
 d      Zdad ZdeddfdZdeddfdZdee   fdZy)    N)
namedtuple)Enum)List)defaultsevent_loggermessagessystemutilNoticeFileDetails)order_idlabelis_permanentmessagec                      e Zd Z edddd      Z edddej                        Z edd	d
ej                        Z edddej                        Z
 edddej                        Z eddd
ej                        Z edddej                        Z eddd
ej                  j                        Z eddd
ej                         Z eddd
ej$                        Z edddej(                        Z eddd
ej*                        Z edddd      Z edd dej0                        Z ed!d"d
ej4                        Zy#)$Noticereboot_required10FzSystem reboot required)r   r   r   r   enable_reboot_required11reboot_script_failed12Tfips_reboot_required20fips_system_reboot_required21fips_install_out_of_date22fips_disable_reboot_required23fips_proc_file_error24fips_manual_disable_url25wrong_fips_metapackage_on_cloudlp_lts_reboot_required30contract_refresh_warning40operation_in_progress60z"Operation in progress: {operation}auto_attach_retry_full_notice70auto_attach_total_failure71N)__name__
__module____qualname__r   REBOOT_REQUIREDr   ENABLE_REBOOT_REQUIRED_TMPLENABLE_REBOOT_REQUIREDREBOOT_SCRIPT_FAILEDFIPS_REBOOT_REQUIRED_MSGFIPS_REBOOT_REQUIREDFIPS_SYSTEM_REBOOT_REQUIREDFIPS_INSTALL_OUT_OF_DATEFIPS_DISABLE_REBOOT_REQUIREDFIPS_PROC_FILE_ERRORtmpl_msgNOTICE_FIPS_MANUAL_DISABLE_URLFIPS_MANUAL_DISABLE_URL&NOTICE_WRONG_FIPS_METAPACKAGE_ON_CLOUDWRONG_FIPS_METAPACKAGE_ON_CLOUDLIVEPATCH_LTS_REBOOT_REQUIREDNOTICE_REFRESH_CONTRACT_WARNINGCONTRACT_REFRESH_WARNINGOPERATION_IN_PROGRESSAUTO_ATTACH_RETRY_NOTICEAUTO_ATTACH_RETRY_FULL_NOTICE&AUTO_ATTACH_RETRY_TOTAL_FAILURE_NOTICEAUTO_ATTACH_RETRY_TOTAL_FAILURE     8/usr/lib/python3/dist-packages/uaclient/files/notices.pyr   r      s   '(	O /&44	 -$--	 -$11	 #4+44	#  1(11	  $5,55	$  -$--66	 0'77	 '8/??	'# %6&66	%!  1(88	  .%4	 %6-11	%! '8)??	'#rJ   r   c                   :    e Zd ZdedefdZdefdZdee   fdZy)NoticesManagernotice_detailsdescriptionc                    t        j                         s+t        j                  d|j                  j
                         y|j                  j                  rt        j                  nt        j                  }dj                  |j                  j                  |j                  j
                        }t        j                  t        j                  j!                  ||      |       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_rootLOGwarningvaluer   r   r   NOTICES_PERMANENT_DIRECTORYNOTICES_TEMPORARY_DIRECTORYformatr   r	   
write_fileospathjoin)selfrN   rO   	directoryfilenames        rK   addzNoticesManager.addn   s     ))+KK@$$**  ##00 0055 	
 >>  ))>+?+?+E+E
 	GGLLH-	
rJ   c                    t        j                         s+t        j                  d|j                  j
                         y|j                  j                  rt        j                  nt        j                  }dj                  |j                  j                  |j                  j
                        }t        j                  t        j                  j!                  ||             y)ziDeletes a notice file.

        :param notice_details: Holds details concerning the notice file.
        z1NoticesManager.remove(%s) called as non-root userNrQ   )r
   rR   rS   rT   rU   r   r   r   rV   rW   rX   r   r	   ensure_file_absentrZ   r[   r\   )r]   rN   r^   r_   s       rK   removezNoticesManager.remove   s    
 ))+KKC$$**  ##00 0055 	
 >>  ))>+?+?+E+E
 	!!"'',,y("CDrJ   returnc           
      T   t         j                  t         j                  f}g }|D ]E  }t        j                  j                  |      s$t        j                  |      D cg c]A  }t        j                  j                  t        j                  j                  ||            r|C }}|D ]  }t        j                  t        j                  j                  ||            }|r|j                  |       J	 |j                  d      \  }}	d}
t        D ]$  }|j                  |k(  s|j                  |	k(  s#|}
& |

t!               |j                  |
j"                  j$                          H |j+                          |S c c}w # t         $ r t&        j)                  d|       Y w xY w)zdGets all the notice files currently saved.

        :returns: List of notice file contents.
        -Nz1Something went wrong while processing notice: %s.)r   rV   rW   rZ   r[   existslistdirisfiler\   r	   	load_fileappendsplitr   r   r   	ExceptionrU   r   rS   rT   sort)r]   notice_directoriesnoticesnotice_directory	file_namenotice_file_namesnotice_file_namenotice_file_contentsr   r   noticens               rK   listzNoticesManager.list   s    0000
  2 	77>>"23 "$,<!=!77>>"'',,/?"KL ! !
 %6  '-'7'7GGLL!13CD($ (NN#78*:*@*@*E%!%!' +A zzX5!''U:J)*+ ">"++-v||';';<#	@ 	=!. % +,s%    AF 5.F$F45FF'&F'N)	r/   r0   r1   r   strr`   rc   r   rx   rI   rJ   rK   rM   rM   m   s7    

 
>EV E,+d3i +rJ   rM   c                  .    t         
t               a t         S N)_notice_clsrM   rI   rJ   rK   
get_noticer}      s    $&rJ   rN   rd   c                 t    t               } | j                  j                  di |}|j                  | |       y )NrI   )r}   r   rX   r`   )rN   kwargsrv   rO   s       rK   r`   r`      s2    \F/.((//9&9K
JJ~{+rJ   c                 :    t               }|j                  |        y r{   )r}   rc   )rN   rv   s     rK   rc   rc      s    \F
MM.!rJ   c                  6    t               } | j                         S r{   )r}   rx   )rv   s    rK   rx   rx      s    \F;;=rJ   )loggingrZ   collectionsr   enumr   typingr   uaclientr   r   r   r	   r
   	getLoggerreplace_top_level_logger_namer/   rS   get_event_loggereventr   r   rM   r|   r}   r`   rc   ry   rx   rI   rJ   rK   <module>r      s     	 "   C Cg:::8DE%%%'I 
Z Zza aH , ,T ,"6 "d "
d3i rJ   