blob: 963c1ea2df8215650e1ff795d5b24d72bbda3554 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001# 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
20import bb.build
Patrick Williamsc0f7c042017-02-23 20:41:17 -060021import time
Patrick Williamsc124f4f2015-09-15 14:41:29 -050022
23class 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 Bishop37a0e4d2017-12-04 01:01:44 -050035 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 Williamsc124f4f2015-09-15 14:41:29 -050039 self.running_pids.append(event.pid)
40 self.needUpdate = True
Patrick Williamsc0f7c042017-02-23 20:41:17 -060041 elif isinstance(event, bb.build.TaskSucceeded):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050042 del self.running_tasks[event.pid]
43 self.running_pids.remove(event.pid)
44 self.needUpdate = True
Patrick Williamsc0f7c042017-02-23 20:41:17 -060045 elif isinstance(event, bb.build.TaskFailedSilent):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050046 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 Williamsc0f7c042017-02-23 20:41:17 -060050 elif isinstance(event, bb.build.TaskFailed):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050051 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 Williamsc0f7c042017-02-23 20:41:17 -060055 elif isinstance(event, bb.runqueue.runQueueTaskStarted) or isinstance(event, bb.runqueue.sceneQueueTaskStarted):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050056 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 Williamsc0f7c042017-02-23 20:41:17 -060059 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 Bishopd7bf8c12018-02-25 22:55:05 -050064 else:
65 return False
66 return True
Patrick Williamsc124f4f2015-09-15 14:41:29 -050067
68 def getTasks(self):
69 self.needUpdate = False
70 return (self.running_tasks, self.failed_tasks)