Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | # ex:ts=4:sw=4:sts=4:et |
| 2 | # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- |
| 3 | # |
| 4 | # Copyright (C) 2006 - 2007 Michael 'Mickey' Lauer |
| 5 | # Copyright (C) 2006 - 2007 Richard Purdie |
| 6 | # |
| 7 | # This program is free software; you can redistribute it and/or modify |
| 8 | # it under the terms of the GNU General Public License version 2 as |
| 9 | # published by the Free Software Foundation. |
| 10 | # |
| 11 | # This program is distributed in the hope that it will be useful, |
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | # GNU General Public License for more details. |
| 15 | # |
| 16 | # You should have received a copy of the GNU General Public License along |
| 17 | # with this program; if not, write to the Free Software Foundation, Inc., |
| 18 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 | |
| 20 | import bb.build |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 21 | import time |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 22 | |
| 23 | class BBUIHelper: |
| 24 | def __init__(self): |
| 25 | self.needUpdate = False |
| 26 | self.running_tasks = {} |
| 27 | # Running PIDs preserves the order tasks were executed in |
| 28 | self.running_pids = [] |
| 29 | self.failed_tasks = [] |
| 30 | self.tasknumber_current = 0 |
| 31 | self.tasknumber_total = 0 |
| 32 | |
| 33 | def eventHandler(self, event): |
| 34 | if isinstance(event, bb.build.TaskStarted): |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 35 | if event._mc != "default": |
| 36 | self.running_tasks[event.pid] = { 'title' : "mc:%s:%s %s" % (event._mc, event._package, event._task), 'starttime' : time.time() } |
| 37 | else: |
| 38 | 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] | 39 | self.running_pids.append(event.pid) |
| 40 | self.needUpdate = True |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 41 | elif isinstance(event, bb.build.TaskSucceeded): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 42 | del self.running_tasks[event.pid] |
| 43 | self.running_pids.remove(event.pid) |
| 44 | self.needUpdate = True |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 45 | elif isinstance(event, bb.build.TaskFailedSilent): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 46 | del self.running_tasks[event.pid] |
| 47 | self.running_pids.remove(event.pid) |
| 48 | # Don't add to the failed tasks list since this is e.g. a setscene task failure |
| 49 | self.needUpdate = True |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 50 | elif isinstance(event, bb.build.TaskFailed): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 51 | del self.running_tasks[event.pid] |
| 52 | self.running_pids.remove(event.pid) |
| 53 | self.failed_tasks.append( { 'title' : "%s %s" % (event._package, event._task)}) |
| 54 | self.needUpdate = True |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 55 | elif isinstance(event, bb.runqueue.runQueueTaskStarted) or isinstance(event, bb.runqueue.sceneQueueTaskStarted): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 56 | self.tasknumber_current = event.stats.completed + event.stats.active + event.stats.failed + 1 |
| 57 | self.tasknumber_total = event.stats.total |
| 58 | self.needUpdate = True |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 59 | elif isinstance(event, bb.build.TaskProgress): |
| 60 | if event.pid > 0: |
| 61 | self.running_tasks[event.pid]['progress'] = event.progress |
| 62 | self.running_tasks[event.pid]['rate'] = event.rate |
| 63 | self.needUpdate = True |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 64 | else: |
| 65 | return False |
| 66 | return True |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 67 | |
| 68 | def getTasks(self): |
| 69 | self.needUpdate = False |
| 70 | return (self.running_tasks, self.failed_tasks) |