ó
Ń%Tc           @   sz   d  Z  d d l Z d d l Z d d l Z d a e j j e j j e	   Z
 d   Z d   Z d e f d     YZ d S(   s   Store and check RCrane settingsi˙˙˙˙Nc          C   sç  t  d k	 r t  Sd }  y t j d }  Wn t k
 r: n X|  d k ro y t j d }  Wqo t k
 rk qo Xn  |  d k rt j j d  rŹ t j j d  rŹ |  d k qt j j d  rÝ t j j d  rÝ |  d k qt j j d	  rt j j d
  r|  d k qn  |  d k r-t d   d St j j |  d  } t j j	 |  rt j j
 |  sĹt d | d   qĹnE y t j |  Wn1 t k
 rÄ} t d | d t |    n Xt j j |  d d  } | a  | S(   s@  Return the filename of the RCrane launch/settings script
    
    ARGUMENTS:
        None
    RETURNS:
        None
    EXCEPTIONS:
        RCraneSettingsError - if the appropriate filename cannot be determined
                              or if the .coot-preferences directory does not exist and cannot be created
    t   HOMEt	   COOT_HOMEs   C:\WinCootin\coots   C:\WinCootin\coot-real.exes
   C:\WinCoots    C:\Program Files\WinCootin\coots)   C:\Program Files\WinCootin\coot-real.exes   C:\Program Files\WinCoots&   C:\Program Files (x86)\WinCootin\coots/   C:\Program Files (x86)\WinCootin\coot-real.exes   C:\Program Files (x86)\WinCoots6   Can't determine home directory ($HOME or %COOT_HOME%).Ns   .coot-preferencess-   Could not create Coot preferences directory: s'   
A file of the same name already existss   
Error: s	   rcrane.py(   t
   __filenamet   Nonet   ost   environt   KeyErrort   patht   getsizet   RCraneSettingsErrort   joint   existst   isdirt   mkdirt   OSErrort   str(   t   homedirt   preferencesDirt   errort   filename(    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/settings.pyt   settingsFilename   sB    $$$"c         C   s   t  t   d  } d } x. | D]& } t j |  |  r | j   t Sq W| d k se | d d k rn d } n d } | j | |  d  | j   d S(   s
  Adds the specified setting to the end of the RCrane configuration file
    
    ARGUMENTS:
        setting - the setting to add to the configuration file
    RETURNS:
        True if the setting was added succesfully
        False if the setting already existed
    s   a+i˙˙˙˙s   
t    N(   t   openR   R   t   ret   matcht   closet   Falset   write(   t   settingt   settingsFilet   curlinet   newline(    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/settings.pyt
   addSettingh   s    
	R	   c           B   s    e  Z d  Z d   Z d   Z RS(   s9   Errors associated with setting or reading RCrane settingsc         C   s   | |  _  d  S(   N(   t   value(   t   selfR!   (    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/settings.pyt   __init__   s    c         C   s   |  j  S(   N(   R!   (   R"   (    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/settings.pyt   __str__   s    (   t   __name__t
   __module__t   __doc__R#   R$   (    (    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/settings.pyR	      s   	(   R'   R   t   os.pathR   R   R   R   t   dirnamet   abspatht   __file__t
   rcranePathR   R    t	   ExceptionR	   (    (    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/settings.pyt   <module>   s   $	O	