diff options
Diffstat (limited to 'bitbake/bin/toaster-eventreplay')
-rwxr-xr-x | bitbake/bin/toaster-eventreplay | 82 |
1 files changed, 14 insertions, 68 deletions
diff --git a/bitbake/bin/toaster-eventreplay b/bitbake/bin/toaster-eventreplay index 8fa4ab7116..74a319320e 100755 --- a/bitbake/bin/toaster-eventreplay +++ b/bitbake/bin/toaster-eventreplay | |||
@@ -19,6 +19,8 @@ import sys | |||
19 | import json | 19 | import json |
20 | import pickle | 20 | import pickle |
21 | import codecs | 21 | import codecs |
22 | import warnings | ||
23 | warnings.simplefilter("default") | ||
22 | 24 | ||
23 | from collections import namedtuple | 25 | from collections import namedtuple |
24 | 26 | ||
@@ -28,79 +30,23 @@ sys.path.insert(0, join(dirname(dirname(abspath(__file__))), 'lib')) | |||
28 | 30 | ||
29 | import bb.cooker | 31 | import bb.cooker |
30 | from bb.ui import toasterui | 32 | from bb.ui import toasterui |
31 | 33 | from bb.ui import eventreplay | |
32 | class EventPlayer: | ||
33 | """Emulate a connection to a bitbake server.""" | ||
34 | |||
35 | def __init__(self, eventfile, variables): | ||
36 | self.eventfile = eventfile | ||
37 | self.variables = variables | ||
38 | self.eventmask = [] | ||
39 | |||
40 | def waitEvent(self, _timeout): | ||
41 | """Read event from the file.""" | ||
42 | line = self.eventfile.readline().strip() | ||
43 | if not line: | ||
44 | return | ||
45 | try: | ||
46 | event_str = json.loads(line)['vars'].encode('utf-8') | ||
47 | event = pickle.loads(codecs.decode(event_str, 'base64')) | ||
48 | event_name = "%s.%s" % (event.__module__, event.__class__.__name__) | ||
49 | if event_name not in self.eventmask: | ||
50 | return | ||
51 | return event | ||
52 | except ValueError as err: | ||
53 | print("Failed loading ", line) | ||
54 | raise err | ||
55 | |||
56 | def runCommand(self, command_line): | ||
57 | """Emulate running a command on the server.""" | ||
58 | name = command_line[0] | ||
59 | |||
60 | if name == "getVariable": | ||
61 | var_name = command_line[1] | ||
62 | variable = self.variables.get(var_name) | ||
63 | if variable: | ||
64 | return variable['v'], None | ||
65 | return None, "Missing variable %s" % var_name | ||
66 | |||
67 | elif name == "getAllKeysWithFlags": | ||
68 | dump = {} | ||
69 | flaglist = command_line[1] | ||
70 | for key, val in self.variables.items(): | ||
71 | try: | ||
72 | if not key.startswith("__"): | ||
73 | dump[key] = { | ||
74 | 'v': val['v'], | ||
75 | 'history' : val['history'], | ||
76 | } | ||
77 | for flag in flaglist: | ||
78 | dump[key][flag] = val[flag] | ||
79 | except Exception as err: | ||
80 | print(err) | ||
81 | return (dump, None) | ||
82 | |||
83 | elif name == 'setEventMask': | ||
84 | self.eventmask = command_line[-1] | ||
85 | return True, None | ||
86 | |||
87 | else: | ||
88 | raise Exception("Command %s not implemented" % command_line[0]) | ||
89 | |||
90 | def getEventHandle(self): | ||
91 | """ | ||
92 | This method is called by toasterui. | ||
93 | The return value is passed to self.runCommand but not used there. | ||
94 | """ | ||
95 | pass | ||
96 | 34 | ||
97 | def main(argv): | 35 | def main(argv): |
98 | with open(argv[-1]) as eventfile: | 36 | with open(argv[-1]) as eventfile: |
99 | # load variables from the first line | 37 | # load variables from the first line |
100 | variables = json.loads(eventfile.readline().strip())['allvariables'] | 38 | variables = None |
101 | 39 | while line := eventfile.readline().strip(): | |
40 | try: | ||
41 | variables = json.loads(line)['allvariables'] | ||
42 | break | ||
43 | except (KeyError, json.JSONDecodeError): | ||
44 | continue | ||
45 | if not variables: | ||
46 | sys.exit("Cannot find allvariables entry in event log file %s" % argv[-1]) | ||
47 | eventfile.seek(0) | ||
102 | params = namedtuple('ConfigParams', ['observe_only'])(True) | 48 | params = namedtuple('ConfigParams', ['observe_only'])(True) |
103 | player = EventPlayer(eventfile, variables) | 49 | player = eventreplay.EventPlayer(eventfile, variables) |
104 | 50 | ||
105 | return toasterui.main(player, player, params) | 51 | return toasterui.main(player, player, params) |
106 | 52 | ||