1#!/usr/local/bin/python3.8
2
3import argparse
4import subprocess
5import os
6
7parser = argparse.ArgumentParser(description='A recorded scenario player for EFL-based applications.\n\n'
8  'Actions recorded with `exactness_record` can be played back with this\n'
9  'application and screenshots obtained. It is typically more convenient to\n'
10  'use the `exactness` wrapper in "play" mode to process files in batches.',
11  formatter_class=argparse.RawDescriptionHelpFormatter,
12  epilog='Example:\n'
13  'exactness_play -s -t my_app.exu -- my_app --app --arguments')
14parser.add_argument('app', metavar='app', help='The app to run. You can also pass environment variables here. '
15  'Use a -- if you need to provide arguments to the app.',
16  type=str, nargs='*')
17parser.add_argument('-o', '--output', metavar='output', help="Destination for the shots. "
18          "If a `.exu` file is given, the shots are stored in the file. "
19          "Otherwise the given path is considered as a directory "
20          "where shots will be stored. "
21          "If omitted, the output type (exu or dir) is determined "
22          "by the given test extension (resp. exu or rec).", type=str)
23parser.add_argument('-t', '--tests', metavar='tests', help='Name of the file where to store the test.', type=str)
24parser.add_argument('-s', '--show-on-screen', help='Show on screen', action='store_true', default=False)
25parser.add_argument('--scan-objects', help='Extract information of all the objects at every shot.', action='store_true')
26parser.add_argument('--external-injection', help='Expect events injection via Eina debug channel.', action='store_true')
27parser.add_argument('--disable-screenshots', help='Disable screenshots.', action='store_true')
28parser.add_argument('-f', '--fontsdir', metavar='fontsdir', help='Specify a directory of the fonts that should be used.', type=str)
29parser.add_argument('--stabilize-shots', help='Wait for the frames to be stable before taking the shots.', action='store_true')
30parser.add_argument('--speed', metavar='speed', help='Set the speed used to play the given test (default 1.0).', type=float, default=1.0)
31parser.add_argument('-v', '--verbose', help='Turn verbose messages on', action='store_true')
32parser.add_argument('-L', '--license', help='Print license information and exit.', action='store_true')
33parser.add_argument('-C', '--copyright', help='Print copyright information and exit.', action='store_true')
34parser.add_argument('-V', '--version', help='Print version information and exit.', action='store_true')
35
36G = parser.parse_args()
37
38if G.license:
39  print("BSD.")
40  exit(0)
41
42if G.copyright:
43  print("(C) 2017-2020 Enlightenment.")
44  exit(0)
45
46if G.version:
47  print(@VERSION@)
48  exit(0)
49
50spawn_env = os.environ.copy()
51spawn_env["LD_PRELOAD"] = @EXACTNESS_PLAY_PRELOAD_PATH@
52
53if G.tests == None and G.external_injection == True:
54  print("no test file specified")
55  exit(-1)
56if G.tests != None and G.external_injection == True:
57  print("Cannot inject events from a source file and from outside simultaneously")
58  exit(-1)
59if G.scan_objects == True and G.tests.endswith(".exu"):
60  printf("Scan objects options is available only if the destination is a EXU file")
61  exit(-1)
62
63if G.output != None:
64  spawn_env["EXACTNESS_DEST"] = G.output;
65if G.external_injection:
66  spawn_env["EXACTNESS_EXTERNAL_INJECTION"] = "Yes"
67if G.tests != None:
68  spawn_env["EXACTNESS_SRC"] = G.tests
69if G.fontsdir != None:
70  spawn_env["EXACTNESS_FONTS_DIR"] = G.fontsdir
71if G.speed != 1.0:
72  spawn_env["EXACTNESS_SPEED"] = G.speed
73if G.scan_objects:
74  spawn_env["EXACTNESS_SCAN_OBJECTS"] = "Yes"
75if G.disable_screenshots:
76  spawn_env["EXACTNESS_DISABLE_SHOTS"] = "Yes"
77if G.stabilize_shots:
78  spawn_env["EXACTNESS_STABILIZE_SHOTS"] = "Yes"
79if G.verbose:
80  spawn_env["EXACTNESS_VERBOSE"] = "Yes"
81if G.show_on_screen == False:
82  spawn_env["ELM_DISPLAY"] = "buffer"
83
84passed_all_the_env_vars = False
85app = []
86
87for argument in G.app:
88  if '=' not in argument:
89    passed_all_the_env_vars = True
90  else:
91    if passed_all_the_env_vars:
92      print("Error, env vars can only be specified at the beginning of the app call line")
93      exit(-1)
94    split_env_var = argument.split('=')
95    spawn_env[split_env_var[0]] = split_env_var[1]
96
97  if passed_all_the_env_vars:
98    app.append(argument)
99
100recorder = subprocess.Popen(app, env=spawn_env)
101recorder.wait()
102