ó
£„öUc           @   sJ  d  d l  m Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z y d  d l Z Wn e k
 r{ d  d l	 Z n XyD d  d l
 m Z d  d l
 m Z d  d l
 m Z d  d l
 m Z Wn% e k
 rç Z e e e ƒ ƒ ‚ n Xd  d l m Z d  d l m Z d	 Z d
 „  Z d e j f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   iÿÿÿÿ(   t   logN(   t   apidoc(   t   application(   t   config(   t   setup_command(   t   git(   t   optionssi   %(heading)s
%(underline)s

.. automodule:: %(module)s
  :members:
  :undoc-members:
  :show-inheritance:
c         C   sW   xP | D]H } | j  d ƒ r | d k r t |  d | j d d ƒ | d  f <q q Wd  S(   Ns   .pys   __init__.pys   %s.%st   /t   .iýÿÿÿ(   t   endswitht   Truet   replace(   t   argt   dirnamet   filest   filename(    (    s0   /usr/lib/python2.7/dist-packages/pbr/builddoc.pyt   _find_modules<   s    t   LocalBuildDocc           B   s\   e  Z d  Z d d g Z d „  Z d
 d „ Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z RS(   t   build_sphinxt   htmlt   manc         C   sj   |  j  j d ƒ } d | k r> t j j | d d d ƒ } n d } t j j | ƒ sf t j | ƒ n  | S(   NR   t
   source_diri   t   apis   doc/source/api(   t   distributiont   get_option_dictt   ost   patht   joint   existst   makedirs(   t   selft   option_dictR   (    (    s0   /usr/lib/python2.7/dist-packages/pbr/builddoc.pyt   _get_source_dirH   s     c            s¤  t  j d t j j t j ƒ ƒ i  } |  j ƒ  } xV |  j j D]H } d | k r? x3 t j	 | ƒ D] \ } } } t
 | | | ƒ qa Wq? q? W‡  f d †  ‰ t ‡ f d †  | j ƒ  Dƒ ƒ } t j j | d ƒ }	 t |	 d ƒ ¾ }
 |
 j d ƒ x§ | D]Ÿ } t j j | d | ƒ } d	 | } d
 t | ƒ } t d | d | d | ƒ } t  j d | ƒ t | d ƒ  } | j t | ƒ Wd  QX|
 j d | ƒ q÷ WWd  QXd  S(   Ns   [pbr] Autodocumenting from %sR   c            s   t  ‡  f d †  ˆ Dƒ ƒ S(   Nc         3   s!   |  ] } t  j  ˆ  | ƒ Vq d  S(   N(   t   fnmatch(   t   .0t   pat(   t   module(    s0   /usr/lib/python2.7/dist-packages/pbr/builddoc.pys	   <genexpr>]   s   (   t   any(   R$   (   t   excluded_modules(   R$   s0   /usr/lib/python2.7/dist-packages/pbr/builddoc.pyt   include\   s    c         3   s!   |  ] } ˆ  | ƒ r | Vq d  S(   N(    (   R"   t   mod(   R'   (    s0   /usr/lib/python2.7/dist-packages/pbr/builddoc.pys	   <genexpr>`   s    s   autoindex.rstt   ws   .. toctree::
   :maxdepth: 1

s   %s.rsts   The :mod:`%s` Modulet   =R$   t   headingt	   underlines   [pbr] Generating %ss
      %s.rst
(   R    t   infoR   R   t   abspatht   curdirR    R   t   packagest   walkR   t   sortedt   keysR   t   opent   writet   lent   dictt   _rst_template(   R   R&   t   modulesR   t   pkgt   dirpatht   dirnamesR   t   module_listt   autoindex_filenamet	   autoindexR$   t   output_filenameR+   R,   t   valuest   output_file(    (   R&   R'   s0   /usr/lib/python2.7/dist-packages/pbr/builddoc.pyt   generate_autoindexR   s4    	"
		c         C   s<   |  j  ƒ  } d d d d d | g } t j | |  j ƒ d  S(   NR   R   s   -Ht   Moduless   -o(   R    R   t   maint   autodoc_tree_excludes(   R   R   t   cmd(    (    s0   /usr/lib/python2.7/dist-packages/pbr/builddoc.pyt   _sphinx_treeu   s    c   
      C   s!  |  j  s t j ƒ  } n	 t j } i  } |  j r@ |  j | d <n  |  j rY |  j | d <n  |  j rr |  j | d <n  t j	 |  j
 d i  g  ƒ } t j d ƒ j } t j | ƒ t j d ƒ k rÐ | j t j ƒ n
 | j ƒ  |  j d k rt | j ƒ d k rd  St j |  j |  j
 |  j |  j |  j | | d	 |  j d
 t ƒ} y | j d |  j ƒ Wn~ t k
 rØ} d d l m } t  | | j! ƒ rÒt j" j# d ƒ t j$ j# | j% d j& d d ƒ ƒ t j$ j# d ƒ qÙ‚  n X|  j' r| j j( | j j) } | j j* d ƒ }	 t+ j, | |	 ƒ n  d  S(   Nt   versiont   releaset   todays   conf.pyt   sphinxs   1.3.1R   i    t   freshenvt   warningiserrort	   force_alliÿÿÿÿ(   t   utilss   reST markup error:
t   asciit   backslashreplaces   
t   index(-   t   verboset	   cStringIOt   StringIOt   syst   stdoutRI   RJ   RK   R   t   Configt
   config_dirt   pkg_resourcest   get_distributiont   parse_versiont   init_valuest   warningst   warnt   builderR6   t	   man_pagesR   t   SphinxR   t   builder_target_dirt   doctree_dirt	   fresh_envt   Falset   buildt	   all_filest	   Exceptiont   docutilsRP   t
   isinstancet   SystemMessaget   stderR5   t   stderrt   argst   encodet
   link_indext
   master_doct
   out_suffixt   get_outfilenameR   t   symlink(
   R   t   status_streamt   confoverridest   sphinx_configt
   sphinx_vert   appt   errRP   t   srct   dst(    (    s0   /usr/lib/python2.7/dist-packages/pbr/builddoc.pyt   _sphinx_runz   sJ    					
$
	c         C   s[  |  j  j d ƒ } t j ƒ  rA t j d | ƒ t j d | ƒ n  t j | d d ƒ } t j | d d ƒ } t j	 d ƒ sÈ | r |  j
 ƒ  n  | rÈ |  j t | j d d  d	 g ƒ d
 j ƒ  ƒ ƒ qÈ n  xŒ |  j D] } | |  _ |  j ƒ  |  j  j ƒ  |  _ |  j  j ƒ  |  _ |  j  j ƒ  |  _ t j | d d ƒ rC|  j ƒ  qÒ t j j |  ƒ qÒ Wd  S(   Nt   pbrR   t   autodoc_tree_index_modulest   AUTODOC_TREE_INDEX_MODULESt   autodoc_index_modulest   AUTODOC_INDEX_MODULESt   SPHINX_DEBUGt   autodoc_exclude_modulest    i   t
   warnerrorst
   WARNERRORS(   R   R   R   t   _git_is_installedt   write_git_changelogt   generate_authorsR   t   get_boolean_optionR   t   getenvRH   RC   t   sett   gett   Nonet   splitt   buildersRa   t   finalize_optionst   get_namet   projectt   get_versionRI   RJ   R   R   t   BuildDoct   run(   R   R   t
   tree_indext
   auto_indexRa   (    (    s0   /usr/lib/python2.7/dist-packages/pbr/builddoc.pyR™   ¦   s8    					#	
	c         C   s    t  j j |  ƒ d g |  _ d  S(   Ns   setup.py(   R   R˜   t   initialize_optionsRF   (   R   (    (    s0   /usr/lib/python2.7/dist-packages/pbr/builddoc.pyRœ   È   s    c         C   sÒ   t  j j |  ƒ |  j j d ƒ } d | j d g  g ƒ d k rU | d d |  _ n  t |  j t ƒ r‰ |  j r‰ |  j j	 d ƒ |  _ n  d } |  j j d ƒ } | | k rÎ | | d |  _
 |  j | ƒ n  d  S(	   NR   s   command lineRa   i    i   t   ,RF   R€   (   R   R˜   R”   R   R   R   R“   Rl   t   listR’   RF   t   ensure_string_list(   R   R   t   opt(    (    s0   /usr/lib/python2.7/dist-packages/pbr/builddoc.pyR”   Ð   s    N(   t   __name__t
   __module__t   command_nameR“   R    R‘   RC   RH   R   R™   Rœ   R”   (    (    (    s0   /usr/lib/python2.7/dist-packages/pbr/builddoc.pyR   C   s   	
#		,	"	t   LocalBuildLatexc           B   s   e  Z d  g Z d Z RS(   t   latext   build_sphinx_latex(   R¡   R¢   R“   R£   (    (    (    s0   /usr/lib/python2.7/dist-packages/pbr/builddoc.pyR¤   ä   s   	(   t	   distutilsR    R!   R   R[   RW   R_   RU   t   ImportErrort   ioRL   R   R   R   R   Rj   t   et   strR€   R   R   R8   R   R˜   R   R¤   (    (    (    s0   /usr/lib/python2.7/dist-packages/pbr/builddoc.pyt   <module>   s,   
	¡