ó
ƒÕUc           @   sk   d  d l  Z  d  d l Z d  d l Z d „  Z d „  Z d „  Z d „  Z d „  Z e d k rg e ƒ  n  d S(   iÿÿÿÿNc           C   s	   d GHd  S(   Nu3   
    help: del_comment.py <filename | dirname>
    (    (    (    (    s   UnComment.pyt   usage   s    c   
      C   sM  t  j j |  ƒ s d |  GHt St  j j |  ƒ r: d GHt St  j j |  ƒ d } y, t  j |  t  j ƒ s{ t  j |  d ƒ n  Wn d |  GHn Xt	 |  d ƒ } |  d } t	 | d ƒ } y[d	 } | j
 ƒ  } xB| rt j | d
 ƒ } t j | d ƒ } | d k r| d k s5| d k rn| d k rn| | k  rn| |  j ƒ  }	 t |	 ƒ d k r| j |	 d ƒ qn“| d k r†| d k sª| d k rß| d k rß| | k rß| |  j ƒ  }	 t |	 ƒ d k rÜ| j |	 ƒ n  t j | d ƒ } | d k r@| | d j ƒ  }	 t |	 ƒ d k r0| j |	 ƒ n  | j d ƒ q| j d ƒ | j
 ƒ  } xr | rÍt j | d ƒ } | d k r¾| | d j ƒ  }	 t |	 ƒ d k rº| j |	 d ƒ n  Pn  | j
 ƒ  } q\W| sd GHqn" t | ƒ d k r| j | ƒ n  | j
 ƒ  } qÏ WWn  d GH| j ƒ  | j ƒ  n X| j ƒ  | j ƒ  t S(   Ns   Error: file - %s doesn't exist.s   Error: file - %s is a link.i   i´  s#   Error: you can not chang %s's mode.t   rs
   .nocommentt   wi    s   /*s   //iÿÿÿÿs   
s   */i   s   Match /*...*/ errors   Error: unexcept error.(   t   ost   patht   existst   Falset   islinkt   splitextt   accesst   W_OKt   chmodt   opent   readlinet   stringt   findt   stript   lent   writet   closet   True(
   t   srct   filetypet   inputft   outputfilenamet   outputft   rFlagt   linet   fmt   dst   sub(    (    s   UnComment.pyt	   deal_file
   sr    	
	<<	


c         C   s•   t  j j |  ƒ s% d t |  ƒ GHt St  j |  ƒ } xZ | D]R } |  d | } t  j j | ƒ rn t | ƒ q; t  j j | ƒ r; t	 | ƒ q; q; Wt
 S(   Ns   Error: dir - %s is not exist.t   /(   R   R   R   t   sR   t   listdirt   isdirt   deal_dirt   isfileR   R   (   R   t	   filelistst   eachfile(    (    s   UnComment.pyR$   W   s    c         C   sŠ   |  } t  j j | ƒ r3 t  j j | ƒ } t } n6 t  j j | ƒ r` t  j j | ƒ } t } n	 d |  GH| r| t | ƒ n
 t | ƒ d  S(   Ns   File not found: (	   R   R   R#   t   abspathR   R%   R   R$   R   (   t   strSrcR   t   diret   dirFlagt   fl(    (    s   UnComment.pyt   Func_DelCommente   s    			c          C   s¾   t  t j ƒ d k  r, t ƒ  t j d ƒ n  t j d }  t j j |  ƒ rf t j j |  ƒ } t	 } n2 t j j
 |  ƒ r“ t j j |  ƒ } t } n d GH| r« t | ƒ n
 t | ƒ d GHd  S(   Ni   i   s   File input errors   Successful handle file.(   R   t   syst   argvR    t   exitR   R   R#   R(   R   R%   R   R$   R   (   R   R*   R+   R,   (    (    s   UnComment.pyt   mainz   s    		
t   __main__(	   R   R.   R   R    R   R$   R-   R1   t   __name__(    (    (    s   UnComment.pyt   <module>   s   $		M			