
    Æe                         d Z ddlZddlZddlZddlmZmZm	Z	 ddZ
d Z e	j                         d        Zd Zd Zej                   fd	Zdd
ZddZd Zd Zy)z2A few useful functions for using rope as a library    N)pyobjectsdef
taskhandleutilsc                 @   t        | |      }|Qt        j                  j                  j	                  |      }t        j                  j                  j                         } || j                  |      S |dk(  r| j                  |      S |dk(  r| j                  |      S y)aL  Get the resource at path

    You only need to specify `type` if `path` does not exist.  It can
    be either 'file' or 'folder'.  If the type is `None` it is assumed
    that the resource already exists.

    Note that this function uses `Project.get_resource()`,
    `Project.get_file()`, and `Project.get_folder()` methods.

    Nfilefolder)	path_relative_to_project_rootropebaseproject	_realpathget_no_projectget_resourceget_file
get_folder)r   pathtypeproject_paths       4/usr/lib/python3/dist-packages/rope/base/libutils.pypath_to_resourcer   	   s     1$?Lyy((2248))##224|##L11v~--x!!,//    c                 .    t        | j                  |      S N)relativeaddress)r   r   s     r   r	   r	   !   s    GOOT**r   c                    t         j                  j                  j                  |       j	                  t
        j                  j                  d      } t         j                  j                  j                  |      j	                  t
        j                  j                  d      }|| k(  ry|j                  | dz         r|t        |       dz   d  S y )N/    )
r
   r   r   r   replaceosr   sep
startswithlen)rootr   s     r   r   r   %   s    99&&t,44RWW[[#FD99&&t,44RWW[[#FDt|tcz"CIMO$$ #r   c                     t        | |      }|yt        | j                        D ]  }|j                  |        | j                  j
                  r,t        j                  j                  j                  | ||       yy)z|Report that the contents of file at `path` was changed

    The new contents of file is retrieved by reading the file.

    N)	r   list	observersresource_changedpycoreautomatic_soar
   r   perform_soa_on_changed_scopes)r   r   old_contentresourceobservers        r   report_changer0   /   so      .H**+ ,!!(+,~~##		66w+V $r   c                 :    | j                   j                  |       y)zwPerform static object analysis on a python file in the project

    Note that this might be really time consuming.
    N)r*   analyze_moduler   r.   s     r   r2   r2   >   s    
 NN!!(+r   c                     | j                         }|j                  dt        |            }|D ]9  }|j                  |j                         t        | |       |j                          ; y)zzPerform static object analysis on all python files in the project

    Note that this might be really time consuming.
    zAnalyzing ModulesN)get_python_filescreate_jobsetr$   started_jobr   r2   finished_job)r   task_handle	resourcesjob_setr.   s        r   analyze_modulesr<   F   s`    
 ((*I''(;S^LG HMM*w)r   c                 H    t        j                  | j                  |||      S )zReturns a `PyObject` object for the given code

    If `force_errors` is `True`, `exceptions.ModuleSyntaxError` is
    raised if module has syntax errors.  This overrides
    ``ignore_syntax_errors`` project config.

    )force_errors)r   PyModuler*   )r   coder.   r>   s       r   get_string_modulerA   S   s$       h\ r   c                 8    t        | ||      j                         S )z+Returns a `Scope` object for the given code)rA   	get_scope)r   r@   r.   s      r   get_string_scoperD   `   s    WdH5??AAr   c                 8    | j                   j                  |      S r   )r*   is_python_filer3   s     r   rF   rF   e   s    >>((22r   c                    | j                         r| j                  }| j                  }nW| j                  dk(  r-| j                  j                  }| j                  j                  }n| j                  d d }| j                  }||j                  k7  rP|j                  d      r?|j                  dz   |z   }|j                  }||j                  k7  r|j                  d      r?|S )Nz__init__.py.)	is_foldernameparent	has_child)r.   module_namesource_folders      r   modnamerP   i   s    mm 	-	'oo** ..mmCR( 
=//
/M4K4K5 $((3.<%,,	 =//
/M4K4K5 r   r   )NF)__doc__os.pathr!   rope.base.projectr
   rope.base.pycore	rope.baser   r   r   r   r	   
deprecatedr   r0   r2   DEFAULT_TASK_HANDLEr<   rA   rD   rF   rP    r   r   <module>rY      sp    8    5 50+ % %W, *4)G)G 

B
3r   