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 |
| 21 | |
| 22 | class BBUIHelper: |
| 23 | def __init__(self): |
| 24 | self.needUpdate = False |
| 25 | self.running_tasks = {} |
| 26 | # Running PIDs preserves the order tasks were executed in |
| 27 | self.running_pids = [] |
| 28 | self.failed_tasks = [] |
| 29 | self.tasknumber_current = 0 |
| 30 | self.tasknumber_total = 0 |
| 31 | |
| 32 | def eventHandler(self, event): |
| 33 | if isinstance(event, bb.build.TaskStarted): |
| 34 | self.running_tasks[event.pid] = { 'title' : "%s %s" % (event._package, event._task) } |
| 35 | self.running_pids.append(event.pid) |
| 36 | self.needUpdate = True |
| 37 | if isinstance(event, bb.build.TaskSucceeded): |
| 38 | del self.running_tasks[event.pid] |
| 39 | self.running_pids.remove(event.pid) |
| 40 | self.needUpdate = True |
| 41 | if isinstance(event, bb.build.TaskFailedSilent): |
| 42 | del self.running_tasks[event.pid] |
| 43 | self.running_pids.remove(event.pid) |
| 44 | # Don't add to the failed tasks list since this is e.g. a setscene task failure |
| 45 | self.needUpdate = True |
| 46 | if isinstance(event, bb.build.TaskFailed): |
| 47 | del self.running_tasks[event.pid] |
| 48 | self.running_pids.remove(event.pid) |
| 49 | self.failed_tasks.append( { 'title' : "%s %s" % (event._package, event._task)}) |
| 50 | self.needUpdate = True |
| 51 | if isinstance(event, bb.runqueue.runQueueTaskStarted) or isinstance(event, bb.runqueue.sceneQueueTaskStarted): |
| 52 | self.tasknumber_current = event.stats.completed + event.stats.active + event.stats.failed + 1 |
| 53 | self.tasknumber_total = event.stats.total |
| 54 | self.needUpdate = True |
| 55 | |
| 56 | def getTasks(self): |
| 57 | self.needUpdate = False |
| 58 | return (self.running_tasks, self.failed_tasks) |
| 59 | |