1"""Cold-open a notebook whose tags carry Snowbound's art in OneNote 2010, have OneNote edit
2the tagged page, and capture what it shows, stores and leaves of the `.snowbound` folder.
3
4Usage: native_custom_art.py NOTEBOOK_DIR OUTPUT_DIR
5"""
6import base64
7import json
8import sys
9from pathlib import Path
10import xml.etree.ElementTree as ET
11
12sys.path.insert(0, str(Path(__file__).resolve().parent))
13import native_runner as runner
14
15windows = runner.windows
16EDIT = Path(__file__).resolve().parent / 'native/custom-art-edit.ps1'
17
18
19def interaction(name, output):
20 (output / 'scripts' / EDIT.name).write_bytes(EDIT.read_bytes())
21 result = windows.do_put(EDIT, 'C:\\one-tests\\custom-art-edit.ps1', name)
22 if result.get('error'):
23 raise RuntimeError(result['error'])
24 runner.command(name, 'powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass -File C:\\one-tests\\custom-art-edit.ps1 -Root C:\\one-tests\\runs\\capture', output, 300000)
25 page, = sorted((output / 'read').glob('page-*.xml'))
26 result = windows.do_exec(runner.navigation_script(ET.parse(page).getroot().attrib['ID']), target=name, shot_delay_ms=1500)
27 screenshot = result.pop('png_b64', None)
28 if screenshot:
29 (output / 'edited.png').write_bytes(base64.b64decode(screenshot))
30 (output / 'edited.json').write_text(json.dumps(result, indent=2))
31 if result.get('error') or result.get('exit') != 0:
32 raise RuntimeError(str(result))
33
34
35if __name__ == '__main__':
36 notebook, output = Path(sys.argv[1]), Path(sys.argv[2])
37 runner.capture(notebook, output, expected_pages=1, author=Path(__file__).resolve().parent / 'native/custom-art.ps1',
38 screenshots=True, collect_notebook=True, interaction=interaction)