summaryrefslogtreecommitdiff
path: root/tools/web_fixture.py
blob: 06fc54cd2c89cd6fed43812703796b309416dc85 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""web_fixture.py PARDES OUT: the web shell's touch fixture as a dump of this
build: one pane on touch-fixture.zig at 100x30, theme helix.

    python3 -B tools/web_fixture.py <pardes> test/web-snapshots/touch.dump
"""
import os, sys, time, shutil, struct, fcntl, termios
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent.parent / 'test'))
import fs  # noqa: E402

binary, out = sys.argv[1], sys.argv[2]
root = Path('/tmp/pardes-web-fixture')  # fixed: the dump names it
shutil.rmtree(root, ignore_errors=True)
root.mkdir(parents=True, mode=0o700)
shutil.copy(Path(__file__).resolve().parent.parent / 'test' / 'web-snapshots' / 'touch-fixture.zig', root / 'touch-fixture.zig')
# Set at startup, which announces nothing: a fixture with no message on
# its pane.
(root / 'config' / 'pardes').mkdir(parents=True)
(root / 'config' / 'pardes' / 'init').write_text('Theme helix\nVerbose off\n')
handles = {}
with fs.session(binary, root, 'web', tty=True, file=root / 'touch-fixture.zig', inherited={'PARDES_DAEMON': 'off'}, terminal=handles) as (client, address):
    fcntl.ioctl(handles['input_fd'], termios.TIOCSWINSZ, struct.pack('HHHH', 30, 100, 0, 0))
    deadline = time.monotonic() + 10
    while client.screen()['cols'] != 100:
        assert time.monotonic() < deadline
        time.sleep(.01)
    client.write('/ctl', b'Dump\n')
    while b'\ndump ' not in client.read('/log'):
        assert time.monotonic() < deadline
        time.sleep(.01)
    print(client.read('/index').decode())
    shutil.copy(root / 'web.dump.zon', out)
shutil.rmtree(root, ignore_errors=True)
print(os.path.getsize(out), 'bytes')