from pathlib import Path
import json,zipfile,shutil,base64
from openpyxl import Workbook
from PIL import Image,ImageDraw
P=Path('/tmp/lead-32693-r2/capture-1/project')
w=Workbook();w.active.title='First long synthetic worksheet';w.create_sheet('Second long synthetic worksheet')
for s in w:
 for row in range(1,201):s.append([f'{s.title[:6]} {row},{col}' for col in range(1,21)])
w.save(P/'workbook.xlsx')
(P/'extended.rtf').write_text(r'{\rtf1\ansi\deff0 '+r'\page '.join(r'\fs36 Synthetic page '+str(i)+r'\par\fs24 '+r'\par '.join('Synthetic paragraph '+str(n)+': '+('reading position '*15) for n in range(30)) for i in range(1,4))+'}')
ns='xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"'
def odf(name,mime,body):
 with zipfile.ZipFile(P/name,'w') as z:
  z.writestr('mimetype',mime)
  z.writestr('META-INF/manifest.xml',f'<manifest:manifest xmlns:manifest="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0"><manifest:file-entry manifest:full-path="/" manifest:media-type="{mime}"/><manifest:file-entry manifest:full-path="content.xml" manifest:media-type="text/xml"/></manifest:manifest>')
  z.writestr('content.xml',f'<office:document-content {ns} office:version="1.2"><office:body>{body}</office:body></office:document-content>')
odf('long-body.odt','application/vnd.oasis.opendocument.text','<office:text>'+''.join(f'<text:p>Synthetic ODT paragraph {i}. '+('Reading position retained. '*20)+'</text:p>' for i in range(100))+'</office:text>')
odf('slides.odp','application/vnd.oasis.opendocument.presentation','<office:presentation>'+''.join(f'<draw:page draw:name="Slide {i}"><draw:frame svg:x="1cm" svg:y="1cm" svg:width="20cm" svg:height="10cm"><draw:text-box><text:p>Synthetic ODP slide {i}</text:p></draw:text-box></draw:frame></draw:page>' for i in range(1,4))+'</office:presentation>')
odf('sheets.ods','application/vnd.oasis.opendocument.spreadsheet','<office:spreadsheet>'+''.join(f'<table:table table:name="{name}">'+''.join('<table:table-row>'+''.join(f'<table:table-cell office:value-type="string"><text:p>R{r} C{c}</text:p></table:table-cell>' for c in range(20))+'</table:table-row>' for r in range(200))+'</table:table>' for name in ['First sheet','Second long synthetic sheet'])+'</office:spreadsheet>')
with zipfile.ZipFile(P/'chapters.epub','w') as z:
 z.writestr('mimetype','application/epub+zip')
 z.writestr('META-INF/container.xml','<container xmlns="urn:oasis:names:tc:opendocument:xmlns:container" version="1.0"><rootfiles><rootfile full-path="content.opf" media-type="application/oebps-package+xml"/></rootfiles></container>')
 z.writestr('content.opf','<package xmlns="http://www.idpf.org/2007/opf" version="3.0" unique-identifier="id"><metadata xmlns:dc="http://purl.org/dc/elements/1.1/"><dc:identifier id="id">synthetic</dc:identifier><dc:title>Synthetic chapters</dc:title><dc:language>en</dc:language></metadata><manifest>'+''.join(f'<item id="c{i}" href="c{i}.xhtml" media-type="application/xhtml+xml"/>' for i in range(1,4))+'</manifest><spine>'+''.join(f'<itemref idref="c{i}"/>' for i in range(1,4))+'</spine></package>')
 for i in range(1,4):z.writestr(f'c{i}.xhtml',f'<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Long synthetic chapter {i} for preview evidence</title></head><body><h1>Chapter {i}</h1>'+''.join(f'<p>Paragraph {n}. '+('Synthetic chapter reading position. '*15)+'</p>' for n in range(60))+'</body></html>')
im=Image.new('RGB',(500,200),'#225577');ImageDraw.Draw(im).text((20,80),'Synthetic image for archive and notebook',fill='white');im.save(P/'synthetic.png')
nb={'nbformat':4,'nbformat_minor':5,'metadata':{},'cells':[]}
for i in range(25):
 kind=['markdown','code','raw'][i%3];cell={'id':f'cell{i}','cell_type':kind,'metadata':{},'source':[f'{"# " if kind=="markdown" else ""}Synthetic cell {i+1}\n',('Synthetic content. '*12)+'\n']}
 if kind=='code':cell.update(execution_count=None,outputs=[{'output_type':'stream','name':'stdout','text':[f'Saved text output {i+1}']},{'output_type':'display_data','metadata':{},'data':{'text/html':['<strong>Synthetic saved HTML</strong>'],'image/png':[base64.b64encode((P/'synthetic.png').read_bytes()).decode()]}}])
 nb['cells'].append(cell)
(P/'notebook.ipynb').write_text(json.dumps(nb))
with zipfile.ZipFile(P/'archive.zip','w') as z:
 z.writestr('nested/','')
 for i in range(60):z.writestr(f'nested/entry-{i:02d}.txt',('Synthetic long text file\n'*200))
 z.write(P/'synthetic.png','nested/synthetic.png')
shutil.copyfile('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf',P/'Synthetic-long-font-specimen-DejaVuSans.ttf')
print('Extra synthetic fixtures created')
