1# 2# Copyright (C) 2006 - 2007 Michael 'Mickey' Lauer 3# Copyright (C) 2006 - 2007 Richard Purdie 4# 5# SPDX-License-Identifier: GPL-2.0-only 6# 7 8import bb.build 9import time 10 11class 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.pidmap = {} 19 self.tasknumber_current = 0 20 self.tasknumber_total = 0 21 22 def eventHandler(self, event): 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 32 if isinstance(event, bb.build.TaskStarted): 33 tid = event._fn + ":" + event._task 34 if event._mc != "default": 35 self.running_tasks[tid] = { 'title' : "mc:%s:%s %s" % (event._mc, event._package, event._task), 'starttime' : time.time(), 'pid' : event.pid } 36 else: 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 40 self.needUpdate = True 41 elif isinstance(event, bb.build.TaskSucceeded): 42 tid = event._fn + ":" + event._task 43 removetid(event.pid, tid) 44 elif isinstance(event, bb.build.TaskFailedSilent): 45 tid = event._fn + ":" + event._task 46 removetid(event.pid, tid) 47 # Don't add to the failed tasks list since this is e.g. a setscene task failure 48 elif isinstance(event, bb.build.TaskFailed): 49 tid = event._fn + ":" + event._task 50 removetid(event.pid, tid) 51 self.failed_tasks.append( { 'title' : "%s %s" % (event._package, event._task)}) 52 elif isinstance(event, bb.runqueue.runQueueTaskStarted) or isinstance(event, bb.runqueue.sceneQueueTaskStarted): 53 self.tasknumber_current = event.stats.completed + event.stats.active + event.stats.failed + event.stats.setscene_active + 1 54 self.tasknumber_total = event.stats.total 55 self.needUpdate = True 56 elif isinstance(event, bb.build.TaskProgress): 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 60 self.needUpdate = True 61 else: 62 return False 63 return True 64 65 def getTasks(self): 66 self.needUpdate = False 67 return (self.running_tasks, self.failed_tasks) 68