#!/usr/bin/env python3
"""The seek walk's two books (WALK_BOOK_FACES=seek): "The Lantern Orchard", an
invented book of twelve chapters, as an EPUB (a nav document, one resource
per chapter) and a PDF (three pages a chapter, an outline entry each). Every
word is made here from a fixed word list, so the files are the same bytes on
every run and belong to nobody.
python3 scripts/gen-seek-fixtures.py # writes apps/cotton/Tests/CottonUITests/Fixtures/Books/the-lantern-orchard.{epub,pdf}
"""
import os
import random
import zipfile
import zlib
HERE = os.path.dirname(os.path.abspath(__file__))
OUT = os.path.join(HERE, "..", "apps", "cotton", "Tests", "CottonUITests", "Fixtures", "Books")
TITLE = "The Lantern Orchard"
AUTHOR = "Asha Mercer"
CHAPTERS = ["The Gate", "Lamp Oil", "The Ferryman's Ledger", "Windfall", "A Map of the Rows", "The Grafting Knife",
"Night Pickers", "Cider Weather", "The Blight Year", "Smoke on the Terraces", "The Last Ladder", "Harvest Home"]
WORDS = ("orchard lantern ferry ledger harbour terrace ladder basket cider graft blossom frost keeper river stone path "
"evening morning quiet amber slow narrow bright cold warm old small tall the a and of in on by with under over "
"walked carried counted lit waited turned gathered remembered opened closed followed kept left found").split()
def paragraph(rng, sentences):
out = []
for _ in range(sentences):
words = [rng.choice(WORDS) for _ in range(rng.randint(9, 17))]
out.append(" ".join(words).capitalize() + ".")
return " ".join(out)
def epub(path):
rng = random.Random(1892)
stamp = (2026, 1, 1, 0, 0, 0)
def put(z, name, text, method=zipfile.ZIP_DEFLATED):
info = zipfile.ZipInfo(name, stamp)
info.compress_type = method
z.writestr(info, text)
with zipfile.ZipFile(path, "w") as z:
put(z, "mimetype", "application/epub+zip", zipfile.ZIP_STORED)
put(z, "META-INF/container.xml", ''
'')
items = "".join(f'' for i in range(1, len(CHAPTERS) + 1))
spine = "".join(f'' for i in range(1, len(CHAPTERS) + 1))
put(z, "OEBPS/content.opf", ''
f'urn:cotton:fixture:the-lantern-orchard'
f'{TITLE}{AUTHOR}en'
'2026-01-01T00:00:00Z'
f'{items}'
f'{spine}')
links = "".join(f'