+
     g                     >   ^ RI t ^ RIt^ RIt^ RIHt ^ RIHtHtHt ^ RI	H
t
HtHt ^ RIHt ^ RIHtHt ^ RIHt ^ RIHt ] P,                  ! ]P.                  ! ]4      4      t ! R	 R
]
4      t]! ]]! RRR7      ]P6                  4      tR R ltR t ! R R4      tR# )    N)Tuple)
exceptionssystemutil)
DataObjectFieldStringDataValue)notices)DataObjectFileDataObjectFileFormat)UAFile)Noticec                   V   a  ] tR t^t o ]! R]4      ]! R]4      .tV 3R lR ltRtV t	R# )LockDatalock_pidlock_holderc                &   < V ^8  d   QhRS[ RS[ /# )   r   r   )str)format__classdict__s   "//usr/lib/python3/dist-packages/uaclient/lock.py__annotate__LockData.__annotate__   s     ' ' '3 '    c                    Wn         W n        R # Nr   r   )selfr   r   s   &&&r   __init__LockData.__init__   s     &r   )r   r   N)
__name__
__module____qualname____firstlineno__r   r	   fieldsr    __static_attributes____classdictcell__r   s   @r   r   r      s*     j/*m_-F
' 'r   r   lockF)privatec                F    V ^8  d   QhR\         \        \        3,          /# )r   return)r   intr   )r   s   "r   r   r   "   s     ' 'sCx 'r   c                 n    \         P                  4       p RpT '       g   T# T P                  pT P                  p \        P                  ! RT.4       \        T4      T3#   \        P                   d'    \        P                  ! \         P
                  R7      hi ; i  \        P                   d    \        P                  ! 4       '       g'   \        P                  RTT4       \        T4      T3u # \        P!                  RTT4       \        P"                  ! \         P
                  4       Tu # i ; i)zReturn lock info if lock file is present the lock is active.

If process claiming the lock is no longer present, remove the lock file
and log a warning.

:return: A tuple (pid, string describing lock holder)
    If no active lock, pid will be -1.
)lock_file_pathpsz.Found stale lock file previously held by %s:%sz1Removing stale lock file previously held by %s:%s) )lock_data_filereadr   InvalidFileFormatErrorInvalidLockFilepathr   r   r   subpr.   ProcessExecutionErrorr   we_are_currently_rootLOGdebugwarningensure_file_absent)lock_data_objno_lockr   r   s       r   check_lock_inforB   "   s   M&++- G%%H++KT8$%H{++ ,, M((8K8KLLM ++ ))++II@
 M;//?	

 	!!."5"56s(   A  $B  ;B/D4$D44=D43D4c                  .    \         P                  4        R # r   )r4   delete r   r   clear_lock_file_if_presentrF   L   s    r   c                   T   a  ] tR t^Pt o RtR^
R^/V 3R lR lltR tR tR tR	t	V t
R
# )	RetryLocka,  
Context manager for gaining exclusive access to the lock file.

Create a lock file if absent. The lock file will contain a pid of the
running process, and a customer-visible description of the lock holder.

The RetryLock will try several times to acquire the lock before giving up.
The number of times to try and how long to sleep in between tries is
configurable.

:param lock_holder: String with the service name or command which is
    holding the lock. This lock_holder string will be customer visible in
    status.json.
:param sleep_time: Number of seconds to sleep before retrying if the lock
    is already held.
:param max_retries: Maximum number of times to try to grab the lock before
    giving up and raising a LockHeldError.
:raises: LockHeldError if lock is held after (sleep_time * max_retries)

sleep_timemax_retriesc                ,   < V ^8  d   QhRS[ RS[RS[/# )r   r   rI   rJ   )r   r.   )r   r   s   "r   r   RetryLock.__annotate__e   s+     	' 	' 	' 		'
 	'r   c               *    Wn         W n        W0n        R # r   )r   rI   rJ   )r   r   rI   rJ   _argss   &$$$*r   r    RetryLock.__init__e   s     '$&r   c                ^   \        4       w  rV^ 8  d$   \        P                  ! V P                  VVR7      h\        P                  \        \        \        P                  ! 4       4      V P                  R7      4       \        P                  ! \        P                  V P                  R7       R# )r   )lock_requestr   pidr   )	operationN)rB   r   LockHeldErrorr   r4   writer   r   osgetpidr
   addr   OPERATION_IN_PROGRESS)r   r   cur_lock_holders   &  r   	grab_lockRetryLock.grab_lockp   s    &5&7#a<**!--+ 
 	c"))+.D<L<LM	
 	((&&	
r   c                z   \         P                  R V P                  4       ^ p  V P                  4        R#   \        P
                   do   p\         P                  RT^,           TP                  4       T^,          pYP                  8  d   Th\        P                  ! T P                  4        Rp?K  Rp?ii ; i)zspin lock starting for %sz%RetryLock Attempt %d. %s. Spinning...N)r<   r=   r   r[   r   rT   msgrJ   timesleeprI   )r   trieses   &  r   	__enter__RetryLock.__enter__   s    		-t/?/?@0 ++ 0		;UQY 
,,,GJJt//0s   7 B:A#B55B:c                v    \         P                  4        \        P                  ! \        P
                  4       R # r   )r4   rD   r
   remover   rY   )r   	_exc_type
_exc_value
_tracebacks   &&&&r   __exit__RetryLock.__exit__   s     v334r   )r   rJ   rI   N)r"   r#   r$   r%   __doc__r    r[   rc   rj   r'   r(   r)   s   @r   rH   rH   P   s<     (	' 		'
 	' 	'
 0"5 5r   rH   ) loggingrV   r_   typingr   uaclientr   r   r   uaclient.data_typesr   r   r	   uaclient.filesr
   uaclient.files.data_typesr   r   uaclient.files.filesr   uaclient.files.noticesr   	getLoggerreplace_top_level_logger_namer"   r<   r   JSONr4   rB   rF   rH   rE   r   r   <module>rx      s     	   - - B B " J ' )::8DE'z '  
65!'TC5 C5r   