ó
æ™xTc           @   s6  d  d l  m Z d  d l Z d  d l Z d  d l Z d  d l Z d d d „  ƒ  YZ d „  Z d „  Z e	 d k r2d  d l
 Z
 d  d l Z d  d l Z e j j d d	 ƒ Z e j Z e j d
 k rá e j e j e e e f ƒ n e j e j e e e f ƒ e j d ƒ e
 j ƒ  Z e GHe r2e j ƒ  GHq2n  d S(   iÿÿÿÿ(   t   divisionNt
   FileClientc           B   s¤   e  Z d  d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d	 „  Z	 d
 „  Z
 d „  Z d „  Z d „  Z d „  Z d i  d „ Z d „  Z d „  Z RS(   t    i@  c         C   s¤   | d k s | d k r! d } n  | s6 t  j ƒ  } n  | |  _ |  j j d ƒ d k rs |  j j d ƒ d |  _ n  t  j |  j ƒ |  _ t | ƒ |  _ d  |  _
 d  S(   Ns	   127.0.0.1t	   localhostR   s   
iÿÿÿÿi    (   t   sockett   getfqdnt   hostt   findt   splitt   gethostbynamet   IPt   intt   portt   Nonet   sock(   t   selfR   R   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/server/FileClient.pyt   __init__	   s    		c         O   s   |  j  d | | ƒ S(   Nt   GetServerDetails(   t   _remote_call(   R   t   argt   kw(    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/server/FileClient.pyR      s    c         O   s   |  j  d | | ƒ S(   Nt   GetHost(   R   (   R   R   R   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/server/FileClient.pyR      s    c         O   s   |  j  d | | ƒ S(   Nt   GetPort(   R   (   R   R   R   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/server/FileClient.pyR      s    c         O   s   |  j  d | | ƒ S(   Nt   LockFile(   R   (   R   R   R   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/server/FileClient.pyR   '   s    c         O   s   |  j  d | | ƒ S(   Nt   ReadFile(   R   (   R   R   R   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/server/FileClient.pyR   *   s    c         O   s   |  j  d | | ƒ S(   Nt	   WriteFile(   R   (   R   R   R   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/server/FileClient.pyR   -   s    c         O   s   |  j  d | | ƒ S(   Nt   ReadPickleFile(   R   (   R   R   R   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/server/FileClient.pyR   0   s    c         O   s   |  j  d | | ƒ S(   Nt   WritePickleFile(   R   (   R   R   R   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/server/FileClient.pyR   3   s    c         O   s   |  j  d | | ƒ S(   Nt
   UnlockFile(   R   (   R   R   R   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/server/FileClient.pyR   6   s    c         O   s   |  j  d | | ƒ S(   Nt
   FileExists(   R   (   R   R   R   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/server/FileClient.pyR   9   s    c         O   s   |  j  d | | ƒ S(   Nt   getpid(   R   (   R   R   R   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/server/FileClient.pyR   ?   s    c         O   s   |  j  d | | ƒ S(   Nt   tester(   R   (   R   R   R   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/server/FileClient.pyR   B   s    c         C   s,  d  } |  j d  k ry t j t j t j ƒ |  _ |  j j |  j |  j f ƒ |  j j d ƒ |  _	 |  j j d ƒ |  _
 n  t j | |  j	 d ƒ t j | |  j	 d ƒ t j | |  j	 d ƒ |  j	 j ƒ  y t j |  j
 ƒ } Wn t k
 r÷ d  } n X|  j	 j ƒ  |  j
 j ƒ  |  j j ƒ  d  |  _ | S(   Nt   wbt   rbi   (   R   R   R   t   AF_INETt   SOCK_STREAMt   connectR   R   t   makefilet   sendt   recvt   picklet   dumpt   flusht   loadt	   Exceptiont   close(   R   t   metht   argst   kwdst   result(    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/server/FileClient.pyR   I   s&    
	c         C   s¶   d |  j  j } | d t |  j ƒ 7} | d t |  j ƒ 7} | d t |  j ƒ 7} | d t |  j ƒ 7} y2 | d t |  j ƒ 7} | d t |  j ƒ 7} Wn t	 k
 r± n X| S(   Ns   
Class s   
	host s   
	IP   s   
	port s   
	sock s   
	send s   
	recv (
   t	   __class__t   __name__t   strR   R
   R   R   R&   R'   R,   (   R   t   outl(    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/server/FileClient.pyt   __repr__i   s    c         C   sƒ   yk |  j  d d i  ƒ d  |  _ |  j  d d i  ƒ d  |  _ |  j  d d i  ƒ d  |  _ |  j  d d i  ƒ Wn t k
 r~ n Xd  S(   Nt   shutdown(    (    (    (    (   R   R   R   R,   (   R   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/server/FileClient.pyR7   v   s    			(    (   R3   t
   __module__R   R   R   R   R   R   R   R   R   R   R   R   R   R   R6   R7   (    (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/server/FileClient.pyR      s$   			
											c         C   sl   |  j  | | ƒ zD |  j | ƒ } d } | rS | | ƒ \ } } |  j | | ƒ n  Wd |  j | | ƒ X| S(   sä   
  This method will lock a file, read the contents and pass it to
  the user defined function.  This function should return the
  return item and the new contents of the file.  The contents is
  writing and the file unlocked.
  N(   R   R   R   R   R   (   t   clientt   filet   idt   funct   linest   return_item(    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/server/FileClient.pyt   LockReadProcessWriteUnlock†   s    c         C   sl   |  j  | | ƒ zD |  j | ƒ } d } | rS | | ƒ \ } } |  j | | ƒ n  Wd |  j | | ƒ X| S(   s1   
  Same as above except a pickled obj is used.
  N(   R   R   R   R   R   (   R9   R:   R;   R<   t   objR>   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/server/FileClient.pyt&   LockReadPickleProcessWritePickleUnlock›   s    t   __main__t   libtbxs   libtbx/server/StartServer.pyt   win32i   (    (   t
   __future__R    R(   R   t   syst   osR   R?   RA   R3   t
   FileServert   timet   libtbx.load_envRC   t   envt
   under_distt   cmdt
   executablet   python_patht   platformt   spawnvt   P_NOWAITt   spawnvpt   sleept   GetServerClientR9   R   (    (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/server/FileClient.pyt   <module>   s.   			