
    X~\j              
         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Zd dlm	Z	  e	e
                                          j        d         Zedz  Zdd
ZddZd dZd!dZd"dZedk    rw	  ej         e                       dS # e$ rTZ e ej        dd ee          j         de dd          ej                    ej        d           Y dZ[dS dZ[ww xY wdS )#    )annotationsN)Path   zscript/project-manifest.jsonpathr   returnstrc                   t          j                    }|                     d          5 t          fdd          D ]}|                    |           	 d d d            n# 1 swxY w Y   |                                S )Nrbc                 .                          d          S )Ni   )read)handles   script/normalize-layout.py<lambda>zsha256.<locals>.<lambda>   s    &++o">">     r   )hashlibsha256openiterupdate	hexdigest)r   digestchunkr   s      @r   r   r      s    ^F	4 !F>>>>DD 	! 	!EMM%    	!! ! ! ! ! ! ! ! ! ! ! ! ! ! ! s   ,A##A'*A'manifestdictkeyc                   |                      d          pi                      |          }t          |t                    r|st          d| d          t	          |          }|                                s
t          |z  }	 |                                                    t                                                     n%# t          $ r}t          d|           |d }~ww xY w|S )Nactive_pathszactive_paths.z is missingzactive path escapes project: )
get
isinstancer   RuntimeErrorr   is_absoluteROOTresolverelative_to
ValueError)r   r   valuer   excs        r   resolve_activer(      s    \\.))/R44S99EeS!! = =;3;;;<<<;;D d{K""4<<>>2222 K K K@3@@AAsJKKs   >C 
C$CC$r&   Nonec                   | j                             dd           t          j        |dd          dz                       d          }t          j        d| j         d| j         	          \  }}	 t          j	        |d
          5 }|
                    |           |                                 t          j        |                                           d d d            n# 1 swxY w Y   t          j        ||            t          j                            |          rt          j        |           d S d S # t          j                            |          rt          j        |           w w xY w)NTparentsexist_okF   )ensure_asciiindent
utf-8.)prefixdirwb)parentmkdirjsondumpsencodetempfilemkstempnameosfdopenwriteflushfsyncfilenoreplacer   existsunlink)r   r&   datafdr>   r   s         r   atomic_jsonrJ   &   s   KdT222Ju5;;;dBJJ7SSD'749'7'7'7T[IIIHBYr4   	&FLLLLNNNHV]]__%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	
47>>$ 	IdOOOOO	 	27>>$ 	IdOOOO	s1   2D: AC#D: #C''D: *C'+D: :6E0command	list[str]c                2    t          j        | d           d S )NT)check)
subprocessrun)rK   s    r   rP   rP   5   s    N7$''''''r   intc                 	   t          j        t                              d                    fddD             } | d         | d         | d         | d         | d	         | d
         g}d |D             }|rt	          d|           t          j        | d
                             d                    }t          j        | d                             d                    }t          j        | d	                             d                    }|                    d          }|                    d          dk    s|                    d          durt	          d          | d         | d         | d         d}d |                                D             }d|fd|ffD ]\  }	}
|
                    d          dk    s|
                    d          durt	          |	 d          |
                    d          |k    rt	          |	 d          |
                    d          |k    rt	          d|	 d          | d         | d         | d         | d          | d!         g}d" |D             }|rt	          d#|           |D ]}|j                            dd$           t          d%d&d'd(d)t          | d                   d*d+d,d-t          | d                   g           t          d%d&d'd(d)t          | d                   d*d+d,d-t          | d                   g           t          d%d&d'd(d)t          | d                   d*d.d,d-t          | d                   g           t          d%d&d'd(d)t          | d                   d)t          | d                   d/d0d1d2d,d-t          | d                    g           d3d4||t          | d                   t          | d                   d5t          | d	                   t          | d	                   d5d6 |d d7         D             d8dd9	}t          | d!         |           t          t          j        |d         d4t          | d!                   d:d4;                     d<S )=Nr2   )encodingc                2    i | ]}|t          |          S  )r(   ).0r   projects     r   
