
    Ri*                        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rddlm!Z! ddl"m#Z# ejH                  dd dk\  r	ddl%m&Z&m'Z' nddlm&Z&m'Z' dZ(dZ) ejT                   ejV                  e,            Z- ej\                  e-d      Z/ ee0d      Z1 ejd                  e0      Z3 G d de      Z4 G d de      Z5 G d de      Z6ddZ7y) 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y)AppleHelpIndexerFailedzHelp indexer failedN__name__
__module____qualname____category     X/home/agent/.friday_env/lib/python3.12/site-packages/sphinxcontrib/applehelp/__init__.pyr   r   -       '(Hr&   r   c                      e Zd Z ed      Zy)AppleHelpCodeSigningFailedzCode signing failedNr   r%   r&   r'   r*   r*   1   r(   r&   r*   c                  >    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Zd fdZ e ed	            dd
       ZddZ e ed            dd       ZddZ e ed            dd       Z e ed            dd       Z e ed            dd       Z x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+xmlTc           	        t         |           d| _        d| _        | j                  j
                  t        d      }t        |      t        j                  | j                  | j                  j                  dz         | _         t        | j                        t        | j                  dd| j                  j                  dz               | _
        y )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__s     r'   r3   zAppleHelpBuilder.initN   s    !";;**2 9 :Cc""99T[[$++2S2SV]2]^'d4;;'KK((83	)
 r&   c                    t         |           | j                  j                  | j                         | j                  j                  | j
                         y N)r2   handle_finishfinish_tasksadd_taskcopy_localized_filesbuild_helpbook)r>   r@   s    r'   rC   zAppleHelpBuilder.handle_finisha   sB    ""4#<#<=""4#6#67r&   zcopying localized filesc                D   t        j                  | j                  | j                  j                  dz         }| j
                  }t        j                  |      rHt        | j                  j                  dgz         }t        |||| j                  | j                         y y )Nr1   z**/.*)contextrenderer)r   r8   confdirr6   r=   r9   isdirr   exclude_patternsr   globalcontextr   )r>   
source_dir
target_direxcludeds       r'   rF   z%AppleHelpBuilder.copy_localized_filesg   sx    YYt||T[[-I-IH-TU
[[
::j!t{{;;wiGHHz:x#11DNNL "r&   c                   t        j                  | j                  d      }t        j                  |d      }t        j                  || j                  j                  dz         }t        |       | j                  |       | j                  |       | j                  |       | j                  |       | j                  j                  r| j                          y y )Nr/   r0   r1   )r   r8   r;   r6   r=   r   build_info_plistcopy_applehelp_iconbuild_access_pagebuild_helpindexapplehelp_codesign_identitydo_codesign)r>   contents_dirresources_dirlanguage_dirs       r'   rG   zAppleHelpBuilder.build_helpbookq   s    yy!1!1:>		,<yy!%!=!=!HJ,l+  /|,\*;;22 3r&   zwriting Info.plistc                   | j                   j                  | j                   j                  dd| j                   j                  d| j                   j                  dd| j                   j
                  ddd}| j                   j                  ,t        j                  | j                   j                        |d
<   | j                   j                  2| j                   j                  |d<   | j                   j                  |d<   | j                   j                  | j                   j                  |d<   t        t        j                  |d      d      5 }t        j                  ||       d	d	d	       y	# 1 sw Y   y	xY w)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)r6   applehelp_dev_regionr7   releaseapplehelp_bundle_versionapplehelp_titleapplehelp_iconr   basenameapplehelp_kb_urlapplehelp_kb_productapplehelp_remote_urlopenr8   plistlibdump)r>   rY   
info_plistfs       r'   rS   z!AppleHelpBuilder.build_info_plist   s)    *.)I)I"&++"A"A-2#)*.++*=*=!'#{{CC!/ 2 KK77).

 ;;%%1,0MM$++:T:T,UJ();;''3-1[[-M-MJ)*)-)E)EJ~&;;++7-1[[-M-MJ)*$))L,7> 	)!MM*a(	) 	) 	)s   E--E6c                r   | j                   j                  r_	 t        t        d            5  t	        j
                  | j                  | j                   j                        }t        ||       ddd       yy# 1 sw Y   yxY w# t        $ r*}t        j                  t        d      |       Y d}~yd}~ww xY w)z"Copy the icon, if one is supplied.zcopying icon... Nzcannot copy icon file %r: %s)r6   rv   r   r#   r   r8   srcdirr   	Exceptionloggerwarning)r>   rZ   rv   errs       r'   rT   z$AppleHelpBuilder.copy_applehelp_icon   s    ;;%%X%b);&<= C%)YYt{{DKK<V<V%WN#NMBC C &C C  Xr"@A>SVWWXs5   B AA7-B 7B <B  B 	B6 B11B6zbuilding access pagec                    | j                   j                  | j                  z   | j                   j                  d}t	        t        j                  t        d      ||       y)zBuild the access page.)toctitlez_access.html_tN)r6   
