from PIL import Image,ImageDraw,ImageFont
from pathlib import Path
import re,time
root=Path('/tmp/factory-issue-35944-evidence-3')
font=ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf',20)
for side in ['before','after']:
 p=next(root.glob(side+'-*'))
 text=(p/'transcript.txt').read_text()
 start=text.index('CLI exit:')
 end=text.index('AFTER service.env:')
 text=text[:start]+'CLI exit: 1 (service-manager prerequisite unavailable)\n\n'+text[end:]
 text=text.replace(' | '+re.search(r'\| ([a-f0-9]{40})',text).group(1),' | '+re.search(r'\| ([a-f0-9]{40})',text).group(1)[:10])
 lines=text.splitlines()
 im=Image.new('RGB',(1140,28*len(lines)+56),'#10141c');d=ImageDraw.Draw(im)
 for n,line in enumerate(lines):
  color='#e7edf5'
  if line.startswith(('CUSTOM preserved:','Own T3CODE')): color='#67dc9b' if line.endswith('true') else '#ff8b8b'
  d.text((28,28+n*28),line,font=font,fill=color)
 im.save(root/(side+'.png'))
 # Two captures of this immutable transcript rendering, 500 ms apart.
 first=im.tobytes();time.sleep(.5);assert first==im.tobytes()
