blob: c8dd7df087a2a49fb6c9eda236da24905750e6fb [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 = []
18 self.tasknumber_current = 0
19 self.tasknumber_total = 0
20
21 def eventHandler(self, event):
22 if isinstance(event, bb.build.TaskStarted):
Brad Bishop37a0e4d2017-12-04 01:01:44 -050023 if event._mc != "default":
24 self.running_tasks[event.pid] = { 'title' : "mc:%s:%s %s" % (event._mc, event._package, event._task), 'starttime' : time.time() }
25 else:
26 self.running_tasks[event.pid] = { 'title' : "%s %s" % (event._package, event._task), 'starttime' : time.time() }
Patrick Williamsc124f4f2015-09-15 14:41:29 -050027 self.running_pids.append(event.pid)
28 self.needUpdate = True
Patrick Williamsc0f7c042017-02-23 20:41:17 -060029 elif isinstance(event, bb.build.TaskSucceeded):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050030 del self.running_tasks[event.pid]
31 self.running_pids.remove(event.pid)
32 self.needUpdate = True
Patrick Williamsc0f7c042017-02-23 20:41:17 -060033 elif isinstance(event, bb.build.TaskFailedSilent):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050034 del self.running_tasks[event.pid]
35 self.running_pids.remove(event.pid)
36 # Don't add to the failed tasks list since this is e.g. a setscene task failure
37 self.needUpdate = True
Patrick Williamsc0f7c042017-02-23 20:41:17 -060038 elif isinstance(event, bb.build.TaskFailed):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050039 del self.running_tasks[event.pid]
40 self.running_pids.remove(event.pid)
41 self.failed_tasks.append( { 'title' : "%s %s" % (event._package, event._task)})
42 self.needUpdate = True
Brad Bishop96ff1982019-08-19 13:50:42 -040043 elif isinstance(event, bb.runqueue.runQueueTaskStarted):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050044 self.tasknumber_current = event.stats.completed + event.stats.active + event.stats.failed + 1
45 self.tasknumber_total = event.stats.total
46 self.needUpdate = True
Patrick Williamsc0f7c042017-02-23 20:41:17 -060047 elif isinstance(event, bb.build.TaskProgress):
48 if event.pid > 0:
49 self.running_tasks[event.pid]['progress'] = event.progress
50 self.running_tasks[event.pid]['rate'] = event.rate
51 self.needUpdate = True
Brad Bishopd7bf8c12018-02-25 22:55:05 -050052 else:
53 return False
54 return True
Patrick Williamsc124f4f2015-09-15 14:41:29 -050055
56 def getTasks(self):
57 self.needUpdate = False
58 return (self.running_tasks, self.failed_tasks)