ó
öÀ„\c           @  sÑ  d  Z  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 d d l m	 Z	 m
 Z
 d d l m Z d d l m Z d d l m Z d d l m Z d d	 l m Z d d
 l m Z d d l m Z d d l m Z d d l m Z m Z m Z d d l m  Z  e! rCd d l" m# Z# m$ Z$ d d l% m& Z& n  e j' e( ƒ Z) y e j* Z+ Wn e, k
 r{e j- Z+ n Xd Z. d e f d „  ƒ  YZ/ d e f d „  ƒ  YZ0 d e f d „  ƒ  YZ1 d „  Z2 d S(   sÌ   
    sphinx.builders.applehelp
    ~~~~~~~~~~~~~~~~~~~~~~~~~

    Build Apple help books.

    :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
    :license: BSD, see LICENSE for details.
iÿÿÿÿ(   t   print_functionN(   t   patht   environ(   t   StandaloneHTMLBuilder(   t   string_classes(   t   SphinxError(   t   __(   t   logging(   t   bold(   t
   copy_asset(   t   Matcher(   t   copyfilet	   ensuredirt   make_filename(   t
   htmlescape(   t   Anyt   Dict(   t   SphinxsŠ  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>%(title)s</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="robots" content="noindex" />
    <meta http-equiv="refresh" content="0;url=%(toc)s" />
  </head>
  <body>
  </body>
</html>
t   AppleHelpIndexerFailedc           B  s   e  Z e d  ƒ Z RS(   s   Help indexer failed(   t   __name__t
   __module__R   t   category(    (    (    s8   lib/python2.7/site-packages/sphinx/builders/applehelp.pyR   ?   s   t   AppleHelpCodeSigningFailedc           B  s   e  Z e d  ƒ Z RS(   s   Code signing failed(   R   R   R   R   (    (    (    s8   lib/python2.7/site-packages/sphinx/builders/applehelp.pyR   C   s   t   AppleHelpBuilderc           B  st   e  Z d  Z d Z e d ƒ Z e Z d d d d d d g Z e Z	 e
 Z e Z d	 „  Z d
 „  Z d „  Z d „  Z RS(   s{   
    Builder that outputs an Apple help book.  Requires Mac OS X as it relies
    on the ``hiutil`` command line tool.
    t	   applehelpsž   The help book is in %(outdir)s.
Note that won't be able to view it unless you put it in ~/Library/Documentation/Help or install it in your application bundle.s	   image/pngs	   image/gifs
   image/jpegs
   image/tiffs	   image/jp2s   image/svg+xmlc         C  sš   t  t |  ƒ j ƒ  d |  _ d |  _ |  j j d  k rL t t	 d ƒ ƒ ‚ n  t
 j |  j |  j j d ƒ |  _ t
 j |  j d d |  j j d ƒ |  _ d  S(   Ns   .htmlsB   You must set applehelp_bundle_id before building Apple Help outputs   .helpt   Contentst	   Resourcess   .lproj(   t   superR   t   initt
   out_suffixt   link_suffixt   configt   applehelp_bundle_idt   NoneR   R   R   t   joint   outdirt   applehelp_bundle_namet   bundle_patht   applehelp_locale(   t   self(    (    s8   lib/python2.7/site-packages/sphinx/builders/applehelp.pyR   `   s    			c         C  s=   t  t |  ƒ j ƒ  |  j j |  j ƒ |  j j |  j ƒ d  S(   N(   R   R   t   handle_finisht   finish_taskst   add_taskt   copy_localized_filest   build_helpbook(   R'   (    (    s8   lib/python2.7/site-packages/sphinx/builders/applehelp.pyR(   s   s    c         C  s«   t  j |  j |  j j d ƒ } |  j } t  j | ƒ r§ t j t	 t
 d ƒ ƒ d t ƒt |  j j d g ƒ } t | | | d |  j d |  j ƒt j t
 d ƒ ƒ n  d  S(   Ns   .lprojs   copying localized files... t   nonls   **/.*t   contextt   renderert   done(   R   R"   t   confdirR   R&   R#   t   isdirt   loggert   infoR   R   t   TrueR
   t   exclude_patternsR	   t   globalcontextt	   templates(   R'   t
   source_dirt
   target_dirt   excluded(    (    s8   lib/python2.7/site-packages/sphinx/builders/applehelp.pyR+   z   s    	c         C  sk  t  j |  j d ƒ } t  j | d ƒ } t  j | |  j j d ƒ } x! | | | g D] } t | ƒ qS W|  j j |  j } i |  j j d 6|  j j	 d 6d d 6d d	 6|  j j
 d
 6d d 6|  j j d 6d d 6d d 6|  j j d 6d d 6t d 6} |  j j d  k	 r t  j |  j j ƒ | d <n  |  j j d  k	 rU|  j j | d <|  j j | d <n  |  j j d  k	 rz|  j j | d <n  t j t t d ƒ ƒ d t ƒt t  j | d ƒ d ƒ  } t | | ƒ Wd  QXt j t d ƒ ƒ |  j j rŸt j t t d ƒ ƒ d t ƒyI t t  j |  j |  j j ƒ t  j | | d ƒ ƒ t j t d ƒ ƒ WqŸt k
 r›} t j t d  ƒ t  j |  j |  j j ƒ | ƒ | d =qŸXn  t j t t d! ƒ ƒ d t ƒt j t  j | d ƒ d" ƒ > } | j  t! i t" | d# t ƒd$ 6t" |  j j ƒ d% 6ƒ Wd  QXt j t d ƒ ƒ t j t t d& ƒ ƒ d t ƒ|  j j# d' t  j | d ƒ | g }	 |  j j$ d  k	 r”|	 j% d( ƒ n  |  j j& d  k	 rÃ|	 d) d* |  j j& g 7}	 n  |  j j' d  k	 rî|	 d+ |  j j' g 7}	 n  |  j j d  k	 r|	 d, |  j j g 7}	 n  |  j j( rvt j t d- ƒ ƒ t j t d. ƒ d/ j g  |	 D] }
 t) j* |
 ƒ ^ qTƒ ƒ n” yf t+ j, |	 d0 t+ j- d1 t+ j. ƒ} | j/ ƒ  d2 } | j0 d2 k rÈt1 | ƒ ‚ n t j t d ƒ ƒ Wn+ t2 k
 r	t1 t d3 ƒ |	 d2 ƒ ‚ n X|  j j3 rgt j t t d4 ƒ ƒ d t ƒ|  j j4 d+ |  j j3 d5 g }	 |	 |  j j5 7}	 |	 j% |  j ƒ |  j j( rÐt j t d- ƒ ƒ t j t d6 ƒ d/ j g  |	 D] }
 t) j* |
 ƒ ^ q®ƒ ƒ qgyf t+ j, |	 d0 t+ j- d1 t+ j. ƒ} | j/ ƒ  d2 } | j0 d2 k r"t6 | ƒ ‚ n t j t d ƒ ƒ Wqgt2 k
 rct6 t d3 ƒ |	 d2 ƒ ‚ qgXn  d  S(7   NR   R   s   .lprojt   CFBundleDevelopmentRegiont   CFBundleIdentifiers   6.0t   CFBundleInfoDictionaryVersiont   BNDLt   CFBundlePackageTypet   CFBundleShortVersionStringt   hbwrt   CFBundleSignaturet   CFBundleVersions   _access.htmlt   HPDBookAccessPaths   search.helpindext   HPDBookIndexPatht   HPDBookTitlet   3t   HPDBookTypet   HPDBookUsesExternalViewert   HPDBookIconPatht   HPDBookKBProductt   HPDBookKBURLt   HPDBookRemoteURLs   writing Info.plist... R-   s
   Info.plistt   wbR0   s   copying icon... s   cannot copy icon file %r: %ss   building access page...t   wt   quotet   toct   titles   generating help index... s   -Cfs   -as   -ms   %ss   -ss   -lt   skippings0   you will need to index this help book with:
  %st    t   stdoutt   stderri    s   Command not found: %ss   signing help book... s   -fs/   you will need to sign this help book with:
  %s(7   R   R"   R%   R   R&   R   t
   master_docR   t   applehelp_dev_regionR    t   releaset   applehelp_bundle_versiont   applehelp_titlet   Falset   applehelp_iconR!   t   basenamet   applehelp_kb_urlt   applehelp_kb_productt   applehelp_remote_urlR3   R4   R   R   R5   t   opent   write_plistR   t   srcdirt	   Exceptiont   warningt   codecst   writet   access_page_templateR   t   applehelp_indexer_patht   applehelp_index_anchorst   appendt   applehelp_min_term_lengtht   applehelp_stopwordst    applehelp_disable_external_toolst   pipesRQ   t
   subprocesst   Popent   PIPEt   STDOUTt   communicatet
   returncodeR   t   OSErrort   applehelp_codesign_identityt   applehelp_codesign_patht   applehelp_codesign_flagsR   (   R'   t   contents_dirt   resources_dirt   language_dirt   dRR   t
   info_plistt   ft   errt   argst   argt   pt   output(    (    s8   lib/python2.7/site-packages/sphinx/builders/applehelp.pyR,   ˆ   s¾    	
!		/			/	(   R   R   t   __doc__t   nameR   t   epilogR]   t
   copysourcet   supported_image_typest   add_permalinksR5   t   embeddedt   searchR   R(   R+   R,   (    (    (    s8   lib/python2.7/site-packages/sphinx/builders/applehelp.pyR   G   s   				c         C  s°  |  j  d ƒ |  j t ƒ |  j d d „  d ƒ |  j d d  d t ƒ |  j d d d ƒ |  j d d	 d ƒ |  j d
 d  d t ƒ |  j d d „  d ƒ |  j d d  d t ƒ |  j d d  d t ƒ |  j d t d t ƒ |  j d d  d t ƒ |  j d d „  d ƒ |  j d d „  d ƒ |  j d d „  d ƒ |  j d d „  d ƒ |  j d d „  d ƒ |  j d d d ƒ |  j d d d ƒ |  j d t d  ƒ i d  d! 6t d" 6t d# 6S($   Ns   sphinx.builders.htmlR$   c         S  s   t  |  j ƒ S(   N(   R   t   project(   R'   (    (    s8   lib/python2.7/site-packages/sphinx/builders/applehelp.pyt   <lambda>  s    R   R    RY   s   en-usR[   t   1R^   Ra   c         S  s   d t  |  j ƒ |  j f S(   Ns   %s-%s(   R   R   RZ   (   R'   (    (    s8   lib/python2.7/site-packages/sphinx/builders/applehelp.pyR   #  s    R`   Rb   Rl   Rn   Ro   c         S  s   |  j  p d S(   Nt   en(   t   language(   R'   (    (    s8   lib/python2.7/site-packages/sphinx/builders/applehelp.pyR   *  s    R&   c         S  s   |  j  p d S(   NR’   (   R“   (   R'   (    (    s8   lib/python2.7/site-packages/sphinx/builders/applehelp.pyR   +  s    R\   c         S  s   |  j  d S(   Ns    Help(   R   (   R'   (    (    s8   lib/python2.7/site-packages/sphinx/builders/applehelp.pyR   ,  s    Ry   c         S  s   t  j d d  ƒ S(   Nt   CODE_SIGN_IDENTITY(   R   t   getR!   (   R'   (    (    s8   lib/python2.7/site-packages/sphinx/builders/applehelp.pyR   .  s    R{   c         S  s   t  j t j d d ƒ ƒ S(   Nt   OTHER_CODE_SIGN_FLAGSt    (   t   shlext   splitR   R•   (   R'   (    (    s8   lib/python2.7/site-packages/sphinx/builders/applehelp.pyR   1  s    Rk   s   /usr/bin/hiutilRz   s   /usr/bin/codesignRp   t   builtint   versiont   parallel_read_safet   parallel_write_safe(   t   setup_extensiont   add_builderR   t   add_config_valueR!   R   R]   R5   (   t   app(    (    s8   lib/python2.7/site-packages/sphinx/builders/applehelp.pyt   setup  s@    					(3   R‡   t
   __future__R    Rh   Rq   t   plistlibR˜   Rr   t   osR   R   t   sphinx.builders.htmlR   t   sphinx.configR   t   sphinx.errorsR   t   sphinx.localeR   t   sphinx.utilR   t   sphinx.util.consoleR   t   sphinx.util.fileutilR	   t   sphinx.util.matchingR
   t   sphinx.util.osutilR   R   R   t   sphinx.util.pycompatR   R]   t   typingR   R   t   sphinx.applicationR   t	   getLoggerR   R3   t   dumpRd   t   AttributeErrort
   writePlistRj   R   R   R   R¢   (    (    (    s8   lib/python2.7/site-packages/sphinx/builders/applehelp.pyt   <module>
   s<   Ð