ó
mÜJ]c           @` s˜   d  Z  d d l m Z m Z m Z m Z d d l Z e j e ƒ Z	 d d l
 m Z d d l m Z d d l m Z d Z d
 „  Z d „  Z d „  Z d S(   u¼   Generate a ``sitemap.txt`` to aid with search indexing.

``sitemap.txt`` is a plain text list of all the pages in the docs site.
Each URL is listed on a line in the text file. It is machine readable
and used by search engines to know what pages are available for indexing.

All that is required to generate the sitemap is to list this module
``bokeh.sphinxext.sitemap`` in the list of extensions in the Sphinx
configuration file ``conf.py``.

i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsN(   t   join(   t   SphinxError(   t   status_iteratoru   build_finishedu   html_page_contextu   setupc         C` s8   | d } | d } |  j  j | | d | d ƒ d S(   uB    Collect page names for the sitemap as HTML pages are built.

    u   SITEMAP_BASE_URLu   versionu   /u   .htmlN(   t   sitemap_linkst   add(   t   appt   pagenamet   templatenamet   contextt   doctreet   sitet   version(    (    s<   lib/python2.7/site-packages/bokeh/sphinxext/bokeh_sitemap.pyt   html_page_context:   s    

c         C` s§   t  |  j d ƒ } t t |  j ƒ d d t |  j ƒ |  j ƒ } y> t | d ƒ ) } x | D] } | j d | ƒ q[ WWd QXWn# t	 k
 r¢ } t
 d | ƒ ‚ n Xd S(   uE    Generate a ``sitemap.txt`` from the collected HTML page links.

    u   sitemap.txtu   adding links to sitemap... u   brownu   wu   %s
Nu$   cannot write sitemap.txt, reason: %s(   R   t   outdirR   t   sortedR   t   lent	   verbosityt   opent   writet   OSErrorR   (   R	   t	   exceptiont   filenamet
   links_itert   ft   linkt   e(    (    s<   lib/python2.7/site-packages/bokeh/sphinxext/bokeh_sitemap.pyt   build_finishedB   s    c         C` s0   |  j  d t ƒ |  j  d t ƒ t ƒ  |  _ d S(   u+    Required Sphinx extension setup function. u   html-page-contextu   build-finishedN(   t   connectR   R   t   setR   (   R	   (    (    s<   lib/python2.7/site-packages/bokeh/sphinxext/bokeh_sitemap.pyt   setupU   s    (   u   build_finishedu   html_page_contextu   setup(   t   __doc__t
   __future__R    R   R   R   t   loggingt	   getLoggert   __name__t   logt   os.pathR   t   sphinx.errorsR   t   sphinx.utilR   t   __all__R   R   R!   (    (    (    s<   lib/python2.7/site-packages/bokeh/sphinxext/bokeh_sitemap.pyt   <module>   s   "	  		