<dictcomp>zmain.<locals>.<dictcomp>;   s5        	^GS))  r   )left_panel_masterright_panel_masterintro_masterleft_panel_normalizedright_panel_normalizedintro_normalizedlayoutartwork_visual_receiptorientation_receiptpromotion_receiptlayout_normalization_receiptrY   rZ   r[   r`   ra   rb   c                T    g | ]%}|                                 t          |          &S rU   rF   r   rV   r   s     r   
<listcomp>zmain.<locals>.<listcomp>H   s+    CCCTT[[]]Cs4yyCCCr   znormalization inputs missing: canon_sha256status	completedverifiedTzpromotion is not verified)
left_panelright_panelintroc                4    i | ]\  }}|t          |          S rU   )r   )rV   r>   r   s      r   rX   zmain.<locals>.<dictcomp>V   s$    JJJJD$T6$<<JJJr   visualorientationz gate is absent or failedsource_canon_sha256z gate is stale for canonartifact_sha256zartwork master drift after z gater\   r]   r^   r_   rc   c                T    g | ]%}|                                 t          |          &S rU   re   rf   s     r   rg   zmain.<locals>.<listcomp>c   s+    ???d?D		???r   zAnormalized outputs already exist and require audit/invalidation: r+   ffmpegz-verrorz-yz-iz-vfzbscale=656:1080:force_original_aspect_ratio=decrease,pad=656:1080:(ow-iw)/2:(oh-ih)/2:color=#101820z	-frames:v1zdscale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2:color=#101820z-filter_complexzlcolor=c=#101820:s=1920x1080:r=1[base];[base][0:v]overlay=0:0[tmp];[tmp][1:v]overlay=1264:0,format=rgb24[out]z-mapz[out]&completed_pending_target_visual_reviewF)r   r   c                    i | ]Q}t          |                    t                              t          |          |                                j        d RS ))r   bytes)r   r$   r"   r   statst_sizerf   s     r   rX   zmain.<locals>.<dictcomp>   sY     
 
 
   &&''F4LL499;;K^)_)_
 
 
r   zImechanical scale-decrease and pad; no crop, text overlay, or text editing)	ri   rk   rr   master_artifact_sha256visual_receiptra   outputsmethodtarget_visual_review_required)ri   rk   receiptr/   r   )r9   loadsPROJECT_MANIFEST	read_textr    r   itemsr7   r8   rP   r   r   rJ   printr:   )pathsrequiredmissing	promotionrp   rq   
canon_hashmastersmaster_hashes	gate_namegater   existingr   resultrW   s                  @r   mainr   9   s|   j)33W3EEFFG   
  E 	!"E*>$?~AV&'/D)EuM`GaH DCXCCCG GEGEEFFF
5!45???QQRRIZ67AA7ASSTTF*U#89CCWCUUVVK~..J}}X+--z1J1JRV1V1V6777/012~& G
 KJ'--//JJJM%v.0LM O O	488H,,0D0DD0P0P)FFFGGG88)**j88)EEEFFF88%&&-77MYMMMNNN 8 	%&.F(G !5?E:X4YG @?g???H ki_giijjj 7 7$6666 $tS7J1K-L-LsS#e$;<==	   
 $tS7K1L-M-MsS#e$<=>>	   
 $tS~1F-G-GuS#e$6788	   
 $tS7N1O-P-Pc%01224Evc3uX+?+?		    ;)]#&u-E'F#G#GSYZ_`xZySzSz{{(+E2G,H(I(IU[\abw\xUyUyzz
 

 
 
 ^)- F 45v>>>	$*x 0ePSTYZxTyPzPz{{  KP  Q  Q  Q  R  R  R1r   __main__failedFz: )ri   rk   rv   r   )file)r   r   r   r   )r   r   r   r   r   r   )r   r   r&   r   r   r)   )rK   rL   r   r)   )r   rQ   )
__future__r   r   r9   r?   rO   sysr<   pathlibr   __file__r#   r,   r"   r   r   r(   rJ   rP   r   __name__exit	Exceptionr'   r   r:   typestderrrU   r   r   <module>r      s   " " " " " "   				     



       tH~~'*88          ( ( ( (T T T Tn z   jdjH%TTRUYYM_JhJhcfJhJhiix}~~~  FI  FP  	Q  	Q  	Q  	Q s   -B C A	CC 