
    UV\
                     ^    d dl mZ d dlZd dlZddlmZmZmZmZm	Z	m
Z
  G d de          ZdS )    )absolute_importN   )LockBase
LockFailed	NotLocked	NotMyLockLockTimeoutAlreadyLockedc                   2    e Zd ZdZddZd Zd Zd Zd ZdS )	LinkLockFilezLock access to a file using atomic property of link(2).

    >>> lock = LinkLockFile('somefile')
    >>> lock = LinkLockFile('somefile', threaded=False)
    Nc                    	 t          | j        d                                           n%# t          $ r t	          d| j        z            w xY w||n| j        }t          j                    }||dk    r||z  }	 	 t          j        | j        | j	                   d S # t          $ r t          j        | j                  j        }|dk    rY d S |dt          j                    |k    rMt          j        | j                   |dk    rt          d| j        z            t!          d| j        z            t          j        |d ur|dz  pd	           Y nw xY w)
Nwbzfailed to create %sr   T   z&Timeout waiting to acquire lock for %sz%s is already locked
   g?)openunique_namecloseIOErrorr   timeouttimeoslink	lock_fileOSErrorstatst_nlinkunlinkr	   pathr
   sleep)selfr   end_timenlinkss       7/usr/lib/python3/dist-packages/lockfile/linklockfile.pyacquirezLinkLockFile.acquire   s   	G!4((..0000 	G 	G 	G2T5EEFFF	G %0''dl9;;7Q;;H	($.999, +  L L L!122;Q;; FF *ty{{X/E/E	$"2333"Q;;"- /=.2i/8 #9 #9 9 #00F04	1: #; #; ;Jwd2Cw|JsKKKKK%L		s"   '* "A<B .EBEEc                 6   |                                  st          d| j        z            t          j                            | j                  st          d| j        z            t          j        | j                   t          j        | j                   d S )Nz%s is not lockedz%s is locked, but not by me)		is_lockedr   r   r   existsr   r   r   r   r    s    r#   releasezLinkLockFile.release7   s    ~~ 	G.:;;; 011 	G9DIEFFF
	$"###
	$.!!!!!    c                 J    t           j                            | j                  S N)r   r   r'   r   r(   s    r#   r&   zLinkLockFile.is_locked?   s    w~~dn---r*   c                     |                                  oEt          j                            | j                  o!t          j        | j                  j        dk    S )Nr   )r&   r   r   r'   r   r   r   r(   s    r#   i_am_lockingzLinkLockFile.i_am_lockingB   sJ       8t/008())2a7	9r*   c                     t           j                            | j                  rt          j        | j                   d S d S r,   )r   r   r'   r   r   r(   s    r#   
break_lockzLinkLockFile.break_lockG   s<    7>>$.)) 	&Idn%%%%%	& 	&r*   r,   )	__name__
__module____qualname____doc__r$   r)   r&   r.   r0    r*   r#   r   r   
   so         $ $ $ $L" " ". . .9 9 9
& & & & &r*   r   )
__future__r   r   r    r   r   r   r   r	   r
   r   r5   r*   r#   <module>r8      s    & & & & & &  				               ?& ?& ?& ?& ?&8 ?& ?& ?& ?& ?&r*   