o
    Mi*                     @  s  d Z ddlm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mZmZ ddlmZ ddl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 ddlmZ ddlmZm Z  errddlm!Z! ddl"m#Z# ej$dd dkrddl%m&Z&m'Z' nddlm&Z&m'Z' dZ(dZ)e*e+e,Z-e.e-dZ/ee0dZ1e2e0Z3G dd deZ4G dd deZ5G dd deZ6d$d"d#Z7dS )%zBuild Apple help books.    )annotationsN)environpath)Path)PIPESTDOUTCalledProcessError)TYPE_CHECKING)StandaloneHTMLBuilder)SphinxError)get_translation)logging)
copy_assetcopy_asset_file)Matcher)	ensuredirmake_filename)Any)Sphinx   )      )SkipProgressMessageprogress_messagez2.0.0)r   r   r   	templatesconsolec                   @     e Zd ZedZdS )AppleHelpIndexerFailedzHelp indexer failedN__name__
__module____qualname____category r$   r$   T/home/ubuntu/.local/lib/python3.10/site-packages/sphinxcontrib/applehelp/__init__.pyr   -       r   c                   @  r   )AppleHelpCodeSigningFailedzCode signing failedNr   r$   r$   r$   r%   r'   1   r&   r'   c                      s   e Zd ZdZdZedZdZg dZdZ	dZ
dZd$ fd	d
Zd$ fddZeedd$ddZd$ddZeedd%ddZd&ddZeedd'ddZeedd'dd Zeed!d$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.
    	applehelpzThe 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.F)z	image/pngz	image/gifz
image/jpegz
image/tiffz	image/jp2zimage/svg+xmlTreturnNonec                   sr   t    d| _d| _| jjd u rtd}t|t	| j
| jjd | _t| j
t| jdd| jjd | _
d S )Nz.htmlzBYou must set applehelp_bundle_id before building Apple Help outputz.helpContents	Resources.lproj)superinit
out_suffixlink_suffixconfigapplehelp_bundle_idr"   r   r   joinoutdirapplehelp_bundle_namebundle_pathtyper   applehelp_locale)selfmsg	__class__r$   r%   r0   N   s   


zAppleHelpBuilder.initc                   s*   t    | j| j | j| j d S N)r/   handle_finishfinish_tasksadd_taskcopy_localized_filesbuild_helpbookr;   r=   r$   r%   r@   a   s   
zAppleHelpBuilder.handle_finishzcopying localized filesc                 C  sV   t | j| jjd }| j}t |r)t| jjdg }t	|||| j
| jd d S d S )Nr.   z**/.*)contextrenderer)r   r5   confdirr3   r:   r6   isdirr   exclude_patternsr   globalcontextr   )r;   
source_dir
target_direxcludedr$   r$   r%   rC   g   s   

z%AppleHelpBuilder.copy_localized_filesc                 C  sv   t | jd}t |d}t || jjd }t| | | | | | | | 	| | jj
r9|   d S d S )Nr,   r-   r.   )r   r5   r8   r3   r:   r   build_info_plistcopy_applehelp_iconbuild_access_pagebuild_helpindexapplehelp_codesign_identitydo_codesign)r;   contents_dirresources_dirlanguage_dirr$   r$   r%   rD   q   s   




zAppleHelpBuilder.build_helpbookzwriting Info.plistrU   strc                 C  s   | j j| j jdd| j jd| j jdd| j jddd}| j jd	ur(t| j j|d
< | j j	d	ur:| j j
|d< | j j	|d< | j jd	urF| j j|d< tt|dd}t|| W d	   d	S 1 saw   Y  d	S )zConstruct the Info.plist file.z6.0BNDLhbwrz_access.htmlsearch.helpindex3F)CFBundleDevelopmentRegionCFBundleIdentifierCFBundleInfoDictionaryVersionCFBundlePackageTypeCFBundleShortVersionStringCFBundleSignatureCFBundleVersionHPDBookAccessPathHPDBookIndexPathHPDBookTitleHPDBookTypeHPDBookUsesExternalViewerNHPDBookIconPathHPDBookKBProductHPDBookKBURLHPDBookRemoteURLz
Info.plistwb)r3   applehelp_dev_regionr4   releaseapplehelp_bundle_versionapplehelp_titleapplehelp_iconr   basenameapplehelp_kb_urlapplehelp_kb_productapplehelp_remote_urlopenr5   plistlibdump)r;   rU   
info_plistfr$   r$   r%   rO      s.   "z!AppleHelpBuilder.build_info_plistrV   c              
   C  s   | j jrJz)ttd t| j| j j}t|| W d   W dS 1 s&w   Y  W dS  tyI } zt	
