ó
†Å•Zc           @   sÙ   d  Z  d d l Z d d l Z d d l Z d d l m Z d d l m Z d d l m	 Z	 d d „ Z d „  Z e j ƒ  d „  ƒ Z d	 „  Z d
 „  Z e	 j ƒ  d „ Z d e d „ Z d d „ Z d „  Z d „  Z d S(   s2   A few useful functions for using rope as a libraryiÿÿÿÿN(   t   pyobjectsdef(   t   utils(   t
   taskhandlec         C   s”   t  |  | ƒ } | d k rE t j j j | ƒ } t j j j ƒ  }  n  | d k r^ |  j | ƒ S| d k rw |  j | ƒ S| d k r |  j	 | ƒ Sd S(   sL  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.

    t   filet   folderN(
   t   path_relative_to_project_roott   Nonet   ropet   baset   projectt	   _realpatht   get_no_projectt   get_resourcet   get_filet
   get_folder(   R	   t   patht   typet   project_path(    (    s1   lib/python2.7/site-packages/rope/base/libutils.pyt   path_to_resource   s    c         C   s   t  |  j | ƒ S(   N(   t   relativet   address(   R	   R   (    (    s1   lib/python2.7/site-packages/rope/base/libutils.pyR   #   s    c         C   s‡   t  j j j |  ƒ j t j j d ƒ }  t  j j j | ƒ j t j j d ƒ } | |  k r^ d S| j |  d ƒ rƒ | t	 |  ƒ d Sd  S(   Nt   /t    i   (
   R   R   R	   R
   t   replacet   osR   t   sept
   startswitht   len(   t   rootR   (    (    s1   lib/python2.7/site-packages/rope/base/libutils.pyR   &   s    ''c         C   sr   t  |  | ƒ } | d k r d Sx$ t |  j ƒ D] } | j | ƒ q/ W|  j j rn t j j j	 |  | | ƒ n  d S(   s|   Report that the contents of file at `path` was changed

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

    N(
   R   R   t   listt	   observerst   resource_changedt   pycoret   automatic_soaR   R   t   perform_soa_on_changed_scopes(   R	   R   t   old_contentt   resourcet   observer(    (    s1   lib/python2.7/site-packages/rope/base/libutils.pyt   report_change0   s    c         C   s   |  j  j | ƒ d S(   sw   Perform static object analysis on a python file in the project

    Note that this might be really time consuming.
    N(   R    t   analyze_module(   R	   R$   (    (    s1   lib/python2.7/site-packages/rope/base/libutils.pyR'   @   s    c         C   s`   |  j  ƒ  } | j d t | ƒ ƒ } x5 | D]- } | j | j ƒ t |  | ƒ | j ƒ  q+ Wd S(   sz   Perform static object analysis on all python files in the project

    Note that this might be really time consuming.
    s   Analyzing ModulesN(   t   get_python_filest   create_jobsetR   t   started_jobR   R'   t   finished_job(   R	   t   task_handlet	   resourcest   job_setR$   (    (    s1   lib/python2.7/site-packages/rope/base/libutils.pyt   analyze_modulesH   s    c         C   s   t  j |  j | | d | ƒS(   sÝ   Returns 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.

    t   force_errors(   R    t   PyModuleR    (   R	   t   codeR$   R0   (    (    s1   lib/python2.7/site-packages/rope/base/libutils.pyt   get_string_moduleU   s    c         C   s   t  |  | | ƒ j ƒ  S(   s+   Returns a `Scope` object for the given code(   R3   t	   get_scope(   R	   R2   R$   (    (    s1   lib/python2.7/site-packages/rope/base/libutils.pyt   get_string_scopea   s    c         C   s   |  j  j | ƒ S(   N(   R    t   is_python_file(   R	   R$   (    (    s1   lib/python2.7/site-packages/rope/base/libutils.pyR6   f   s    c         C   s¤   |  j  ƒ  r! |  j } |  j } n@ |  j d k rK |  j j } |  j j } n |  j d  } |  j } x< | | j k rŸ | j d ƒ rŸ | j d | } | j } qd W| S(   Ns   __init__.pyiýÿÿÿt   .(   t	   is_foldert   namet   parentt	   has_child(   R$   t   module_namet   source_folder(    (    s1   lib/python2.7/site-packages/rope/base/libutils.pyt   modnamej   s    		(   t   __doc__t   os.pathR   t   rope.base.projectR   t   rope.base.pycoret	   rope.baseR    R   R   R   R   R   t
   deprecatedR   R&   R'   t   NullTaskHandleR/   t   FalseR3   R5   R6   R>   (    (    (    s1   lib/python2.7/site-packages/rope/base/libutils.pyt   <module>   s    	
			