B
    öÀ„\ý.  ã               @   s8  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 !e"¡Z#y
ej$Z%W n e&k
rö   ej'Z%Y nX dZ(G dd„ deƒZ)G dd„ deƒZ*G dd„ deƒZ+dd„ Z,dS )zÌ
    sphinx.builders.applehelp
    ~~~~~~~~~~~~~~~~~~~~~~~~~

    Build Apple help books.

    :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
    :license: BSD, see LICENSE for details.
é    )Úprint_functionN)ÚpathÚenviron)ÚStandaloneHTMLBuilder)Ústring_classes)ÚSphinxError)Ú__)Úlogging)Úbold)Ú
copy_asset)ÚMatcher)ÚcopyfileÚ	ensuredirÚmake_filename)Ú
htmlescapeaŠ  <!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>
c               @   s   e Zd ZedƒZdS )ÚAppleHelpIndexerFailedzHelp indexer failedN)Ú__name__Ú
__module__Ú__qualname__r   Úcategory© r   r   ú8lib/python3.7/site-packages/sphinx/builders/applehelp.pyr   ?   s   r   c               @   s   e Zd ZedƒZdS )ÚAppleHelpCodeSigningFailedzCode signing failedN)r   r   r   r   r   r   r   r   r   r   C   s   r   c                   sh   e Zd ZdZdZedƒZdZddddd	d
gZdZ	dZ
dZ‡ fdd„Z‡ fdd„Zdd„ Zdd„ Z‡  ZS )ÚAppleHelpBuilderz{
    Builder that outputs an Apple help book.  Requires Mac OS X as it relies
    on the ``hiutil`` command line tool.
    Ú	applehelpzž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.Fz	image/pngz	image/gifz
image/jpegz
image/tiffz	image/jp2zimage/svg+xmlTc                sj   t t| ƒ ¡  d| _d| _| jjd kr2ttdƒƒ‚t	 
| j| jjd ¡| _t	 
| jdd| jjd ¡| _d S )Nz.htmlzBYou must set applehelp_bundle_id before building Apple Help outputz.helpÚContentsÚ	Resourcesz.lproj)Úsuperr   ÚinitÚ
out_suffixZlink_suffixÚconfigÚapplehelp_bundle_idr   r   r   ÚjoinÚoutdirÚapplehelp_bundle_nameÚbundle_pathÚapplehelp_locale)Úself)Ú	__class__r   r   r   `   s    
zAppleHelpBuilder.initc                s.   t t| ƒ ¡  | j | j¡ | j | j¡ d S )N)r   r   Úhandle_finishZfinish_tasksZadd_taskÚcopy_localized_filesÚbuild_helpbook)r'   )r(   r   r   r)   s   s    zAppleHelpBuilder.handle_finishc             C   sv   t  | j| jjd ¡}| j}t  |¡rrtjt	t
dƒƒdd t| jjdg ƒ}t|||| j| jd t t
dƒ¡ d S )Nz.lprojzcopying localized files... T)Únonlz**/.*)ÚcontextZrendererÚdone)r   r"   Zconfdirr    r&   r#   ÚisdirÚloggerÚinfor
   r   r   Zexclude_patternsr   ZglobalcontextZ	templates)r'   Z
source_dirZ
target_dirZexcludedr   r   r   r*   z   s    
z%AppleHelpBuilder.copy_localized_filesc             C   sŠ  t  | jd¡}t  |d¡}t  || jjd ¡}x|||gD ]}t|ƒ q:W | jj| j }| jj| jj	dd| jj
d| jjdd| jjd	d
dœ}| jjd k	r¨t  | jj¡|d< | jjd k	rÌ| jj|d< | jj|d< | jjd k	rä| jj|d< tjttdƒƒdd tt  |d¡dƒ}t||ƒ W d Q R X t tdƒ¡ | jjrÒtjttdƒƒdd y6tt  | j| jj¡t  ||d ¡ƒ t tdƒ¡ W nJ tk
rÐ } z*t tdƒt  | j| jj¡|¡ |d= W d d }~X Y nX tjttdƒƒdd t t  |d¡d¡*}| tt|ddt| jjƒdœ ¡ W d Q R X t tdƒ¡ tjttdƒƒdd | jj dt  |d¡|g}	| jj!d k	r€|	 "d¡ | jj#d k	r¢|	dd | jj# g7 }	| jj$d k	rÀ|	d!| jj$g7 }	| jjd k	rÞ|	d"| jjg7 }	| jj%rt td#ƒ¡ t td$ƒd% d&d'„ |	D ƒ¡¡ ntyHt&j'|	t&j(t&j)d(}
|
 *¡ d) }|
j+d)krPt,|ƒ‚nt tdƒ¡ W n* t-k
rŠ   t,td*ƒ|	d)  ƒ‚Y nX | jj.r†tjttd+ƒƒdd | jj/d!| jj.d,g}	|	| jj07 }	|	 "| j¡ | jj%rt td#ƒ¡ t td-ƒd% d.d'„ |	D ƒ¡¡ ntyHt&j'|	t&j(t&j)d(}
|
 *¡ d) }|
j+d)krJt1|ƒ‚nt tdƒ¡ W n* t-k
r„   t1td*ƒ|	d)  ƒ‚Y nX d S )/Nr   r   z.lprojz6.0ZBNDLZhbwrz_access.htmlzsearch.helpindexÚ3F)ZCFBundleDevelopmentRegionZCFBundleIdentifierZCFBundleInfoDictionaryVersionZCFBundlePackageTypeZCFBundleShortVersionStringZCFBundleSignatureZCFBundleVersionZHPDBookAccessPathZHPDBookIndexPathZHPDBookTitleZHPDBookTypeZHPDBookUsesExternalViewerZHPDBookIconPathZHPDBookKBProductZHPDBookKBURLZHPDBookRemoteURLzwriting Info.plist... T)r,   z
Info.plistÚwbr.   zcopying icon... zcannot copy icon file %r: %szbuilding access page...Úw)Úquote)ÚtocÚtitlezgenerating help index... z-Cfz-az-mz%sz-sz-lZskippingz0you will need to index this help book with:
  %sú c             S   s   g | ]}t  |¡‘qS r   )Úpipesr5   )Ú.0Úargr   r   r   ú
<listcomp>å   s    z3AppleHelpBuilder.build_helpbook.<locals>.<listcomp>)ÚstdoutÚstderrr   zCommand not found: %szsigning help book... z-fz/you will need to sign this help book with:
  %sc             S   s   g | ]}t  |¡‘qS r   )r9   r5   )r:   r;   r   r   r   r<     s    )2r   r"   r%   r    r&   r   Z
master_docr   Úapplehelp_dev_regionr!   ÚreleaseÚapplehelp_bundle_versionÚapplehelp_titleÚapplehelp_iconÚbasenameÚapplehelp_kb_urlÚapplehelp_kb_productÚapplehelp_remote_urlr0   r1   r
   r   ÚopenÚwrite_plistr   ZsrcdirÚ	ExceptionZwarningÚcodecsÚwriteÚaccess_page_templater   Úapplehelp_indexer_pathÚapplehelp_index_anchorsÚappendÚapplehelp_min_term_lengthÚapplehelp_stopwordsÚ applehelp_disable_external_toolsÚ
subprocessÚPopenÚPIPEZSTDOUTZcommunicateÚ
returncoder   ÚOSErrorÚapplehelp_codesign_identityÚapplehelp_codesign_pathÚapplehelp_codesign_flagsr   )r'   Zcontents_dirZresources_dirZlanguage_dirÚdr6   Z
info_plistÚfÚerrÚargsÚpÚoutputr   r   r   r+   ˆ   s¼    













zAppleHelpBuilder.build_helpbook)r   r   r   Ú__doc__Únamer   ZepilogZ
copysourceZsupported_image_typesZadd_permalinksZembeddedÚsearchr   r)   r*   r+   Ú__classcell__r   r   )r(   r   r   G   s   
r   c             C   sD  |   d¡ |  t¡ |  ddd„ d¡ |  dd dt¡ |  ddd¡ |  d	d
d¡ |  dd dt¡ |  ddd„ d¡ |  dd dt¡ |  dd dt¡ |  dddt¡ |  dd dt¡ |  ddd„ d¡ |  ddd„ d¡ |  ddd„ d¡ |  ddd„ d¡ |  ddd„ d¡ |  ddd¡ |  dd d¡ |  d!dd ¡ d"d#d#d$œS )%Nzsphinx.builders.htmlr$   c             S   s
   t | jƒS )N)r   Úproject)r'   r   r   r   Ú<lambda>  s    zsetup.<locals>.<lambda>r   r!   r?   zen-usrA   Ú1rC   rF   c             S   s   dt | jƒ| jf S )Nz%s-%s)r   rf   r@   )r'   r   r   r   rg   #  s    rE   rG   rO   FrQ   rR   c             S   s
   | j pdS )NÚen)Úlanguage)r'   r   r   r   rg   *  s    r&   c             S   s
   | j pdS )Nri   )rj   )r'   r   r   r   rg   +  s    rB   c             S   s
   | j d S )Nz Help)rf   )r'   r   r   r   rg   ,  s    rY   c             S   s   t  dd ¡S )NZCODE_SIGN_IDENTITY)r   Úget)r'   r   r   r   rg   .  s    r[   c             S   s   t  t dd¡¡S )NZOTHER_CODE_SIGN_FLAGSÚ )ÚshlexÚsplitr   rk   )r'   r   r   r   rg   1  s    rN   z/usr/bin/hiutilrZ   z/usr/bin/codesignrS   ZbuiltinT)ÚversionZparallel_read_safeZparallel_write_safe)Zsetup_extensionZadd_builderr   Zadd_config_valuer   )Zappr   r   r   Úsetup  s>    

rp   )-rb   Z
__future__r   rK   r9   Zplistlibrm   rT   Úosr   r   Zsphinx.builders.htmlr   Zsphinx.configr   Zsphinx.errorsr   Zsphinx.localer   Zsphinx.utilr	   Zsphinx.util.consoler
   Zsphinx.util.fileutilr   Zsphinx.util.matchingr   Zsphinx.util.osutilr   r   r   Zsphinx.util.pycompatr   Z	getLoggerr   r0   ÚdumprI   ÚAttributeErrorZ
writePlistrM   r   r   r   rp   r   r   r   r   Ú<module>
   s8   

 Q