ó
é™xTc           @   sw   d  d l  m Z d  d l Z d  d l m Z m Z d  d l Z e j Z	 d e
 f d „  ƒ  YZ d e
 f d „  ƒ  YZ d S(   iÿÿÿÿ(   t   divisionN(   t   Sorryt   format_exceptiont   argument_interpreterc           B   s\   e  Z d d d d d  „ Z d „  Z d „  Z d d „ Z d d d d „ Z d d d „ Z RS(   c         C   s›   | d  k r d } n  | | g j d  ƒ d k s6 t ‚ | d  k rs d d  l } | j d d d t d d ƒ | } n  | |  _ | |  _ | |  _ d  |  _	 d  S(	   Ns   command line i   iÿÿÿÿt   messagesZ   The "master_params" keyword argument name is deprecated. Please use "master_phil" instead.t   categoryt
   stackleveli   (
   t   Nonet   countt   AssertionErrort   warningst   warnt   DeprecationWarningt   master_philt
   home_scopet   argument_descriptiont   target_paths(   t   selfR   R   R   t   master_paramsR
   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/phil/command_line.pyt   __init__	   s    	!					c         C   sû   | j  | ƒ } | d k  r d S| d k rG t | ƒ t | ƒ k rG d St } |  j d  k	 rÃ |  j d | | k rw d S| j |  j d ƒ rÃ | j d | ƒ r¤ d S| j | ƒ r· d St } qÃ n  | rÍ d S| j d | ƒ rä d S| j | ƒ r÷ d	 Sd
 S(   Ni    i   t   .i   i   i   i   i   i   i   (   t   findt   lent   FalseR   R   t
   startswitht   endswitht   True(   R   t   source_patht   target_patht   it!   target_path_start_with_home_scope(    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/phil/command_line.pyt   get_path_score   s,     $       c         C   s:  y& t  j j d | d |  j d ƒ } Wn0 t k
 rX t d |  j | t ƒ  f ƒ ‚ n X|  j d  k r“ g  |  j	 j
 ƒ  D] } | j ^ qx |  _ n  | j
 ƒ  } d } xD| D]<} | j } g  |  j D] } |  j | j | ƒ ^ qÅ } t | ƒ }	 |	 d k r&t d |  j | j ƒ  j ƒ  f ƒ ‚ n  | j |	 ƒ d k r¼d	 | j ƒ  j ƒ  g }
 |
 j d
 ƒ x@ t |  j | ƒ D], \ } } | |	 k rt|
 j d | ƒ qtqtWt d j |
 ƒ ƒ ‚ n  | | j d |  j | j |	 ƒ ƒ j ƒ  7} q¬ W| d k rt d |  j | f j ƒ  ƒ ‚ n  t  j j d | d |  j d ƒ S(   Nt   input_stringt   source_infot   argumentsB   Error interpreting %sargument as parameter definition:
  "%s"
  %st    i    s"   Unknown %sparameter definition: %si   s"   Ambiguous parameter definition: %ss   Best matches:s     s   
t   names*   %sparameter definition has no effect: "%s"(   t   libtbxt   philt   parseR   t   RuntimeErrorR   R   R   R   R   t   all_definitionst   patht   objectR   t   maxt   as_strt   stripR   t   appendt   zipt   joint   customized_copyt   indext
   capitalize(   R   t   argt   paramst   object_locatort   source_definitionst   complete_definitionsR+   R   t   scorest	   max_scoret   errort   score(    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/phil/command_line.pyt   process_arg.   sJ    (	("$c         C   s$  g  } x| D]} t  | j ƒ  ƒ d k r1 q n  | j d ƒ r‹ | d } | j d ƒ d k  rl | d 7} n  | j |  j d | ƒ ƒ q n  t j | ƒ ré t j | ƒ d k ré y  | j t	 j
 j d | ƒ ƒ Wq t k
 râ qé Xq n  | j d ƒ d k r5y | j |  j d | ƒ ƒ Wq t k
 r.q5Xq n  | d  k	 r™| d | ƒ } t | t	 j
 j ƒ rx| j | ƒ q q™| d  k	 r™| t k r™q q™n  t j | ƒ rít	 j
 j d | ƒ d d	 l m } t d
 |  j | | ƒ f ƒ ‚ n  d d	 l m } t d |  j | | ƒ f ƒ ‚ q W| S(   Ni    s   --i   t   =s    = TrueR5   t	   file_nameiÿÿÿÿ(   t   show_stringsO   Programming error or highly unusual situation (while processing %sargument %s).s   Uninterpretable %sargument: %s(   R   R.   R   R   R/   R>   t   opt   isfilet   getsizeR%   R&   R'   t	   ExceptionR   t
   isinstancet   scopeR   t   libtbx.str_utilsRA   R(   R   R   (   R   t   argst   custom_processort
   user_philsR5   t   arg_workt   resultRA   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/phil/command_line.pyt   process_argsU   sP    
 $     	c         C   se   | | g j  d  ƒ d k s! t ‚ | d  k	 rO | d  k s? t ‚ |  j d | ƒ S|  j d | d | ƒ S(   Ni   R5   RI   RJ   (   R   R   R	   R>   RN   (   R   R5   RI   RJ   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/phil/command_line.pyt   process{   s
    !c            s™   t  | t ƒ r9 | d k s! t ‚ g  ‰  ‡  f d †  } n d  ‰  |  j d | d | ƒ } | j t | ƒ ƒ |  j j d | ƒ } ˆ  d  k r� | S| ˆ  f S(   Nt   collect_remainingc            s   ˆ  j  |  ƒ t S(   N(   R/   R   (   R5   (   t   remaining_args(    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/phil/command_line.pyRJ   †   s    RI   RJ   t   sources(	   RF   t   strR	   R   RO   t   extendt   listR   t   fetch(   R   RI   RJ   t   extra_sourcesRR   RM   (    (   RQ   sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/phil/command_line.pyt   process_and_fetch‚   s    N(    (	   t   __name__t
   __module__R   R   R   R>   RN   RO   RX   (    (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/phil/command_line.pyR      s   		'&RO   c           B   s#   e  Z d d d  „ Z d d „ Z RS(   c         C   sy   | d  k r t j j } n  | |  _ |  j d | d t ƒ |  _ t d |  j ƒ j d | d d d | ƒ \ |  _ |  _	 d  S(   NR    t   process_includesR   RI   RJ   RP   RW   (
   R   R%   R&   R'   R   t   masterR   RX   t   workRQ   (   R   RI   t   master_stringR'   RW   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/phil/command_line.pyR   ”   s     	c         C   s   |  j  j d | ƒ |  S(   Nt   out(   R]   t   show(   R   R_   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/phil/command_line.pyR`   Ÿ   s    N(    (   RY   RZ   R   R   R`   (    (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/phil/command_line.pyRO   ’   s   (   t
   __future__R    t   libtbx.philR%   t   libtbx.utilsR   R   t   osR*   RB   R+   R   RO   (    (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/phil/command_line.pyt   <module>   s   	‹