ó
†Å•Zc           @   s$  d  Z  d d l Z d d l Z d d l Z d d l j j j Z y e Wn e	 k
 r` e
 Z n Xd „  Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d	 „  ƒ  YZ d
 e f d „  ƒ  YZ d e f d „  ƒ  YZ d d „ Z d d „ Z d d „ Z d „  Z d „  Z d „  Z d „  Z d S(   s  Project file system commands.

This modules implements file system operations used by rope.  Different
version control systems can be supported by implementing the interface
provided by `FileSystemCommands` class.  See `SubversionCommands` and
`MercurialCommands` for example.

iÿÿÿÿNc         C   s‹   t  j |  ƒ } i t d 6t d 6t d 6t d 6t d 6} xI | D]A } | | k r? y | | |  ƒ SWq€ t t f k
 r| q€ Xq? q? Wt ƒ  S(   Ns   .hgs   .svns   .gitt   _svnt   _darcs(	   t   ost   listdirt   MercurialCommandst   SubversionCommandst   GITCommandst   DarcsCommandst   ImportErrort   OSErrort   FileSystemCommands(   t   roott   dirlistt   commandst   key(    (    s3   lib/python2.7/site-packages/rope/base/fscommands.pyt   create_fscommands   s    

R
   c           B   s5   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   s   t  | d ƒ j ƒ  d  S(   Nt   w(   t   opent   close(   t   selft   path(    (    s3   lib/python2.7/site-packages/rope/base/fscommands.pyt   create_file&   s    c         C   s   t  j | ƒ d  S(   N(   R   t   mkdir(   R   R   (    (    s3   lib/python2.7/site-packages/rope/base/fscommands.pyt   create_folder)   s    c         C   s   t  j | | ƒ d  S(   N(   t   shutilt   move(   R   R   t   new_location(    (    s3   lib/python2.7/site-packages/rope/base/fscommands.pyR   ,   s    c         C   s3   t  j j | ƒ r" t  j | ƒ n t j | ƒ d  S(   N(   R   R   t   isfilet   removeR   t   rmtree(   R   R   (    (    s3   lib/python2.7/site-packages/rope/base/fscommands.pyR   /   s    c         C   s2   t  | d ƒ } z | j | ƒ Wd  | j ƒ  Xd  S(   Nt   wb(   R   t   writeR   (   R   R   t   datat   file_(    (    s3   lib/python2.7/site-packages/rope/base/fscommands.pyR   5   s    (   t   __name__t
   __module__R   R   R   R   R   (    (    (    s3   lib/python2.7/site-packages/rope/base/fscommands.pyR
   $   s
   				R   c           B   s>   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         G   s+   t  ƒ  |  _ d d  l } | j ƒ  |  _ d  S(   Niÿÿÿÿ(   R
   t   normal_actionst   pysvnt   Clientt   client(   R   t   argsR%   (    (    s3   lib/python2.7/site-packages/rope/base/fscommands.pyt   __init__?   s    c         C   s*   |  j  j | ƒ |  j j | d t ƒd  S(   Nt   force(   R$   R   R'   t   addt   True(   R   R   (    (    s3   lib/python2.7/site-packages/rope/base/fscommands.pyR   D   s    c         C   s*   |  j  j | ƒ |  j j | d t ƒd  S(   NR*   (   R$   R   R'   R+   R,   (   R   R   (    (    s3   lib/python2.7/site-packages/rope/base/fscommands.pyR   H   s    c         C   s   |  j  j | | d t ƒd  S(   NR*   (   R'   R   R,   (   R   R   R   (    (    s3   lib/python2.7/site-packages/rope/base/fscommands.pyR   L   s    c         C   s   |  j  j | d t ƒd  S(   NR*   (   R'   R   R,   (   R   R   (    (    s3   lib/python2.7/site-packages/rope/base/fscommands.pyR   O   s    c         C   s   |  j  j | | ƒ d  S(   N(   R$   R   (   R   R   R    (    (    s3   lib/python2.7/site-packages/rope/base/fscommands.pyR   R   s    (   R"   R#   R)   R   R   R   R   R   (    (    (    s3   lib/python2.7/site-packages/rope/base/fscommands.pyR   =   s   					R   c           B   sG   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   s  |  j  ƒ  |  _ t ƒ  |  _ y= |  j j j d t d t d t d t d t d t ƒ |  _ Wn  |  j j j ƒ  |  _ |  j j d d d ƒ |  j j d d d ƒ |  j j d d d ƒ |  j j d d d ƒ |  j j d d d ƒ |  j j d d d	 ƒ n X|  j j j |  j | ƒ |  _	 d  S(
   Nt   verboset   debugt   quiett   interactivet	   tracebackt   report_untrustedt   uit   not   yes(
   t   _import_mercurialt   hgR
   R$   R3   t   FalseR,   t	   setconfigt
   repositoryt   repo(   R   R   (    (    s3   lib/python2.7/site-packages/rope/base/fscommands.pyR)   X   s    c         C   s(   d d  l  } d d  l } d d  l } | S(   Niÿÿÿÿ(   t   mercurial.commandst   mercurial.hgt   mercurial.ui(   R   t	   mercurial(    (    s3   lib/python2.7/site-packages/rope/base/fscommands.pyR6   j   s    c         C   s3   |  j  j | ƒ |  j j j |  j |  j | ƒ d  S(   N(   R$   R   R7   R   R+   R3   R;   (   R   R   (    (    s3   lib/python2.7/site-packages/rope/base/fscommands.pyR   p   s    c         C   s   |  j  j | ƒ d  S(   N(   R$   R   (   R   R   (    (    s3   lib/python2.7/site-packages/rope/base/fscommands.pyR   t   s    c         C   s,   |  j  j j |  j |  j | | d t ƒd  S(   Nt   after(   R7   R   t   renameR3   R;   R8   (   R   R   R   (    (    s3   lib/python2.7/site-packages/rope/base/fscommands.pyR   w   s    c         C   s#   |  j  j j |  j |  j | ƒ d  S(   N(   R7   R   R   R3   R;   (   R   R   (    (    s3   lib/python2.7/site-packages/rope/base/fscommands.pyR   {   s    c         C   s   |  j  j | | ƒ d  S(   N(   R$   R   (   R   R   R    (    (    s3   lib/python2.7/site-packages/rope/base/fscommands.pyR   ~   s    (	   R"   R#   R)   R6   R   R   R   R   R   (    (    (    s3   lib/python2.7/site-packages/rope/base/fscommands.pyR   V   s   						R   c           B   sP   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 RS(   c         C   s)   | |  _  |  j d g ƒ t ƒ  |  _ d  S(   Nt   version(   R   t   _doR
   R$   (   R   R   (    (    s3   lib/python2.7/site-packages/rope/base/fscommands.pyR)   „   s    	c         C   s0   |  j  j | ƒ |  j d |  j | ƒ g ƒ d  S(   NR+   (   R$   R   RC   t   _in_dir(   R   R   (    (    s3   lib/python2.7/site-packages/rope/base/fscommands.pyR   ‰   s    c         C   s   |  j  j | ƒ d  S(   N(   R$   R   (   R   R   (    (    s3   lib/python2.7/site-packages/rope/base/fscommands.pyR      s    c         C   s,   |  j  d |  j | ƒ |  j | ƒ g ƒ d  S(   Nt   mv(   RC   RD   (   R   R   R   (    (    s3   lib/python2.7/site-packages/rope/base/fscommands.pyR      s    c         C   s    |  j  d |  j | ƒ g ƒ d  S(   Nt   rm(   RC   RD   (   R   R   (    (    s3   lib/python2.7/site-packages/rope/base/fscommands.pyR   “   s    c         C   s   |  j  j | | ƒ d  S(   N(   R$   R   (   R   R   R    (    (    s3   lib/python2.7/site-packages/rope/base/fscommands.pyR   –   s    c         C   s   t  d g | d |  j ƒd  S(   Nt   gitt   cwd(   t   _executeR   (   R   R(   (    (    s3   lib/python2.7/site-packages/rope/base/fscommands.pyRC   š   s    c         C   s.   | j  |  j ƒ r' | t |  j ƒ d S|  j S(   Ni   (   t
   startswithR   t   len(   R   R   (    (    s3   lib/python2.7/site-packages/rope/base/fscommands.pyRD      s    (
   R"   R#   R)   R   R   R   R   R   RC   RD   (    (    (    s3   lib/python2.7/site-packages/rope/base/fscommands.pyR   ‚   s   							R   c           B   sG   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   s   | |  _  t ƒ  |  _ d  S(   N(   R   R
   R$   (   R   R   (    (    s3   lib/python2.7/site-packages/rope/base/fscommands.pyR)   ¥   s    	c         C   s'   |  j  j | ƒ |  j d | g ƒ d  S(   NR+   (   R$   R   RC   (   R   R   (    (    s3   lib/python2.7/site-packages/rope/base/fscommands.pyR   ©   s    c         C   s'   |  j  j | ƒ |  j d | g ƒ d  S(   NR+   (   R$   R   RC   (   R   R   (    (    s3   lib/python2.7/site-packages/rope/base/fscommands.pyR   ­   s    c         C   s   |  j  d | | g ƒ d  S(   NRE   (   RC   (   R   R   R   (    (    s3   lib/python2.7/site-packages/rope/base/fscommands.pyR   ±   s    c         C   s   |  j  j | ƒ d  S(   N(   R$   R   (   R   R   (    (    s3   lib/python2.7/site-packages/rope/base/fscommands.pyR   ´   s    c         C   s   |  j  j | | ƒ d  S(   N(   R$   R   (   R   R   R    (    (    s3   lib/python2.7/site-packages/rope/base/fscommands.pyR   ·   s    c         C   s   t  d g | d |  j ƒd  S(   Nt   darcsRH   (   RI   R   (   R   R(   (    (    s3   lib/python2.7/site-packages/rope/base/fscommands.pyRC   º   s    (	   R"   R#   R)   R   R   R   R   R   RC   (    (    (    s3   lib/python2.7/site-packages/rope/base/fscommands.pyR   £   s   						c         C   s/   t  j |  d | d t  j ƒ} | j ƒ  | j S(   NRH   t   stdout(   t
   subprocesst   Popent   PIPEt   waitt
   returncode(   R(   RH   t   process(    (    s3   lib/python2.7/site-packages/rope/base/fscommands.pyRI   ¾   s    
c         C   sw   t  |  t ƒ s |  S| d  k r. t |  ƒ } n  | d  k	 rG |  j | ƒ Sy |  j ƒ  SWn t k
 rr |  j d ƒ SXd  S(   Ns   utf-8(   t
   isinstancet   unicodet   Nonet   read_str_codingt   encodet   UnicodeEncodeError(   t   contentst   encoding(    (    s3   lib/python2.7/site-packages/rope/base/fscommands.pyt   unicode_to_file_dataÄ   s    c         C   s@   t  |  | ƒ } d | k r< | j d d ƒ j d d ƒ } n  | S(   Ns   s   
s   
(   t   _decode_datat   replace(   R    R[   t   result(    (    s3   lib/python2.7/site-packages/rope/base/fscommands.pyt   file_data_to_unicodeÑ   s    !c         C   s|   t  |  t ƒ r |  S| d  k r. t |  ƒ } n  | d  k rC d } n  y |  j | ƒ SWn! t t f k
 rw |  j d ƒ SXd  S(   Ns   utf-8t   latin1(   RT   RU   RV   RW   t   decodet   UnicodeErrort   LookupError(   R    R[   (    (    s3   lib/python2.7/site-packages/rope/base/fscommands.pyR]   Ø   s    	c         C   s~   t  |  d ƒ } d } g  } xC t r` | j d ƒ } | s= Pn  | | j d ƒ 7} | j | ƒ q W| j ƒ  t d j | ƒ ƒ S(   Nt   bi    i
   s   
t    (   R   R,   t   readt   countt   appendR   t   _find_codingt   join(   R   t   fileRh   R_   t   current(    (    s3   lib/python2.7/site-packages/rope/base/fscommands.pyt   read_file_codingê   s    	
c         C   s|   t  |  ƒ t k r d } n d } y- |  j | ƒ d } |  j | | ƒ d } Wn t k
 rm t |  ƒ } n Xt |  |  ƒ S(   Ns   
i   (   t   typet   bytest   indext
   ValueErrorRK   Rj   (   t   sourcet   newlinet   firstt   second(    (    s3   lib/python2.7/site-packages/rope/base/fscommands.pyRW   ø   s    	c         C   sV  t  |  t j ƒ r$ |  j d ƒ }  n  d } t j r9 t n d „  } yü |  j | ƒ t | ƒ } |  | d k rr d  S| d 7} x6 | t |  ƒ k  r´ | |  | ƒ j ƒ  r´ | d 7} q W| } xM | t |  ƒ k  r
|  | } | | ƒ j	 ƒ  rý | d k rý Pn  | d 7} q¾ W|  | | !} t  | t
 ƒ r9| j d ƒ } n  | SWn t k
 rQn Xd  S(   Ns   utf-8t   codingc         S   s   |  S(   N(    (   t   x(    (    s3   lib/python2.7/site-packages/rope/base/fscommands.pyt   <lambda>  Rf   s   =:i   s   -_(   RT   t   pycompatt   strRX   t   PY3t   chrRq   RK   t   isspacet   isalnumRp   Rb   Rr   (   t   textRw   t   to_chrt   startt   endt   cR_   (    (    s3   lib/python2.7/site-packages/rope/base/fscommands.pyRj   	  s.    
+
(   t   __doc__R   R   RN   t   rope.base.utils.pycompatt   baset   utilsRz   RU   t	   NameErrorR{   R   t   objectR
   R   R   R   R   RV   RI   R\   R`   R]   Rn   RW   Rj   (    (    (    s3   lib/python2.7/site-packages/rope/base/fscommands.pyt   <module>   s*   
	,!			