summaryrefslogtreecommitdiffstats
path: root/bitbake/bin/toaster-eventreplay
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/bin/toaster-eventreplay')
-rwxr-xr-xbitbake/bin/toaster-eventreplay179
1 files changed, 179 insertions, 0 deletions
diff --git a/bitbake/bin/toaster-eventreplay b/bitbake/bin/toaster-eventreplay
new file mode 100755
index 0000000000..624829aea0
--- /dev/null
+++ b/bitbake/bin/toaster-eventreplay
@@ -0,0 +1,179 @@
1#!/usr/bin/env python
2# ex:ts=4:sw=4:sts=4:et
3# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
4#
5# Copyright (C) 2014 Alex Damian
6#
7# This file re-uses code spread throughout other Bitbake source files.
8# As such, all other copyrights belong to their own right holders.
9#
10#
11# This program is free software; you can redistribute it and/or modify
12# it under the terms of the GNU General Public License version 2 as
13# published by the Free Software Foundation.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18# GNU General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License along
21# with this program; if not, write to the Free Software Foundation, Inc.,
22# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23
24
25# This command takes a filename as a single parameter. The filename is read
26# as a build eventlog, and the ToasterUI is used to process events in the file
27# and log data in the database
28
29import os
30import sys, logging
31
32# mangle syspath to allow easy import of modules
33sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
34 'lib'))
35
36
37import bb.cooker
38from bb.ui import toasterui
39import sys
40import logging
41
42logger = logging.getLogger(__name__)
43console = logging.StreamHandler(sys.stdout)
44format_str = "%(levelname)s: %(message)s"
45logging.basicConfig(format=format_str)
46
47
48import json, pickle
49
50
51class FileReadEventsServerConnection():
52 """ Emulates a connection to a bitbake server that feeds
53 events coming actually read from a saved log file.
54 """
55
56 class MockConnection():
57 """ fill-in for the proxy to the server. we just return generic data
58 """
59 def __init__(self, sc):
60 self._sc = sc
61
62 def runCommand(self, commandArray):
63 """ emulates running a command on the server; only read-only commands are accepted """
64 command_name = commandArray[0]
65
66 if command_name == "getVariable":
67 if commandArray[1] in self._sc._variables:
68 return (self._sc._variables[commandArray[1]]['v'], None)
69 return (None, "Missing variable")
70
71 elif command_name == "getAllKeysWithFlags":
72 dump = {}
73 flaglist = commandArray[1]
74 for k in self._sc._variables.keys():
75 try:
76 if not k.startswith("__"):
77 v = self._sc._variables[k]['v']
78 dump[k] = {
79 'v' : v ,
80 'history' : self._sc._variables[k]['history'],
81 }
82 for d in flaglist:
83 dump[k][d] = self._sc._variables[k][d]
84 except Exception as e:
85 print(e)
86 return (dump, None)
87 else:
88 raise Exception("Command %s not implemented" % commandArray[0])
89
90 def terminateServer(self):
91 """ do not do anything """
92 pass
93
94
95
96 class EventReader():
97 def __init__(self, sc):
98 self._sc = sc
99 self.firstraise = 0
100
101 def _create_event(self, line):
102 def _import_class(name):
103 assert len(name) > 0
104 assert "." in name, name
105
106 components = name.strip().split(".")
107 modulename = ".".join(components[:-1])
108 moduleklass = components[-1]
109
110 module = __import__(modulename, fromlist=[str(moduleklass)])
111 return getattr(module, moduleklass)
112
113 # we build a toaster event out of current event log line
114 try:
115 event_data = json.loads(line.strip())
116 event_class = _import_class(event_data['class'])
117 event_object = pickle.loads(json.loads(event_data['vars']))
118 except ValueError as e:
119 print("Failed loading ", line)
120 raise e
121
122 if not isinstance(event_object, event_class):
123 raise Exception("Error loading objects %s class %s ", event_object, event_class)
124
125 return event_object
126
127 def waitEvent(self, timeout):
128
129 nextline = self._sc._eventfile.readline()
130 if len(nextline) == 0:
131 # the build data ended, while toasterui still waits for events.
132 # this happens when the server was abruptly stopped, so we simulate this
133 self.firstraise += 1
134 if self.firstraise == 1:
135 raise KeyboardInterrupt()
136 else:
137 return None
138 else:
139 self._sc.lineno += 1
140 return self._create_event(nextline)
141
142
143 def _readVariables(self, variableline):
144 self._variables = json.loads(variableline.strip())['allvariables']
145
146
147 def __init__(self, file_name):
148 self.connection = FileReadEventsServerConnection.MockConnection(self)
149 self._eventfile = open(file_name, "r")
150
151 # we expect to have the variable dump at the start of the file
152 self.lineno = 1
153 self._readVariables(self._eventfile.readline())
154
155 self.events = FileReadEventsServerConnection.EventReader(self)
156
157
158
159
160
161class MockConfigParameters():
162 """ stand-in for cookerdata.ConfigParameters; as we don't really config a cooker, this
163 serves just to supply needed interfaces for the toaster ui to work """
164 def __init__(self):
165 self.observe_only = True # we can only read files
166
167
168# run toaster ui on our mock bitbake class
169if __name__ == "__main__":
170 if len(sys.argv) < 2:
171 logger.error("Usage: %s event.log " % sys.argv[0])
172 sys.exit(1)
173
174 file_name = sys.argv[-1]
175 mock_connection = FileReadEventsServerConnection(file_name)
176 configParams = MockConfigParameters()
177
178 # run the main program
179 toasterui.main(mock_connection.connection, mock_connection.events, configParams)