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