master_docr4   ru   r   r   r8   template_dir)r>   r[   rI   s      r'   rU   z"AppleHelpBuilder.build_access_page   sI     ;;))DOO;[[00
 			,0@A<QXYr&   zgenerating help indexc                z   | j                   j                  dt        j                  |d      |g}| j                   j                  |j                  d       | j                   j                  |d| j                   j                   gz  }| j                   j                  |d| j                   j                  gz  }| j                   j                  |d| j                   j                  gz  }| j                   j                  rEt        t        d      d	j                  |D cg c]  }t        j                  |       c}            	 t        j                  |t         t"        d
       yc c}w # t$        $ r"}t        d      |d   z  }t'        |      |d}~wt(        $ r}t'        |j*                        |d}~ww xY w)zGenerate the help index.z-Cfr_   Nz-az-m-sz-lz0you will need to index this help book with:
  %s TstdoutstderrcheckCommand not found: %sr   )r6   applehelp_indexer_pathr   r8   applehelp_index_anchorsappendapplehelp_min_term_lengthapplehelp_stopwordsr=    applehelp_disable_external_toolsr   r#   shlexquote
subprocessrunr   r   OSErrorr   r	   r   )r>   r[   argsargr   r?   s         r'   rV   z AppleHelpBuilder.build_helpindex   sz    KK..IIl$67	
 ;;..:KK;;00<TdkkCCDFFD;;**6T4;;::;;D;;''3T4;;7788D;;77%b)\&]&)hhD/QSC0@/Q&RT TBtDtL 0R  ;01DG;,S1s:% B,SZZ8cABs*   E(!E- -	F:6FF:F55F:zsigning help bookc                l   | j                   j                  d| j                   j                  dg}|| j                   j                  z  }|j	                  | j
                         | j                   j                  rEt        t        d      dj                  |D cg c]  }t        j                  |       c}            	 t        j                  |t        t        d       y	c c}w # t         $ r"}t        d      |d   z  }t#        |      |d	}~wt$        $ r}t#        |j&                        |d	}~ww xY w)
z(If we've been asked to, sign the bundle.r   z-fz/you will need to sign this help book with:
  %sr   Tr   r   r   N)r6   applehelp_codesign_pathrW   applehelp_codesign_flagsr   r;   r   r   r#   r8   r   r   r   r   r   r   r   r*   r	   r   )r>   r   r   r   r?   s        r'   rX   zAppleHelpBuilder.do_codesign   s    KK//$++99
 	444D$$%;;77%b)[&\&)hhD/QSC0@/Q&RT TFtDtL 0R  ?01DG;053>% F0<#EFs*   C!?!C& &	D3/DD3D..D3)returnNone)rY   strr   r   )rZ   r   r   r   )r[   r   r   r   )r    r!   r"   __doc__namer#   epilog
copysourcesupported_image_typesadd_permalinksembeddedsearchr3   rC   r   rF   rG   rS   rT   rU   rV   rX   __classcell__)r@   s   @r'   r,   r,   5   s     D  F JI N H F&8 b234L 5L b-./) 0)<	X b/01Z 2Z b012B 3BB b,-.F /Fr&   r,   c                   | j                  d       | j                  d       | j                  t               | j	                  t
        t        j                  t        d             | j                  dd d       | j                  dd dt        g       | j                  dd	d       | j                  d
dd       | j                  dd dt        g       | j                  dd d       | j                  dd dt        g       | j                  dd dt        g       | j                  dddt        g       | j                  dd dt        g       | 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"dd       t        d#d#d$S )%Nz5.0zsphinx.builders.htmllocalesr:   c                ,    t        | j                        S rB   )r   projectr>   s    r'   <lambda>zsetup.<locals>.<lambda>   s    mDLL&A r&   r-   r7   rr   zen-usrt   1rv   ry   c                J    t        | j                         d| j                   S )N-)r   r   rs   r   s    r'   r   zsetup.<locals>.<lambda>   s    t||)D(EQt||n&U r&   rx   rz   r   Fr   r   c                "    | j                   xs dS Nenlanguager   s    r'   r   zsetup.<locals>.<lambda>  s    dmm&;t r&   r=   c                "    | j                   xs dS r   r   r   s    r'   r   zsetup.<locals>.<lambda>  s    $--:O4 r&   ru   c                     | j                   dz   S )Nz Help)r   r   s    r'   r   zsetup.<locals>.<lambda>  s    9O r&   rW   c                .    t        j                  dd       S )NCODE_SIGN_IDENTITY)r   getr   s    r'   r   zsetup.<locals>.<lambda>  s    gkk2F&M r&   r   c                T    t        j                  t        j                  dd            S )NOTHER_CODE_SIGN_FLAGS )r   splitr   r   r   s    r'   r   zsetup.<locals>.<lambda>
  s    ekk'++>UWY2Z&[ r&   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   r8   package_diradd_config_valuer   __version__)apps    r'   setupr      s   u./OO$%HdiiY&GH0A;P.kC5I/+F3S+F)4seD/U$& +T;F/{SEJ2E;N4dK#O.;[J+-OQ\]*,OQ\]6M$& 3[$& 13DkR24GU;UKP "# r&   )r   r   r   zdict[str, Any])8r   
__future__r   r|   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   r8   r   r    r#   	getLoggerr   r   r*   r,   r   r%   r&   r'   <module>r      s     "      7 7    6 % )  < ( 7)	rf$II
  dll<4<<12tyyk2Xy)			8	$)[ )) )wF, wFt%r&   