td|| W Y d}~dS d}~ww dS )z"Copy the icon, if one is supplied.zcopying icon... Nzcannot copy icon file %r: %s)r3   rr   r   r"   r   r5   srcdirr   	Exceptionloggerwarning)r;   rV   rr   errr$   r$   r%   rP      s   & z$AppleHelpBuilder.copy_applehelp_iconzbuilding access pagerW   c                 C  s0   | j j| j | j jd}tttd|| dS )zBuild the access page.)toctitlez_access.html_tN)r3   
master_docr1   rq   r   r   r5   template_dir)r;   rW   rF   r$   r$   r%   rQ      s   z"AppleHelpBuilder.build_access_pagezgenerating help indexc              
   C  s  | j jdt|d|g}| j jdur|d | j jdur&|d| j j g7 }| j jdur4|d| j jg7 }| j jdurB|d| j jg7 }| j j	rUt
tdd	d
d |D ztj|ttdd W dS  tyz } ztd|d  }t||d}~w ty } zt|j|d}~ww )zGenerate the help index.z-Cfr[   Nz-az-m-sz-lz0you will need to index this help book with:
  %s c                 S     g | ]}t |qS r$   shlexquote.0argr$   r$   r%   
<listcomp>       z4AppleHelpBuilder.build_helpindex.<locals>.<listcomp>TstdoutstderrcheckCommand not found: %sr   )r3   applehelp_indexer_pathr   r5   applehelp_index_anchorsappendapplehelp_min_term_lengthapplehelp_stopwordsr:    applehelp_disable_external_toolsr   r"   
subprocessrunr   r   OSErrorr   r   r   )r;   rW   argsr   r<   r$   r$   r%   rR      s6   


z AppleHelpBuilder.build_helpindexzsigning help bookc              
   C  s   | j jd| j jdg}|| j j7 }|| j | j jr)ttdd	dd |D zt
j|ttdd W dS  tyN } ztd	|d
  }t||d}~w ty_ } zt|j|d}~ww )z(If we've been asked to, sign the bundle.r   z-fz/you will need to sign this help book with:
  %sr   c                 S  r   r$   r   r   r$   r$   r%   r      r   z0AppleHelpBuilder.do_codesign.<locals>.<listcomp>Tr   r   r   N)r3   applehelp_codesign_pathrS   applehelp_codesign_flagsr   r8   r   r   r"   r5   r   r   r   r   r   r'   r   r   )r;   r   r   r<   r$   r$   r%   rT      s(   
zAppleHelpBuilder.do_codesign)r*   r+   )rU   rX   r*   r+   )rV   rX   r*   r+   )rW   rX   r*   r+   )r   r    r!   __doc__namer"   epilog
copysourcesupported_image_typesadd_permalinksembeddedsearchr0   r@   r   rC   rD   rO   rP   rQ   rR   rT   __classcell__r$   r$   r=   r%   r(   5   s.    

	




!r(   appr   r*   dict[str, Any]c                 C  sn  |  d | d | t | tttd | 	ddd d | 	dd dt
g | 	d	d
d | 	ddd | 	dd dt
g | 	ddd d | 	dd dt
g | 	dd dt
g | 	dddt
g | 	dd dt
g | 	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 td$d$d%S )&Nz5.0zsphinx.builders.htmllocalesr7   c                 S  s
   t | jS r?   )r   projectrE   r$   r$   r%   <lambda>      
 zsetup.<locals>.<lambda>r)   r4   rn   zen-usrp   1rr   ru   c                 S  s   t | j d| j S )N-)r   r   ro   rE   r$   r$   r%   r      r   rt   rv   r   Fr   r   c                 S  
   | j pdS NenlanguagerE   r$   r$   r%   r     r   r:   c                 S  r   r   r   rE   r$   r$   r%   r     r   rq   c                 S  s
   | j d S )Nz Help)r   rE   r$   r$   r%   r     r   rS   c                 S  s   t dd S )NCODE_SIGN_IDENTITY)r   getrE   r$   r$   r%   r     s    r   c                 S  s   t tddS )NOTHER_CODE_SIGN_FLAGS )r   splitr   r   rE   r$   r$   r%   r   
  s    r   z/usr/bin/hiutilr   z/usr/bin/codesignr   T)versionparallel_read_safeparallel_write_safe)require_sphinxsetup_extensionadd_builderr(   add_message_catalogr   r   r5   package_diradd_config_valuerX   __version__)r   r$   r$   r%   setup   sN   


r   )r   r   r*   r   )8r   
__future__r   rx   r   r   osr   r   pathlibr   r   r   r   typingr	   sphinxsphinx.builders.htmlr
   sphinx.errorsr   sphinx.localer   sphinx.utilr   sphinx.util.fileutilr   r   sphinx.util.matchingr   sphinx.util.osutilr   r   r   sphinx.applicationr   version_infosphinx.util.displayr   r   r   __version_info__abspathdirname__file__r   r5   r   r   r"   	getLoggerr~   r   r'   r(   r   r$   r$   r$   r%   <module>   sD    

 ;