ó
„¾^Yc           @   st   d  Z  d d l Z d d l Z d d l Z d d l m Z d Z d „  Z d „  Z	 d „  Z
 e d	 „ Z d
 „  Z d S(   ss   Module containing the main mecurial hook interface and helpers.

.. autofunction:: hook
.. autofunction:: install

iÿÿÿÿN(   t
   exceptionst   hookt   installc   	      K   sÂ   d d l  m } t d t ƒ } | d	 k r? d GHt t ƒ ‚ n  t | ƒ } | j d d d t ƒ} t	 t
 | | ƒ ƒ } | j ƒ  } | j | ƒ t | j _ | j ƒ  | j ƒ  | r¾ | j Sd S(
   st  Execute Flake8 on the repository provided by Mercurial.

    To understand the parameters read more of the Mercurial documentation
    around Hooks: https://www.mercurial-scm.org/wiki/Hook.

    We avoid using the ``ui`` attribute because it can cause issues with
    the GPL license tha Mercurial is under. We don't import it, but we
    avoid using it all the same.
    iÿÿÿÿ(   t   applicationt   create_if_missings-   Cannot locate your root mercurial repository.t   flake8t   strictt   fallbacki    N(   t   flake8.mainR   t	   find_hgrct   Falset   Nonet
   SystemExitt   Truet   configparser_fort   gett   listt   get_filenames_fromt   Applicationt
   initializet   optionst   _running_from_vcst
   run_checkst   reportt   result_count(	   t   uit   repot   kwargsR   t   hgrct   hgconfigR   t	   filenamest   app(    (    s5   /tmp/pip-build-EndXZ2/flake8/flake8/main/mercurial.pyR      s     


c          C   sR  t  d t ƒ }  |  d k r t St |  ƒ } | j d ƒ sJ | j d ƒ n  | j d d ƒ rƒ t j	 d |  d | j
 d d ƒ ƒ ‚ n  | j d d ƒ r¼ t j d |  d | j
 d d ƒ ƒ ‚ n  | j d d d ƒ | j d d d ƒ | j d ƒ s| j d ƒ n  | j d d	 ƒ s)| j d d	 t ƒ n  t |  d
 ƒ  } | j | ƒ Wd QXt S(   s.   Ensure that the mercurial hooks are installed.R   t   hookst   committ   patht   valuet   qrefreshs!   python:flake8.main.mercurial.hookR   R   t   wN(   R	   R   R   R
   R   t   has_sectiont   add_sectiont
   has_optiont   exct    MercurialCommitHookAlreadyExistsR   t"   MercurialQRefreshHookAlreadyExistst   sett   opent   write(   R   R   t   fd(    (    s5   /tmp/pip-build-EndXZ2/flake8/flake8/main/mercurial.pyR   0   s.    		c   	      c   sÃ   t  ƒ  } | d } x© t |  | t |  ƒ ƒ D] } x… |  | j ƒ  D]s } t j j |  j | ƒ } | | k } t j j | ƒ } | sD | r“ qD n  | j	 | ƒ | j
 d ƒ rD | VqD qD Wq- Wd  S(   Nt   nodes   .py(   R,   t   ranget   lent   filest   osR"   t   joint   roott   existst   addt   endswith(	   t
   repositoryR   t   seen_filenamesR0   t   revisiont   filenamet   full_filenamet   have_seen_filenamet   filename_does_not_exist(    (    s5   /tmp/pip-build-EndXZ2/flake8/flake8/main/mercurial.pyR   V   s    	
 c         C   sÖ   t  j d d g d t  j d t  j ƒ} | j ƒ  \ } } t t | d d  ƒ ƒ rc | j d ƒ } n  t j	 j
 | ƒ sy d  St j	 j t j	 j | d d ƒ ƒ } t j	 j | ƒ sÒ |  rË t | d	 ƒ j ƒ  qÒ d  Sn  | S(
   Nt   hgR6   t   stdoutt   stderrt   decodes   utf-8s   .hgR   R%   (   t
   subprocesst   Popent   PIPEt   communicatet   callablet   getattrR   RD   R4   R"   t   isdirt   abspathR5   R7   R-   t   close(   R   R6   t   hg_directoryt   _R   (    (    s5   /tmp/pip-build-EndXZ2/flake8/flake8/main/mercurial.pyR	   f   s     		c         C   s#   t  j d d  ƒ } | j |  ƒ | S(   Nt   interpolation(   t   configparsert   ConfigParserR   t   read(   R"   t   parser(    (    s5   /tmp/pip-build-EndXZ2/flake8/flake8/main/mercurial.pyR   €   s    (   s   hooks   install(   t   __doc__RQ   R4   RE   R   R    R)   t   __all__R   R   R   R
   R	   R   (    (    (    s5   /tmp/pip-build-EndXZ2/flake8/flake8/main/mercurial.pyt   <module>   s   	 	&	