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 = [] |
| 18 | self.tasknumber_current = 0 |
| 19 | self.tasknumber_total = 0 |
| 20 | |
| 21 | def eventHandler(self, event): |
| 22 | if isinstance(event, bb.build.TaskStarted): |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 23 | 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 27 | self.running_pids.append(event.pid) |
| 28 | self.needUpdate = True |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 29 | elif isinstance(event, bb.build.TaskSucceeded): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 30 | del self.running_tasks[event.pid] |
| 31 | self.running_pids.remove(event.pid) |
| 32 | self.needUpdate = True |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 33 | elif isinstance(event, bb.build.TaskFailedSilent): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 34 | 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 Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 38 | elif isinstance(event, bb.build.TaskFailed): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 39 | 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 Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame^] | 43 | elif isinstance(event, bb.runqueue.runQueueTaskStarted): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 44 | 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 Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 47 | 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 Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 52 | else: |
| 53 | return False |
| 54 | return True |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 55 | |
| 56 | def getTasks(self): |
| 57 | self.needUpdate = False |
| 58 | return (self.running_tasks, self.failed_tasks) |