blob: 82913e0da836de0ab481bb19b4f622dc4a806be9 [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)})
Andrew Geissler5199d832021-09-24 16:47:35 -050052 elif isinstance(event, bb.runqueue.runQueueTaskStarted) or isinstance(event, bb.runqueue.sceneQueueTaskStarted):
Andrew Geisslereff27472021-10-29 15:35:00 -050053 self.tasknumber_current = event.stats.completed + event.stats.active + event.stats.failed
Patrick Williamsc124f4f2015-09-15 14:41:29 -050054 self.tasknumber_total = event.stats.total
Andrew Geisslereff27472021-10-29 15:35:00 -050055 self.setscene_current = event.stats.setscene_active + event.stats.setscene_covered + event.stats.setscene_notcovered
56 self.setscene_total = event.stats.setscene_total
Patrick Williamsc124f4f2015-09-15 14:41:29 -050057 self.needUpdate = True
Patrick Williamsc0f7c042017-02-23 20:41:17 -060058 elif isinstance(event, bb.build.TaskProgress):
Andrew Geissler82c905d2020-04-13 13:39:40 -050059 if event.pid > 0 and event.pid in self.pidmap:
60 self.running_tasks[self.pidmap[event.pid]]['progress'] = event.progress
61 self.running_tasks[self.pidmap[event.pid]]['rate'] = event.rate
Patrick Williamsc0f7c042017-02-23 20:41:17 -060062 self.needUpdate = True
Brad Bishopd7bf8c12018-02-25 22:55:05 -050063 else:
64 return False
65 return True
Patrick Williamsc124f4f2015-09-15 14:41:29 -050066
67 def getTasks(self):
68 self.needUpdate = False
69 return (self.running_tasks, self.failed_tasks)