forked from stb-tester/stb-tester
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstbt-record
executable file
·78 lines (65 loc) · 2.46 KB
/
stbt-record
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python
"""
Copyright 2012-2013 YouView TV Ltd.
License: LGPL v2.1 or (at your option) any later version (see
https://github.com/stb-tester/stb-tester/blob/master/LICENSE for details).
"""
import itertools
import sys
import _stbt.control
import _stbt.core
import stbt
def main(argv):
parser = _stbt.core.argparser()
parser.prog = 'stbt record'
parser.description = 'Create an stb-tester test script'
parser.add_argument(
'--control-recorder',
default=stbt.get_config('record', 'control_recorder'),
help='The source of remote control keypresses (default: %(default)s)')
parser.add_argument(
'-o', '--output-file',
default=stbt.get_config('record', 'output_file'),
help='The filename of the generated script (default: %(default)s)')
args = parser.parse_args(argv[1:])
stbt.debug("Arguments:\n" + "\n".join([
"%s: %s" % (k, v) for k, v in args.__dict__.items()]))
try:
script = open(args.output_file, 'w')
except IOError as e:
e.strerror = "Failed to write to output-file '%s': %s" % (
args.output_file, e.strerror)
raise
try:
stbt.init_run(
args.source_pipeline, args.sink_pipeline, args.control,
restart_source=args.restart_source,
transformation_pipeline=(
stbt.get_config('global', 'transformation_pipeline')))
record(args.control_recorder, script)
finally:
stbt.teardown_run()
def record(control_recorder, script_out):
stbt.get_frame() # Fail early if no video
count = itertools.count()
old_key = None
script_out.write("import stbt\n\n\n")
script_out.write("def test_that_WRITE_TESTCASE_DESCRIPTION_HERE():\n")
try:
for key in _stbt.control.uri_to_remote_recorder(control_recorder):
write_wait_for_match(script_out, count.next(), old_key)
script_out.write(" stbt.press('%s')\n" % key)
stbt.press(key)
old_key = key
except KeyboardInterrupt:
write_wait_for_match(script_out, count.next(), old_key)
return
write_wait_for_match(script_out, count.next(), old_key)
def write_wait_for_match(script_out, i, old_key):
if old_key is None:
return
filename = "%04d-%s-complete.png" % (i, old_key)
stbt.save_frame(stbt.get_frame(), filename)
script_out.write(" stbt.wait_for_match('%s')\n" % filename)
if __name__ == "__main__":
sys.exit(main(sys.argv))