blob: 48d808ae28254f56b1bce0a6b149e0f286ac4689 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001#
2# Copyright (C) 2006 - 2007 Michael 'Mickey' Lauer
3# Copyright (C) 2006 - 2007 Richard Purdie
4#
Brad Bishopc342db32019-05-15 21:57:59 -04005# SPDX-License-Identifier: GPL-2.0-only
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006#
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007
8import bb.build
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009import time
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010
11class BBUIHelper:
12 def __init__(self):
13 self.needUpdate = False
14 self.running_tasks = {}
15 # Running PIDs preserves the order tasks were executed in
16 self.running_pids = []
17 self.failed_tasks = []
Andrew Geissler82c905d2020-04-13 13:39:40 -050018 self.pidmap = {}
Patrick Williamsc124f4f2015-09-15 14:41:29 -050019 self.tasknumber_current = 0
20 self.tasknumber_total = 0
21
22 def eventHandler(self, event):
Andrew Geissler82c905d2020-04-13 13:39:40 -050023 # PIDs are a bad idea as they can be reused before we process all UI events.
24 # We maintain a 'fuzzy' match for TaskProgress since there is no other way to match
25 def removetid(pid, tid):
26 self.running_pids.remove(tid)
27 del self.running_tasks[tid]
28 if self.pidmap[pid] == tid:
29 del self.pidmap[pid]
30 self.needUpdate = True
31
Patrick Williamsc124f4f2015-09-15 14:41:29 -050032 if isinstance(event, bb.build.TaskStarted):
Andrew Geissler82c905d2020-04-13 13:39:40 -050033 tid = event._fn + ":" + event._task
Brad Bishop37a0e4d2017-12-04 01:01:44 -050034 if event._mc != "default":
Andrew Geissler82c905d2020-04-13 13:39:40 -050035 self.running_tasks[tid] = { 'title' : "mc:%s:%s %s" % (event._mc, event._package, event._task), 'starttime' : time.time(), 'pid' : event.pid }
Brad Bishop37a0e4d2017-12-04 01:01:44 -050036 else:
Andrew Geissler82c905d2020-04-13 13:39:40 -050037 self.running_tasks[tid] = { 'title' : "%s %s" % (event._package, event._task), 'starttime' : time.time(), 'pid' : event.pid }
38 self.running_pids.append(tid)
39 self.pidmap[event.pid] = tid
Patrick Williamsc124f4f2015-09-15 14:41:29 -050040 self.needUpdate = True
Patrick Williamsc0f7c042017-02-23 20:41:17 -060041 elif isinstance(event, bb.build.TaskSucceeded):
Andrew Geissler82c905d2020-04-13 13:39:40 -050042 tid = event._fn + ":" + event._task
43 removetid(event.pid, tid)
Patrick Williamsc0f7c042017-02-23 20:41:17 -060044 elif isinstance(event, bb.build.TaskFailedSilent):
Andrew Geissler82c905d2020-04-13 13:39:40 -050045 tid = event._fn + ":" + event._task
46 removetid(event.pid, tid)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050047 # Don't add to the failed tasks list since this is e.g. a setscene task failure
Patrick Williamsc0f7c042017-02-23 20:41:17 -060048 elif isinstance(event, bb.build.TaskFailed):
Andrew Geissler82c905d2020-04-13 13:39:40 -050049 tid = event._fn + ":" + event._task
50 removetid(event.pid, tid)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050051 self.failed_tasks.append( { 'title' : "%s %s" % (event._package, event._task)})
Brad Bishop96ff1982019-08-19 13:50:42 -040052 elif isinstance(event, bb.runqueue.runQueueTaskStarted):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050053 self.tasknumber_current = event.stats.completed + event.stats.active + event.stats.failed + 1
54 self.tasknumber_total = event.stats.total
55 self.needUpdate = True
Patrick Williamsc0f7c042017-02-23 20:41:17 -060056 elif isinstance(event, bb.build.TaskProgress):
Andrew Geissler82c905d2020-04-13 13:39:40 -050057 if event.pid > 0 and event.pid in self.pidmap:
58 self.running_tasks[self.pidmap[event.pid]]['progress'] = event.progress
59 self.running_tasks[self.pidmap[event.pid]]['rate'] = event.rate
Patrick Williamsc0f7c042017-02-23 20:41:17 -060060 self.needUpdate = True
Brad Bishopd7bf8c12018-02-25 22:55:05 -050061 else:
62 return False
63 return True
Patrick Williamsc124f4f2015-09-15 14:41:29 -050064
65 def getTasks(self):
66 self.needUpdate = False
67 return (self.running_tasks, self.failed_tasks)