Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | # |
| 2 | # Copyright (C) 2006 - 2007 Michael 'Mickey' Lauer |
| 3 | # Copyright (C) 2006 - 2007 Richard Purdie |
| 4 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 5 | # SPDX-License-Identifier: GPL-2.0-only |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 6 | # |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7 | |
| 8 | import bb.build |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 9 | import time |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 10 | |
| 11 | class 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 Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 18 | self.pidmap = {} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 19 | self.tasknumber_current = 0 |
| 20 | self.tasknumber_total = 0 |
| 21 | |
| 22 | def eventHandler(self, event): |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 23 | # 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 32 | if isinstance(event, bb.build.TaskStarted): |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 33 | tid = event._fn + ":" + event._task |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 34 | if event._mc != "default": |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 35 | self.running_tasks[tid] = { 'title' : "mc:%s:%s %s" % (event._mc, event._package, event._task), 'starttime' : time.time(), 'pid' : event.pid } |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 36 | else: |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 37 | 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 40 | self.needUpdate = True |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 41 | elif isinstance(event, bb.build.TaskSucceeded): |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 42 | tid = event._fn + ":" + event._task |
| 43 | removetid(event.pid, tid) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 44 | elif isinstance(event, bb.build.TaskFailedSilent): |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 45 | tid = event._fn + ":" + event._task |
| 46 | removetid(event.pid, tid) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 47 | # Don't add to the failed tasks list since this is e.g. a setscene task failure |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 48 | elif isinstance(event, bb.build.TaskFailed): |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 49 | tid = event._fn + ":" + event._task |
| 50 | removetid(event.pid, tid) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 51 | self.failed_tasks.append( { 'title' : "%s %s" % (event._package, event._task)}) |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 52 | elif isinstance(event, bb.runqueue.runQueueTaskStarted): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 53 | 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 Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 56 | elif isinstance(event, bb.build.TaskProgress): |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 57 | 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 Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 60 | self.needUpdate = True |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 61 | else: |
| 62 | return False |
| 63 | return True |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 64 | |
| 65 | def getTasks(self): |
| 66 | self.needUpdate = False |
| 67 | return (self.running_tasks, self.failed_tasks) |