ó
ôŸ?`c           @   s‹  d  d l  Z  d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z e j	 d ƒ Z
 d „  Z e d d „ Z d „  Z e d d d „  ƒd	 „  ƒ Z d
 „  Z e d d e ƒd „  ƒ Z e d d e ƒd „  ƒ Z e  j d ƒ Z e d d e ƒd „  ƒ Z e d d e ƒd „  ƒ Z e d d e ƒd „  ƒ Z e d d e ƒd „  ƒ Z d „  Z e d k r‡e ƒ  n  d S(   iÿÿÿÿNt   srcdirc         C   s"   d j  |  |  d k r d n d ƒ S(   s7   Return 'N file(s)' with the proper plurality on 'file'.s	   {} file{}i   t   st    (   t   format(   t   count(    (    s0   /usr/lib64/python2.7/Tools/scripts/patchcheck.pyt   n_files_str   s    c            s   ‡  ‡ ‡ f d †  } | S(   s*   Decorator to output status info to stdout.c            s   ‡  ‡ ‡ ‡ f d †  } | S(   Nc             so   t  j j ˆ d ƒ t  j j ƒ  ˆ  |  | Ž  } ˆ rF ˆ rF d GHn% ˆ rZ ˆ | ƒ GHn | rf d n d GH| S(   Ns    ... t   donet   yest   NO(   t   syst   stdoutt   writet   flush(   t   argst   kwargst   result(   t   fxnt   infot   messaget   modal(    s0   /usr/lib64/python2.7/Tools/scripts/patchcheck.pyt   call_fxn   s    (    (   R   R   (   R   R   R   (   R   s0   /usr/lib64/python2.7/Tools/scripts/patchcheck.pyt   decorated_fxn   s    (    (   R   R   R   R   (    (   R   R   R   s0   /usr/lib64/python2.7/Tools/scripts/patchcheck.pyt   status   s    c          C   sx   d }  t  j |  j ƒ  d t  j d t  j ƒ} z) | j ƒ  \ } } | j d k oT | SWd | j j ƒ  | j j ƒ  Xd S(   s*   Check if there are any applied MQ patches.s   hg qappliedR
   t   stderri    N(	   t
   subprocesst   Popent   splitt   PIPEt   communicatet
   returncodeR
   t   closeR   (   t   cmdt   stt   bstdoutt   _(    (    s0   /usr/lib64/python2.7/Tools/scripts/patchcheck.pyt   mq_patches_applied'   s    	s6   Getting the list of files that have been added/changedR   c         C   s   t  t |  ƒ ƒ S(   N(   R   t   len(   t   x(    (    s0   /usr/lib64/python2.7/Tools/scripts/patchcheck.pyt   <lambda>6   s    c          C   s  t  j j t  j j t d ƒ ƒ rF d }  d } t ƒ  rt | d 7} qt n. t  j j d ƒ rg d }  d } n t j d ƒ t j	 | j
 ƒ  d	 t j ƒ} zg | j ƒ  |  d k rÑ g  | j D] } | j ƒ  j ƒ  ^ qµ Sd
 „  | j Dƒ } t d „  | Dƒ ƒ SWd | j j ƒ  Xd S(   s4   Get the list of changed or added files from the VCS.s   .hgt   hgs(   hg status --added --modified --no-statuss    --rev qparents   .svnt   svns7   svn status --quiet --non-interactive --ignore-externalss%   need a checkout to get modified filesR
   c         s   sA   |  ]7 } | d  d k r | j  ƒ  j ƒ  j d d ƒ d Vq d S(   i    t   AMi   iÿÿÿÿN(   t   decodet   rstript   rsplitt   None(   t   .0R%   (    (    s0   /usr/lib64/python2.7/Tools/scripts/patchcheck.pys	   <genexpr>J   s   c         s   s'   |  ] } t  j j | ƒ r | Vq d  S(   N(   t   ost   patht   isfile(   R.   R0   (    (    s0   /usr/lib64/python2.7/Tools/scripts/patchcheck.pys	   <genexpr>L   s    N(   R/   R0   t   isdirt   joint   SRCDIRR#   R	   t   exitR   R   R   R   t   waitR
   R*   R+   t   setR   (   t   vcsR   R    R%   t   output(    (    s0   /usr/lib64/python2.7/Tools/scripts/patchcheck.pyt   changed_files5   s$    !		
&c         C   sr   t  |  ƒ } | d k r" t | ƒ Sd j t | ƒ ƒ g } x$ |  D] } | j d j | ƒ ƒ qA Wd j | ƒ Sd  S(   Ni    s   {}:s     {}s   
(   R$   R   R   t   appendR3   (   t
   file_pathsR   t   linesR0   (    (    s0   /usr/lib64/python2.7/Tools/scripts/patchcheck.pyt   report_modified_filesQ   s    
s   Fixing whitespacec         C   s\   t  t _ g  } xF d „  |  Dƒ D]4 } t j t j j t | ƒ ƒ r  | j | ƒ q  q  W| S(   sA   Make sure that the whitespace for .py files have been normalized.c         s   s$   |  ] } | j  d  ƒ r | Vq d S(   s   .pyN(   t   endswith(   R.   R%   (    (    s0   /usr/lib64/python2.7/Tools/scripts/patchcheck.pys	   <genexpr>a   s    (	   t   Falset   reindentt
   makebackupt   checkR/   R0   R3   R4   R;   (   R<   t   fixedR0   (    (    s0   /usr/lib64/python2.7/Tools/scripts/patchcheck.pyt   normalize_whitespace\   s    	s   Fixing C file whitespacec         C   sƒ   g  } xv |  D]n } t  j j t | ƒ } t | d ƒ  } d | j ƒ  k rR w n  Wd QXt j | d d t ƒ| j	 | ƒ q W| S(   s   Report if any C files t   rs   	Ni   t   verbose(
   R/   R0   R3   R4   t   opent   readt   untabifyt   processR@   R;   (   R<   RD   R0   t   abspatht   f(    (    s0   /usr/lib64/python2.7/Tools/scripts/patchcheck.pyt   normalize_c_whitespaceg   s    s   \s+(\r?\n)$s   Fixing docs whitespacec   	      C   s÷   g  } xê |  D]â } t  j j t | ƒ } y¢ t | d ƒ  } | j ƒ  } Wd  QXg  | D] } t j d | ƒ ^ qV } | | k rÉ t j	 | | d ƒ t | d ƒ  } | j
 | ƒ Wd  QX| j | ƒ n  Wq t k
 rî } d | | f GHq Xq W| S(   Nt   rbs   \1s   .bakt   wbs   Cannot fix %s: %s(   R/   R0   R3   R4   RH   t	   readlinest   ws_ret   subt   shutilt   copyfilet
   writelinesR;   t	   Exception(	   R<   RD   R0   RL   RM   R=   t   linet	   new_linest   err(    (    s0   /usr/lib64/python2.7/Tools/scripts/patchcheck.pyt   normalize_docs_whitespacew   s    %s   Docs modifiedR   c         C   s
   t  |  ƒ S(   s9   Report if any file in the Doc directory has been changed.(   t   bool(   R<   (    (    s0   /usr/lib64/python2.7/Tools/scripts/patchcheck.pyt   docs_modifiedŠ   s    s   Misc/ACKS updatedc         C   s
   d |  k S(   s$   Check if Misc/ACKS has been changed.s	   Misc/ACKS(    (   R<   (    (    s0   /usr/lib64/python2.7/Tools/scripts/patchcheck.pyt   credit_given   s    s   Misc/NEWS updatedc         C   s
   d |  k S(   s$   Check if Misc/NEWS has been changed.s	   Misc/NEWS(    (   R<   (    (    s0   /usr/lib64/python2.7/Tools/scripts/patchcheck.pyt   reported_news–   s    c          C   s  t  ƒ  }  g  |  D] } | j d ƒ r | ^ q } g  |  D] } | j d
 ƒ r8 | ^ q8 } g  |  D] } | j d ƒ r` | ^ q` } d d h t |  ƒ @} t | ƒ t | ƒ t | ƒ t | ƒ t | ƒ t	 | ƒ | sß | rþ | rë d n d } Hd	 | GHn  d  S(   Ns   .pys   .cs   .ht   Docs	   Misc/ACKSs	   Misc/NEWSs    and check for refleaks?t   ?s   Did you run the test suite(   s   .cs   .h(
   R:   R?   t
   startswithR7   RE   RN   R[   R]   R^   R_   (   R<   t   fnt   python_filest   c_filest	   doc_filest   special_filest   end(    (    s0   /usr/lib64/python2.7/Tools/scripts/patchcheck.pyt   mainœ   s    	(((





t   __main__(   t   reR	   RT   t   os.pathR/   R   t	   sysconfigRA   RJ   t   get_config_varR4   R   R@   R-   R   R#   R:   R>   RE   RN   t   compileRR   R[   t   TrueR]   R^   R_   Ri   t   __name__(    (    (    s0   /usr/lib64/python2.7/Tools/scripts/patchcheck.pyt   <module>   s0   					