ó
å™xTc           @   sð  d  d l  m Z d  d l m Z m Z m Z m Z d  d l m Z d  d l m	 Z	 m
 Z
 d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z e j j d ƒ Z d e f d „  ƒ  YZ d	 e f d
 „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ 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 e f d  „  ƒ  YZ& d S(!   iÿÿÿÿ(   t   division(   t   Sorryt   Abortt	   multi_outt   host_and_user(   t   easy_pickle(   t   adopt_init_argst
   group_argsNsõ   
run_file = None
  .type = path
prefix = None
  .type = str
output_dir = None
  .type = path
tmp_dir = None
  .type = path
debug = False
  .type = bool
timeout = 200
  .type = int
buffer_stdout = False
  .type = bool
fsync = True
  .type = bool
t   simple_targetc           B   s   e  Z d d  „ Z d „  Z RS(   c         C   s2   t  |  t ƒ  ƒ | d  k r. t j ƒ  |  _ n  d  S(   N(   R   t   localst   Nonet   ost   getcwdt
   output_dir(   t   selft   argsR   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyt   __init__.   s    c         C   s   t  S(   N(   t   True(   R   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyt   __call__3   s    N(   t   __name__t
   __module__R
   R   R   (    (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyR   -   s   t   target_with_save_resultc           B   s,   e  Z d d d d  „ Z d „  Z d „  Z RS(   c         C   s¶   t  | t ƒ s t ‚ t  | t ƒ s9 t  | t ƒ s9 t ‚ | d  k sZ t  | t ƒ sZ t ‚ | d  k s{ t  | t ƒ s{ t ‚ t |  t ƒ  ƒ | d  k r© t j	 ƒ  |  _
 n  d  |  _ d  S(   N(   t
   isinstancet
   basestringt   AssertionErrort   listt   tupleR
   R   R	   R   R   R   t   _out(   R   R   t	   file_nameR   t   log_filet	   job_title(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyR   7   s    $!!c         C   sº   |  j  d  k	 rb t |  j  d ƒ } t ƒ  } | j d | ƒ | j d t j ƒ | t _ | |  _ n  |  j ƒ  } t	 j
 |  j | ƒ |  j d  k	 r¶ t |  j d t ƒ r¶ |  j j ƒ  n  | S(   Nt   wt   logt   stdoutt   closed(   R   R
   t   openR   t   registert   sysR!   R   t   runR   t   dumpR   t   getattrt   Falset   flush(   R   R    t   new_outt   result(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyR   B   s    		%c         C   s   t  ƒ  ‚ d  S(   N(   t   NotImplementedError(   R   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyR&   R   s    N(   R   R   R
   R   R   R&   (    (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyR   6   s   
	t   detached_process_driverc           B   s   e  Z d  „  Z d „  Z RS(   c         C   s   t  |  t ƒ  ƒ d  S(   N(   R   R	   (   R   t   target(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyR   V   s    c         C   s   |  j  ƒ  } | S(   N(   R/   (   R   R,   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyR   Y   s    (   R   R   R   R   (    (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyR.   U   s   	t   detached_process_driver_mpc           B   s   e  Z d  „  Z RS(   c         C   s   |  j  ƒ  } | S(   N(   R/   (   R   R   t   kwdst
   child_connR,   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyR   ^   s    (   R   R   R   (    (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyR0   ]   s   t   detached_basec           B   sY   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(	   c         C   s�   t  |  t ƒ  ƒ g  |  _ | j d  k r4 d | _ n  | j d  k	 rV |  j | j ƒ n5 | j d  k	 rx |  j | j ƒ n |  j t j	 ƒ  ƒ d  S(   Nt    (
   R   R	   t   _accumulated_callbackst   prefixR
   t   tmp_dirt   set_file_namesR   R   R   (   R   t   params(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyR   c   s    	c         C   s°   t  j j | |  j j ƒ } | d |  _ | d |  _ | d |  _ | d |  _ | d |  _	 | d |  _
 | d |  _ | d |  _ |  j d	 |  _ |  j d	 |  _ | |  _ d  S(
   Ns   .libtbx_starts   .libtbx_stdouts   .libtbx_errors   .libtbx_STOPs   .libtbx_aborts   .libtbx_results   .libtbx_infos   .libtbx_states   .LOCK(   R   t   patht   joinR9   R6   t
   start_filet   stdout_filet
   error_filet	   stop_filet
   abort_filet   result_filet	   info_filet
   state_filet	   info_lockt
   state_lock(   R   R7   R6   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyR8   o   s    c         C   s   t  S(   N(   R)   (   R   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyt   isAlive}   s    c         C   s   d  S(   N(    (   R   t   data(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyt   callback_start€   s    c         C   s   d  S(   N(    (   R   RG   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyt   callback_stdoutƒ   s    c         C   s   d  S(   N(    (   R   t   errort   traceback_info(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyt   callback_error†   s    c         C   s   d  S(   N(    (   R   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyt   callback_abort‰   s    c         C   s   d  S(   N(    (   R   R,   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyt   callback_finalŒ   s    c         C   s   d  S(   N(    (   R   t   status(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyt   callback_other�   s    (   R   R   R   R8   RF   RH   RI   RL   RM   RN   RP   (    (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyR3   b   s   								t   stdout_redirectc           B   s,   e  Z d  „  Z d „  Z d „  Z d „  Z RS(   c         C   s   t  |  t ƒ  ƒ d  S(   N(   R   R	   (   R   t   handler(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyR   “   s    c         C   s   |  j  j | ƒ d  S(   N(   RR   RI   (   R   RG   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyt   write–   s    c         C   s   d  S(   N(    (   R   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyR*   ™   s    c         C   s   d  S(   N(    (   R   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyt   closeœ   s    (   R   R   R   RS   R*   RT   (    (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyRQ   ’   s   			t   detached_process_serverc           B   s†   e  Z d  „  Z d „  Z d „  Z e e d „ Z d d „ Z d „  Z	 d „  Z
 d „  Z d „  Z d	 „  Z d
 „  Z d „  Z d „  Z RS(   c         O   s8   t  j |  | | Ž | |  _ t |  j d ƒ s4 t ‚ d  S(   NR   (   R3   R   R/   t   hasattrR   (   R   R/   R   R1   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyR       s    	c         O   s
   |  j  ƒ  S(   N(   R&   (   R   R   R1   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyR   ¦   s    c         C   s�  |  j  ƒ  t ƒ  |  _ t |  j d ƒ |  _ |  j j d |  j ƒ t j } t	 |  ƒ t _ d d  l
 } | j j |  j ƒ y |  j ƒ  } Wnê t k
 r¥ |  j ƒ  nÝ t k
 rt} t j t | ƒ j IJt | ƒ j d k rì |  j ƒ  q‚| j j d k r#t d | j j t | ƒ f ƒ } n t | d ƒ r?| j ƒ  n  d j t j t j ƒ  d	 ƒ ƒ } |  j | | ƒ n X|  j  | ƒ | t _ d  S(
   NR   s   Communication logiÿÿÿÿR   s   Boost.Pythons   Boost.Python.%s: %st   reset_modules   
i   (!   RH   R   t   _stdoutR#   R=   t   _tmp_stdoutR$   R%   R!   RQ   t   libtbx.callbackst	   call_backt   register_handlert   callback_wrapperR/   R   RM   t	   Exceptiont   stderrt   typeR   t	   __class__R   t   RuntimeErrort   strRV   RW   R;   t	   tracebackt	   format_tbt   exc_infoRL   RN   (   R   t
   old_stdoutt   libtbxt   return_valuet   et   traceback_str(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyR&   ©   s2    
	"c         C   s8   | r4 |  j  d t d | d | d | d | ƒ ƒ n  d  S(   NRG   t   messaget
   accumulatet   cached(   RP   R   (   R   Rl   RG   Rm   Rn   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyR]   Ç   s    c         C   s’   t  ƒ  } | j d  k	 s t ‚ t |  j d ƒ } | j ƒ  } | d  k rj t j d k rj t	 j
 ƒ  d } n  | j d | | j f ƒ | j ƒ  d  S(   NR   t   darwini   s   %s %d(   R   t   pidR
   R   R#   R<   t   get_host_nameR%   t   platformR   t   unameRS   RT   (   R   RG   t   infot   ft	   host_name(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyRH   Ï   s    	c         C   sg   |  j  j | ƒ |  j  j ƒ  |  j j rB t j |  j j ƒ  ƒ n  t j j	 |  j
 ƒ rc t ƒ  ‚ n  d  S(   N(   RX   RS   R*   R9   t   fsyncR   RY   t   filenoR:   t   isfileR?   R   (   R   RG   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyRI   Ù   s    c         C   s'   |  j  ƒ  t j |  j | | f ƒ d  S(   N(   t   cleanupR   R'   R>   (   R   RJ   RK   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyRL   á   s    
c         C   s!   |  j  ƒ  t j |  j t ƒ d  S(   N(   Rz   R   R'   R@   R   (   R   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyRM   å   s    
c         C   s!   |  j  ƒ  t j |  j | ƒ d  S(   N(   Rz   R   R'   RA   (   R   R,   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyRN   é   s    
c         C   s   d  S(   N(    (   R   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyt   callback_pauseí   s    c         C   s   d  S(   N(    (   R   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyt   callback_resumeð   s    c         C   s�   | j  s d  S| j r\ |  j j | ƒ t |  j ƒ t j |  j |  j ƒ t	 j
 |  j ƒ n0 t |  j ƒ t j |  j | ƒ t	 j
 |  j ƒ d  S(   N(   Rn   Rm   R5   t   appendt
   touch_fileRD   R   R'   RB   R   t   removeRE   RC   (   R   RG   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyRP   ó   s    		c         C   s   |  j  j ƒ  |  j  j ƒ  d  S(   N(   RX   R*   RT   (   R   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyRz      s    N(   R   R   R   R   R&   R   R]   R
   RH   RI   RL   RM   RN   R{   R|   RP   Rz   (    (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyRU   Ÿ   s   			
							t   detached_process_clientc           B   s’   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d d „ Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         O   s_   t  j |  | | Ž d  |  _ d |  _ d |  _ t |  _ t |  _ d  |  _	 d  |  _
 t |  _ d  S(   Ng        (   R3   R   R
   t   _logfilet   _info_mtimet   _state_mtimeR)   t   runningt   finishedt   _process_hostt   _process_pidR   t   update_progress(   R   R   R1   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyR     s    							c         C   s   |  j  S(   N(   R…   (   R   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyRF     s    c         C   s   |  j  S(   N(   R„   (   R   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyt
   is_started  s    c         C   sE   |  j  j } x2 t r@ |  j ƒ  |  j r, Pq t j | d ƒ q Wt S(   Ngü©ñÒMbP?(   R9   t   timeoutR   t   updateR…   t   timet   sleep(   R   RŠ   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyR&     s    	
	c         C   sÇ  |  j  rž t j j |  j ƒ rž t |  _  t |  j d ƒ j ƒ  } y. | j ƒ  \ } } | |  _	 t
 | ƒ |  _ Wn t k
 r� } d GH| GHn X|  j | ƒ n  |  j r¾ |  j ƒ  |  j ƒ  n  t j j |  j ƒ ry t j |  j ƒ \ } } Wn t k
 rqºX|  j | | ƒ n¤ t j j |  j ƒ r8|  j ƒ  n‚ t j j |  j ƒ r­y t j |  j ƒ } Wn t k
 r{d GHqºXt j d ƒ |  j ƒ  |  j ƒ  |  j | ƒ n t |  _ d  St |  _ d  S(   Nt   rs   Error acquiring runtime info:s$   EOFError trying to load result file!i   (   R„   R   R:   t   existsR<   R   R#   t   readt   splitR†   t   intR‡   R^   RH   Rˆ   t   check_stdoutt   check_statusR>   R   t   loadt   EOFErrorRL   R@   RM   RA   RŒ   R�   RN   R)   R…   (   R   RG   t   hostRp   Rj   RJ   RK   R,   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyR‹   !  sD    				
	

	c         C   sŸ   |  j  d  k r? t j j |  j ƒ r? t |  j d d ƒ |  _  n  |  j  d  k	 r› |  j  j ƒ  } |  j  j ƒ  } | d k r‹ |  j  j	 | ƒ q› |  j
 | ƒ n  d  S(   NRŽ   i    R4   (   R�   R
   R   R:   R�   R=   R#   t   tellR�   t   seekRI   (   R   t   lastRG   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyR“   H  s    $c         C   s&   |  j  d  k	 r" |  j  j d ƒ n  d  S(   Ni    (   R�   R
   R™   (   R   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyt   reset_logfileS  s    c   	      C   sÑ  t  j j |  j ƒ rt  j j |  j ƒ } | |  j k rt  j j |  j ƒ r| |  _ y t j	 |  j ƒ } Wn; t
 k
 r„ ‚  qt k
 r” qt k
 r« } | GHqXt | ƒ } t |  j ƒ } xA t | | ƒ D]- } | | } |  j j | ƒ |  j | ƒ q× Wqn  t  j j |  j ƒ rÍt  j j |  j ƒ } | |  j k rÍt  j j |  j ƒ rÍ| |  _ y t j	 |  j ƒ } Wn; t
 k
 r’‚  qÊt k
 r¢qÊt k
 r¹} | GHqÊX|  j | ƒ qÍn  d  S(   N(   R   R:   R�   RB   t   getmtimeR‚   Ry   RD   R   R•   t   KeyboardInterruptR–   R^   t   lenR5   t   rangeR}   RP   RC   Rƒ   RE   (	   R   t   mtimet   accumulated_statusRj   t   n_cbt   n_cb_oldt   it   new_cbt   current_status(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyR”   W  s>    %		
%		c         C   s|   t  |  j ƒ | rx d  |  j |  j g k rx t ƒ  } | j ƒ  |  j k rx t j |  j t	 j
 ƒ t |  _ |  j ƒ  qx n  d  S(   N(   R~   R?   R
   R†   R‡   R   Rq   R   t   killt   signalt   SIGTERMR)   R„   RM   (   R   t   forceRt   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyt   abort|  s    		c         C   s_   |  j  d k	 r t j d k s$ t ‚ y t j |  j  | ƒ Wn t k
 rV } | GHt SXt	 Sd S(   st   
    Signals the process using os.kill, which despite the name, can also
    pause or resume processes on Unix.
    t   win32N(
   R‡   R
   R%   Rr   R   R   R§   t   OSErrorR)   R   (   R   t   signal_numberRj   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyt   send_signal†  s    $c         C   s#   |  j  t j ƒ r |  j ƒ  n  d  S(   N(   R¯   R¨   t   SIGSTOPR{   (   R   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyt   pause•  s    c         C   s#   |  j  t j ƒ r |  j ƒ  n  d  S(   N(   R¯   R¨   t   SIGCONTR|   (   R   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyt   resume™  s    c         C   s   d  S(   N(    (   R   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyR{   �  s    c         C   s   d  S(   N(    (   R   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyR|      s    c         C   s‡   d d d d d d d d g } xb | D]Z } t  |  d	 | ƒ } t j j | ƒ r% y t j | ƒ Wq t k
 r{ } | GHq Xq% q% Wd  S(
   Nt   startR!   RJ   t   stopR«   R,   Rt   t   states   %s_file(   R(   R   R:   R�   R   R^   (   R   t   filest   fnR   Rj   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyt   purge_files£  s    N(   R   R   R   RF   R‰   R&   R‹   R“   R›   R”   R
   R«   R¯   R±   R³   R{   R|   R¹   (    (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyR€     s   				
	'			%
					c         C   s   t  |  d ƒ j ƒ  } d  S(   NR   (   R#   RT   (   R   Ru   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyR~   ­  s    c         C   s?   t  j d |  ƒ } t | d ƒ } | j d | ƒ | j ƒ  d  S(   Nt   python_objectR   t   out(   t   process_master_philt   formatR#   t   showRT   (   R9   R   t
   param_philRu   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyt   write_params°  s    c         C   s  t  |  d ƒ } t j | j ƒ  t j t j Bt j Bt j Bt j	 Bƒ | j
 d ƒ t } d t j k rÀ d t j k rÀ t j j t j d d ƒ } t j j | ƒ rÀ | j
 d | ƒ t } qÀ n  | ræ | j
 d t j j d ƒ ƒ n  | j
 d d	 j | ƒ ƒ | j ƒ  d  S(
   NR   s   #!/bin/sh

t   PHENIXt   PHENIX_CUSTOM_ENVs   phenix_env.shs
   source %s
s   setpaths.shs   %st    (   R#   R   t   fchmodRx   t   statt   S_IRUSRt   S_IWUSRt   S_IXUSRt   S_IRGRPt   S_IROTHRS   R   t   environR:   R;   Ry   R)   Rh   t   envt   under_buildRT   (   R   t   cmdsRu   t   use_cctbx_setpathst   env_file(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyt   write_run_script¶  s    & c         C   si  g  } xè |  D]à } t  j j | ƒ r¯ t  j j | ƒ } t  j j | ƒ \ } } | d k rz | j t j j d | ƒ ƒ qí | d k rí d | } | j t j j | ƒ ƒ qí q y t j j | ƒ } Wn t	 k
 rß } | GHq X| j | ƒ q Wt
 j d	 | ƒ }	 |	 j ƒ  }
 |
 j d  k r7|	 j ƒ  t d
 ƒ ‚ n  t j |
 j ƒ } t | d |
 ƒ} | j ƒ  d  S(   Ns   .paramss   .effs   .defs   .philR   s   .pkls   .pickles   run_file = %st   sourcess-   Pickled target function run_file not defined.R9   (   s   .paramss   .effs   .defs   .phil(   s   .pkls   .pickle(   R   R:   Ry   t   abspatht   splitextR}   Rh   t   philt   parseRb   R¼   t   fetcht   extractt   run_fileR
   R¾   R   R   R•   RU   R&   (   R   t	   user_philt   argR   t   baset   extt   input_stringt   arg_philRj   t   working_philR9   R/   t   server(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyR&   Ç  s.    
	
t   simple_clientc           B   s>   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         O   s/   d |  _  t j ƒ  |  _ t j |  | | Ž d  S(   Ni    (   R¢   t	   cStringIOt   StringIOR»   R€   R   (   R   R   R1   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyR   å  s    	c         C   s
   | ‚ d  S(   N(    (   R   RJ   RK   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyRL   ê  s    c         C   s   t  d ƒ ‚ d  S(   Ns   aborted as planned.(   R   (   R   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyt   callback_abortedí  s    c         C   s   |  j  j | ƒ d  S(   N(   R»   RS   (   R   RG   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyRI   ð  s    c         C   s   |  j  d 7_  d  S(   Ni   (   R¢   (   R   RG   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyRP   ô  s    c         C   s   | |  _  d  S(   N(   R,   (   R   R,   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyRN   ÷  s    (   R   R   R   RL   Rå   RI   RP   RN   (    (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyRâ   ä  s   					t
   simple_runc           B   s   e  Z d  „  Z d „  Z RS(   c         C   s   t  |  t ƒ  ƒ d  S(   N(   R   R	   (   R   R   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyR   û  s    c         C   s%  d } xt  d d ƒ D]} d | d d } } d } d } d g d } t  d d ƒ } t j d	 | d  d
 t ƒt j d ƒ xq t  d | ƒ D]` }	 x$ | D] }
 | d d | |
 <} q� Wd } x  | D] }
 | | | |
 } qÊ W| | } q� W| | 7} t j d | d
 t ƒd | GHq W| S(   Ni    i   gš™™™™™¹?i   i N  g      $@g        id   s   run %dRm   g       @t   current_totals   current is %f(   RŸ   Rh   R[   R
   R   RŒ   R�   R)   (   R   t   pu_totalR&   t   xt   nt   mut   put   polRŽ   R¤   t   jt   su(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyR   þ  s(    
(   R   R   R   R   (    (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyRæ   ú  s   	t   simple_funcc           B   s   e  Z d  „  Z d „  Z RS(   c         C   s   | |  _  d  S(   N(   Ré   (   R   Ré   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyR     s    c         C   s   |  j  GHd  S(   N(   Ré   (   R   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyR     s    (   R   R   R   R   (    (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyRð     s   	('   t
   __future__R    t   libtbx.utilsR   R   R   R   Rh   R   R   R   t   libtbx.load_envt   libtbx.philRã   Rd   R¨   RÅ   RŒ   R   R%   RÕ   RÖ   R¼   t   objectR   R   R.   R0   R3   RQ   RU   R€   R~   RÀ   RÑ   R&   Râ   Ræ   Rð   (    (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/runtime_utils.pyt   <module>   s:   "			0f¨				