ó
È”Mc           @   s2   d  d l  Z  d  d l Z d e f d „  ƒ  YZ d S(   iÿÿÿÿNt	   PathLocksc           B   sP   e  Z e d  „ Z d „  Z d „  Z d „  Z d „  Z d „  Z e	 e	 d „ Z
 RS(   c         C   s   i  |  _  t | ƒ |  _ d  S(   N(   t   _lockt   boolt   _force(   t   selft   force(    (    s8   /usr/lib/python2.7/dist-packages/smart/util/pathlocks.pyt   __init__   s    	c         C   s   |  j  S(   N(   R   (   R   (    (    s8   /usr/lib/python2.7/dist-packages/smart/util/pathlocks.pyt   getForce   s    c         C   s   | |  _  d  S(   N(   R   (   R   t   flag(    (    s8   /usr/lib/python2.7/dist-packages/smart/util/pathlocks.pyt   setForce"   s    c         C   s   t  r |  j ƒ  n  d  S(   N(   t   fcntlt	   unlockAll(   R   (    (    s8   /usr/lib/python2.7/dist-packages/smart/util/pathlocks.pyt   __del__%   s     c         C   sR   x> |  j  D]3 } |  j  | } t j | t j ƒ t j | ƒ q
 W|  j  j ƒ  d  S(   N(   R   R
   t   flockt   LOCK_UNt   ost   closet   clear(   R   t   patht   fd(    (    s8   /usr/lib/python2.7/dist-packages/smart/util/pathlocks.pyR   )   s
    c         C   s^   |  j  } |  j j | ƒ } | d  k	 rZ t j | t j ƒ t j | ƒ |  j | =t	 } n  | S(   N(
   R   R   t   gett   NoneR
   R   R   R   R   t   True(   R   R   t   resultR   (    (    s8   /usr/lib/python2.7/dist-packages/smart/util/pathlocks.pyt   unlock0   s    	
	c         C   sê   |  j  } |  j j | ƒ } | d  k r… t j | t j ƒ } |  j | <t j | t j d ƒ } | t j	 O} t j | t j
 | ƒ n  | r— t j } n	 t j } | s¶ | t j O} n  y t j | | ƒ t } Wn t k
 rå } n X| S(   Ni    (   R   R   R   R   R   t   opent   O_RDONLYR
   t   F_GETFDt
   FD_CLOEXECt   F_SETFDt   LOCK_EXt   LOCK_SHt   LOCK_NBR   R   t   IOError(   R   R   t	   exclusivet   blockR   R   t   flagst   e(    (    s8   /usr/lib/python2.7/dist-packages/smart/util/pathlocks.pyt   lock:   s$    	 	
(   t   __name__t
   __module__R   R   R   R	   R   R   R   t   FalseR&   (    (    (    s8   /usr/lib/python2.7/dist-packages/smart/util/pathlocks.pyR       s   					
(   R
   R   t   objectR    (    (    (    s8   /usr/lib/python2.7/dist-packages/smart/util/pathlocks.pyt   <module>   s   