ó
ë™xTc           @   sæ   d  d l  m Z d  d l m Z d  d l Z d  d l Z d  d l Z d  d l Z d e f d „  ƒ  YZ	 d e f d „  ƒ  YZ
 d e f d	 „  ƒ  YZ d
 „  Z d „  Z d „  Z d „  Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   iÿÿÿÿ(   t   division(   t   EmptyNt   Instantc           B   s   e  Z d  Z d „  Z RS(   s   
  Timeout immediately
  c         C   s   t  d ‚ d  S(   Ns   No data found in queue(   R   (   t   self(    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/queuing_system_utils/file_queue.pyt   __call__   s    (   t   __name__t
   __module__t   __doc__R   (    (    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/queuing_system_utils/file_queue.pyR   
   s   t   Timedc           B   s    e  Z d  Z d „  Z d „  Z RS(   s   
  Timeout after given time
  c         C   s   | |  _  | |  _ d  S(   N(   t   timeoutt   waittime(   R   R	   R
   (    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/queuing_system_utils/file_queue.pyt   __init__   s    	c         C   s_   d |  j  k  rR d d  l } t |  j  |  j ƒ } |  j  |  j 8_  | j | ƒ n	 t d ‚ d  S(   Ni    iÿÿÿÿs%   No data found in queue within timeout(   R	   t   timet   minR
   t   sleepR   (   R   R   R
   (    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/queuing_system_utils/file_queue.pyR      s    (   R   R   R   R   R   (    (    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/queuing_system_utils/file_queue.pyR      s   	t   Eternalc           B   s    e  Z d  Z d „  Z d „  Z RS(   s   
  No timeout
  c         C   s   | |  _  d  S(   N(   R
   (   R   R
   (    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/queuing_system_utils/file_queue.pyR   0   s    c         C   s    d d  l  } | j |  j ƒ d  S(   Niÿÿÿÿ(   R   R   R
   (   R   R   (    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/queuing_system_utils/file_queue.pyR   5   s    (   R   R   R   R   R   (    (    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/queuing_system_utils/file_queue.pyR   +   s   	c         C   s=   |  s t  ƒ  S| d  k	 r, t d | d | ƒ St d | ƒ Sd  S(   NR	   R
   (   R   t   NoneR   R   (   t   blockR	   R
   (    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/queuing_system_utils/file_queue.pyt   get_timeout_object;   s
    c         C   s5   t  j d | d |  d | ƒ \ } } t j | ƒ | S(   Nt   suffixt   prefixt   dir(   t   tempfilet   mkstempt   ost   close(   R   R   t   foldert   fdt   fname(    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/queuing_system_utils/file_queue.pyt	   temp_nameH   s    $c         C   sQ   xJ t  rL y% t j |  j ƒ  t j t j Bƒ PWq t k
 rH | ƒ  q Xq Wd  S(   N(   t   Truet   fcntlt   lockft   filenot   LOCK_EXt   LOCK_NBt   IOError(   t   fobjR	   (    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/queuing_system_utils/file_queue.pyt   _lockO   s    	 c         C   s   t  j |  j ƒ  t  j ƒ d  S(   N(   R   R    R!   t   LOCK_UN(   R%   (    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/queuing_system_utils/file_queue.pyt   _unlockZ   s    t   Queuec           B   sY   e  Z d  Z d d d d „ Z e d
 d „ Z d „  Z d „  Z e d
 d „ Z	 d	 „  Z
 RS(   sI   
  File-based queue. Can be used cross-host via an NFS 3.0 filesystem.
  t   tmpt   .gš™™™™™¹?c         C   s’   | |  _  t d | d d d | ƒ |  _ t d | d d d | ƒ |  _ t d | d d d | ƒ |  _ t |  j d ƒ � } t j d | ƒ Wd  QXd  S(	   NR   R   s   .putR   s   .gets   .offsett   wi    (   R
   R   t	   _put_filet	   _get_filet   _offset_filet   opent   picklet   dump(   R   R   R   R
   t   foff(    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/queuing_system_utils/file_queue.pyR   d   s    	c      	   C   s‰   t  d | d | d |  j ƒ } t |  j d ƒ �S } t | | ƒ z1 | j d t j ƒ t j	 | | ƒ | j
 ƒ  Wd  t | ƒ XWd  QXd  S(   NR   R	   R
   s   r+bi    (   R   R
   R0   R-   R&   t   seekR   t   SEEK_ENDR1   R2   t   flushR(   (   R   t   valueR   R	   t   tobjt   fput(    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/queuing_system_utils/file_queue.pyt   putq   s    c      	   C   sÏ   t  |  j d ƒ �± } | j | t j ƒ y t j | ƒ } | j ƒ  } Wnu t k
 r¾ x& t j	 j
 |  j ƒ d k r | ƒ  qZ W| j d t j ƒ |  j d | d | ƒ } | j ƒ  d } n XWd  QX| | f S(   Ns   r+bi    t   fgetR	   (   R0   R.   R4   R   t   SEEK_SETR1   t   loadt   tellt   EOFErrort   patht   getsizeR-   t-   read_one_and_transfer_remanining_put_contentst   truncate(   R   t   offsetR	   R;   R7   (    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/queuing_system_utils/file_queue.pyt   get_next_item…   s    		
c      	   C   s¹   t  |  j d ƒ �¡ } t | | ƒ z t j | ƒ } d } x< t rx | j | ƒ } | j | ƒ t | ƒ | k  r= Pq= q= W| j	 d t
 j ƒ | j ƒ  | j ƒ  Wd  t | ƒ XWd  QX| S(   Ns   r+bi   i    (   R0   R-   R&   R1   R=   R   t   readt   writet   lenR4   R   R<   RC   R6   R(   (   R   R;   R	   R9   R7   t	   chunksizet   data(    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/queuing_system_utils/file_queue.pyRB   �   s    	
c      	   C   s°   t  d | d | d |  j ƒ } t |  j d ƒ �z } t | | ƒ zX t j | ƒ } |  j d | d | ƒ \ } } | j d ƒ t j	 | | ƒ | j
 ƒ  Wd  t | ƒ XWd  QX| S(   NR   R	   R
   s   r+bRD   i    (   R   R
   R0   R/   R&   R1   R=   RE   R4   R2   RC   R(   (   R   R   R	   R8   R3   RD   R7   (    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/queuing_system_utils/file_queue.pyt   get·   s    c         C   sI   xB |  j  |  j |  j g D]( } t j j | ƒ r t j | ƒ q q Wd  S(   N(   R.   R-   R/   R   R@   t   existst   remove(   R   R   (    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/queuing_system_utils/file_queue.pyR   Ï   s    N(   R   R   R   R   R   R   R:   RE   RB   RK   R   (    (    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/queuing_system_utils/file_queue.pyR)   _   s   		t   QFactoryc           B   s8   e  Z d  Z d d d d „ Z d „  Z e d „  ƒ Z RS(   s>   
  Creator pattern for file queue, also include destruction
  R*   R+   gš™™™™™¹?c         C   s   | |  _  | |  _ | |  _ d  S(   N(   R   R   R
   (   R   R   R   R
   (    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/queuing_system_utils/file_queue.pyR   Û   s    		c         C   s"   t  d |  j d |  j d |  j ƒ S(   NR   R   R
   (   R)   R   R   R
   (   R   (    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/queuing_system_utils/file_queue.pyt   createâ   s    c         C   s   |  j  ƒ  d  S(   N(   R   (   t   queue(    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/queuing_system_utils/file_queue.pyt   destroyç   s    (   R   R   R   R   RO   t   staticmethodRQ   (    (    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/queuing_system_utils/file_queue.pyRN   Ö   s   	(   t
   __future__R    R)   R   R1   R   R   R   t   objectR   R   R   R   R   R&   R(   RN   (    (    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/queuing_system_utils/file_queue.pyt   <module>   s   
				w