ó
û™xTc           @   sx   d  d l  m Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d „  Z d „  Z e	 d k rt e ƒ  n  d S(   iÿÿÿÿ(   t   divisionNc          C   s¾  d d l  }  t j j |  j j ƒ d } t j } t j d k rŠ t j j	 d ƒ rŠ t j j	 d ƒ rŠ t j j
 t j d t j d ƒ } n" t j j	 d ƒ r¬ t j d } n  xh t j | ƒ D]W } d | d	  k r¼ d
 | d k r¼ | d  } |  j j d | } t | | | ƒ q¼ q¼ Wt j j
 | d ƒ } t j j | ƒ rº| t j k r`t j j | ƒ n  xW t j | ƒ D]C } d | d	  k rpd
 | d k rp| d  } t | | | ƒ qpqpWn  d S(   sÉ   Look for files named Format(something).py in the sensible
  places (i.e. in the xia2 distribution and in the users home area)
  and import the corresponding modules using their fully qualified
  names.iÿÿÿÿNi    t   ntt	   HOMEDRIVEt   HOMEPATHt   HOMEt   Formati   s   .pyiýÿÿÿt   .s   .dxtbx(   t   dxtbx.formatt   ost   patht   splitt   formatt   __file__t   curdirt   namet   environt   has_keyt   joint   listdirt   __name__t   _LoadFormatModulet   existst   syst   append(   t   dxtbxt
   format_dirt   homet   fR   t   fqname(    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/RegistryHelpers.pyt   LoadFormatClasses   s.    	 
 
c         C   s¾   y t  j | SWn t k
 r" n Xy" t j |  | g ƒ \ } } } Wn t k
 rY d SXzI y t j | | | | ƒ } Wn& t j	 k
 r¡ } t
 j t  j ƒ n XWd | r¹ | j ƒ  n  X| S(   sW  Load a format class module, which will trigger the automated
  self-registration.  This module will therefore not need to publish
  anything as the module will self-publish.  The idea being that
  these format classes were found by the search procedure above.  On
  success, the function returns the loaded module, otherwise it
  returns None.N(   R   t   modulest   KeyErrort   impt   find_modulet   ImportErrort   Nonet   load_modulet
   exceptionst	   Exceptiont	   tracebackt	   print_exct   stderrt   close(   R   R   R	   t   streamt   pathnamet   descriptiont   modulet   e(    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/RegistryHelpers.pyR   7   s     	" t   __main__(
   t
   __future__R    R   R   R    R%   R'   R   R   R   (    (    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/RegistryHelpers.pyt   <module>
   s   	%	