+
    #j                     2   R t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIHt ^ RIt	^ RI
HtHtHt RR R lltRR R lltR	 R
 lt]R8X  d   ]P$                  ! RR7      t]P)                  RRR7       ]P)                  RRR7       ]P)                  RRR7       ]P)                  RR RRRR7       ]P+                  4       t]! ]P.                  ]P0                  ]P2                  ]P4                  R7      w  tt]! ]4       R]9   d   ]P<                  ! ^4       R# R# R# )aq  Pack a directory into a DOCX, PPTX, or XLSX file.

Validates with auto-repair, condenses XML formatting, and creates the Office file.

Usage:
    python pack.py <input_directory> <output_file> [--original <file>] [--validate true|false]

Examples:
    python pack.py unpacked/ output.docx --original input.docx
    python pack.py unpacked/ output.pptx --validate false
NPath)DOCXSchemaValidatorPPTXSchemaValidatorRedliningValidatorTc                |    V ^8  d   QhR\         R\         R\         R,          R\        R\        R\         3,          /# )   input_directoryoutput_fileoriginal_fileNvalidatereturn)strbooltuple)formats   "l/opt/hermes-venv/lib/python3.14/site-packages/../../../skills/productivity/powerpoint/scripts/office/pack.py__annotate__r      sN     *E *E*E*E :*E 	*E 49*E    c                    \        V 4      p\        V4      pVP                  P                  4       pVP                  4       '       g	   R RV R23# VR9  d	   R RV R23# V'       dZ   V'       dR   \        V4      pVP	                  4       '       d1   \        WXWt4      w  rV
'       d   \        V
4       V	'       g   R RV 23# \        P                  ! 4       ;_uu_ 4       p\        V4      R,          p\        P                  ! W\4       R F&  pVP                  V4       F  p\        V4       K  	  K(  	  VP                  P                  RRR7       \        P                   ! VR\        P"                  4      ;_uu_ 4       pVP                  R	4       F<  pVP%                  4       '       g   K  VP'                  VVP)                  V4      4       K>  	  R R R 4       R R R 4       R R
V RV 23#   + '       g   i     L"; i  + '       g   i     L-; i)NzError: z is not a directoryz& must be a .docx, .pptx, or .xlsx filezError: Validation failed for contentT)parentsexist_okw*zSuccessfully packed z to >   .docx.pptx.xlsx)z*.xmlz*.rels)r   suffixloweris_direxists_run_validationprinttempfileTemporaryDirectoryshutilcopytreerglob_condense_xmlparentmkdirzipfileZipFileZIP_DEFLATEDis_filewriterelative_to)r	   r
   r   r   infer_author_func	input_diroutput_pathr   original_pathsuccessoutputtemp_dirtemp_content_dirpatternxml_filezffs   &&&&&            r   packr>      s    _%I{#K%%'Fwyk)<===00w{m+QRRRM]+!!-&OG f<YKHHH		$	$	&	&(>I5	4*G,227;h' < + 	   =__[#w/C/CDD%++C099;;HHQ.> ?@ 1 E 
' '	{${mDDD ED 
'	&s+   B G;<(G(	)%G(	G;(G83G;;H	c                x    V ^8  d   QhR\         R\         R\        R\        \        \        R,          3,          /# )r   unpacked_dirr   r   r   N)r   r   r   r   )r   s   "r   r   r   E   sD     $F $F$F$F $F
 4t$Fr   c                 J   . p. pVR 8X  d-   RpV'       d
    V! W4      p\	        W4      \        WVR7      .pMVR8X  d   \        W4      .pV'       g   R# \        R	 V 4       4      pV'       d   VP                  R
V R24       \        ;QJ d    R V 4       F  '       d   K   RM	  RM! R V 4       4      p	V	'       d   VP                  R4       Y'       d   RP                  V4      3# R3#   \          d*   p\        RT R2\        P                  R7        Rp?LRp?ii ; i)r   Claudez	Warning: z Using default author 'Claude'.fileN)authorr   Tc              3   @   "   T F  qP                  4       x  K  	  R # 5iN)repair.0vs   & r   	<genexpr>"_run_validation.<locals>.<genexpr>`   s     7Jq

J   zAuto-repaired z	 issue(s)c              3   @   "   T F  qP                  4       x  K  	  R # 5irG   )r   rI   s   & r   rL   rM   d   s     3
1**,,
rN   FzAll validations PASSED!
)TN)
ValueErrorr#   sysstderrr   r   r   sumappendalljoin)
r@   r   r   r2   output_lines
validatorsrE   etotal_repairsr6   s
   &&&&      r   r"   r"   E   s    LJW*<G
  <|6J

 
7	),FG
7J77Mn]O9EFc3
3ccc3
33G56|DIIl+EEEE-  W	!$CD3::VVWs   C. .D"9DD"c                (    V ^8  d   QhR\         RR/# )r   r;   r   Nr   )r   s   "r   r   r   l   s      D T r   c                     \        V R R7      ;_uu_ 4       p\        P                  P                  V4      pRRR4       XP	                  R4       F  pVP
                  P                  R4      '       d   K&  \        VP                  4       F}  pVP                  VP                  8X  d2   VP                  '       d    VP                  P                  4       R8X  g   VP                  VP                  8X  g   Kl  VP                  V4       K  	  K  	  V P                  VP!                  RR7      4       R#   + '       g   i     EL; i  \"         d2   p\%        RT P&                   RT 2\(        P*                  R	7       h Rp?ii ; i)
zutf-8)encodingNr   z:t zUTF-8zERROR: Failed to parse z: rC   )open
defusedxmlminidomparsegetElementsByTagNametagNameendswithlist
childNodesnodeType	TEXT_NODE	nodeValuestripCOMMENT_NODEremoveChildwrite_bytestoxml	Exceptionr#   namerR   rS   )r;   r=   domelementchildrZ   s   &     r   r)   r)   l   s   (W--$$**1-C . //4G''--g001NNeoo5--/25^^u'9'99''. 2	 5 	SYYY89 .--   'b<3::Ns:   E  D3BE ;7E 7:E 3E	>	E F,E>>F__main__z0Pack a directory into a DOCX, PPTX, or XLSX file)descriptionr	   z"Unpacked Office document directory)helpr
   z&Output Office file (.docx/.pptx/.xlsx)z
--originalz'Original file for validation comparisonz
--validatec                 (    V P                  4       R 8H  # )true)r   )xs   &r   <lambda>r|      s    qwwyF*r   z
true|falsez/Run validation with auto-repair (default: true))typedefaultmetavarrx   )r   r   Error)NTNrG   )__doc__argparserR   r&   r$   r,   pathlibr   defusedxml.minidomra   rY   r   r   r   r>   r"   r)   __name__ArgumentParserparseradd_argument
parse_argsargsr	   r
   originalr   _messager#   exit r   r   <module>r      s#  
  
      S S*EZ$FN. z$$FF )0TU
,TU
6   *>   Dmm	JAw 
'N' 7 r   