diff options
Diffstat (limited to 'bitbake/lib/bb/ui/uihelper.py')
-rw-r--r-- | bitbake/lib/bb/ui/uihelper.py | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/bitbake/lib/bb/ui/uihelper.py b/bitbake/lib/bb/ui/uihelper.py new file mode 100644 index 0000000000..a703387fb8 --- /dev/null +++ b/bitbake/lib/bb/ui/uihelper.py | |||
@@ -0,0 +1,100 @@ | |||
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 | |||
60 | def findServerDetails(self): | ||
61 | import sys | ||
62 | import optparse | ||
63 | from bb.server.xmlrpc import BitbakeServerInfo, BitBakeServerConnection | ||
64 | host = "" | ||
65 | port = 0 | ||
66 | bind = "" | ||
67 | parser = optparse.OptionParser( | ||
68 | usage = """%prog -H host -P port -B bindaddr""") | ||
69 | |||
70 | parser.add_option("-H", "--host", help = "Bitbake server's IP address", | ||
71 | action = "store", dest = "host", default = None) | ||
72 | |||
73 | parser.add_option("-P", "--port", help = "Bitbake server's Port number", | ||
74 | action = "store", dest = "port", default = None) | ||
75 | |||
76 | parser.add_option("-B", "--bind", help = "Hob2 local bind address", | ||
77 | action = "store", dest = "bind", default = None) | ||
78 | |||
79 | options, args = parser.parse_args(sys.argv) | ||
80 | for key, val in options.__dict__.items(): | ||
81 | if key == 'host' and val: | ||
82 | host = val | ||
83 | elif key == 'port' and val: | ||
84 | port = int(val) | ||
85 | elif key == 'bind' and val: | ||
86 | bind = val | ||
87 | |||
88 | if not host or not port or not bind: | ||
89 | parser.print_usage() | ||
90 | sys.exit(1) | ||
91 | |||
92 | serverinfo = BitbakeServerInfo(host, port) | ||
93 | clientinfo = (bind, 0) | ||
94 | connection = BitBakeServerConnection(serverinfo, clientinfo) | ||
95 | |||
96 | server = connection.connection | ||
97 | eventHandler = connection.events | ||
98 | |||
99 | return server, eventHandler, host, bind | ||
100 | |||