
Ԑ\c           @  s   d  d l  m Z d  d l Z d  d l Z d  d l Z d  d l Z e j e  Z d   Z	 e
   Z d   Z d   Z d   Z e j j d e  d S(   i(   t   print_functionNc         C  s   t  | j | |  f  d S(   sj   
    Reports that the call statement ending at `position` in `filename`
    is missing a from clause.
    N(   t   missingt   append(   t   targett   filenamet   position(    (    s   renpy/add_from.pyt   report_missing!   s    c         C  s   |  j  d d  }  d } xa t r{ | r< d j |  |  } n d j |   } t j j |  rn | t k rn Pn  | d 7} q Wt j |  | S(   sL   
    Generate a reasonable and unique new label for a call to `target`.
    t   .t   _i    s   _call_{}_{}s   _call_{}i   (   t   replacet   Truet   formatt   renpyt   exportst	   has_labelt
   new_labelst   add(   R   t   nt   label(    (    s   renpy/add_from.pyt   generate_label.   s    	c         C  s/  t  j j |   s d St |  } | j   t j |  d d   } | j   } Wd QXd } d } xD | D]< \ } } | | | | !7} | } | d j t	 |   7} qg W| | | 7} t j |  d d d   } | j
 |  Wd QXy t  j |  d	  Wn n Xt  j |  |  d	  t  j |  d |   d S(
   s,   
    Adds missing from clauses to `fn`.
    Nt   rs   utf-8i    u    s    from {}s   .newt   ws   .bak(   t   ost   patht   existsR   t   sortt   codecst   opent   readR   R   t   writet   unlinkt   rename(   t   fnt   editst   ft   datat   consumedt   outputR   R   (    (    s   renpy/add_from.pyt   process_fileF   s*    

c          C  sG   t  j j d  x0 t D]( }  |  j t  j j  r t |   q q Wt S(   Ns;   Adds from clauses to call statements that are missing them.(	   R   t	   argumentst   takes_no_argumentsR   t
   startswitht   configt   gamedirR&   t   False(   R    (    (    s   renpy/add_from.pyt   add_fromn   s
    R-   (   t
   __future__R    t   collectionsR   R   R   t   defaultdictt   listR   R   t   setR   R   R&   R-   R'   t   register_command(    (    (    s   renpy/add_from.pyt   <module>   s   	
			(	