ó
ĊZc           @   sP   d  Z  d d l m Z d d l m Z d d l m Z d e f d     YZ d S(   s¸  Fix the name of modules

This module is useful when you want to rename many of the modules in
your project.  That can happen specially when you want to change their
naming style.

For instance::

  fixer = FixModuleNames(project)
  changes = fixer.get_changes(fixer=str.lower)
  project.do(changes)

Here it renames all modules and packages to use lower-cased chars.
You can tell it to use any other style by using the ``fixer``
argument.

i˙˙˙˙(   t
   taskhandle(   t   changestack(   t   renamet   FixModuleNamesc           B   sD   e  Z d    Z e j e j   d  Z d   Z d   Z	 d   Z
 RS(   c         C   s   | |  _  d  S(   N(   t   project(   t   selfR   (    (    s7   lib/python2.7/site-packages/rope/contrib/fixmodnames.pyt   __init__   s    c         C   sê   t  j |  j d  } | j d |  j |  d  } z x t rı xs |  j |  D]a } | j | j  t	 j
 |  j |  } | j | |  j |    } | j |  | j   PqP WPq: WWd | j d  | j   | j   X| j   S(   s   Fix module names

        `fixer` is a function that takes and returns a `str`.  Given
        the name of a module, it should return the fixed name.

        s   Fixing module namesi   Ns   Reverting to original state(   R   t   ChangeStackR   t   create_jobsett   _count_fixest   Truet   _tobe_fixedt   started_jobt   pathR   t   Renamet   get_changest   _namet   pusht   finished_jobt   pop_allt   merged(   R   t   fixert   task_handlet   stackt   jobsett   resourcet   renamert   changes(    (    s7   lib/python2.7/site-packages/rope/contrib/fixmodnames.pyR      s"    		
	
c         C   s   t  t |  j |    S(   N(   t   lent   listR   (   R   R   (    (    s7   lib/python2.7/site-packages/rope/contrib/fixmodnames.pyR	   8   s    c         c   sG   x@ |  j  j   D]/ } |  j |  } | | |  k r | Vq q Wd  S(   N(   R   t   get_python_filesR   (   R   R   R   t   modname(    (    s7   lib/python2.7/site-packages/rope/contrib/fixmodnames.pyR   ;   s    c         C   s8   | j  j d d  d } | d k r4 | j j  } n  | S(   Nt   .i   i    R   (   t   namet   rsplitt   parent(   R   R   R   (    (    s7   lib/python2.7/site-packages/rope/contrib/fixmodnames.pyR   A   s    (   t   __name__t
   __module__R   t   strt   lowerR    t   NullTaskHandleR   R	   R   R   (    (    (    s7   lib/python2.7/site-packages/rope/contrib/fixmodnames.pyR      s   			N(	   t   __doc__t	   rope.baseR    t   rope.contribR   t   rope.refactorR   t   objectR   (    (    (    s7   lib/python2.7/site-packages/rope/contrib/fixmodnames.pyt   <module>   s   