diff options
Diffstat (limited to 'bitbake/lib/bb/ui/crumbs/runningbuild.py')
-rw-r--r-- | bitbake/lib/bb/ui/crumbs/runningbuild.py | 180 |
1 files changed, 180 insertions, 0 deletions
diff --git a/bitbake/lib/bb/ui/crumbs/runningbuild.py b/bitbake/lib/bb/ui/crumbs/runningbuild.py new file mode 100644 index 0000000000..401559255b --- /dev/null +++ b/bitbake/lib/bb/ui/crumbs/runningbuild.py | |||
@@ -0,0 +1,180 @@ | |||
1 | # | ||
2 | # BitBake Graphical GTK User Interface | ||
3 | # | ||
4 | # Copyright (C) 2008 Intel Corporation | ||
5 | # | ||
6 | # Authored by Rob Bradford <rob@linux.intel.com> | ||
7 | # | ||
8 | # This program is free software; you can redistribute it and/or modify | ||
9 | # it under the terms of the GNU General Public License version 2 as | ||
10 | # published by the Free Software Foundation. | ||
11 | # | ||
12 | # This program is distributed in the hope that it will be useful, | ||
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | # GNU General Public License for more details. | ||
16 | # | ||
17 | # You should have received a copy of the GNU General Public License along | ||
18 | # with this program; if not, write to the Free Software Foundation, Inc., | ||
19 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
20 | |||
21 | import gtk | ||
22 | import gobject | ||
23 | |||
24 | class RunningBuildModel (gtk.TreeStore): | ||
25 | (COL_TYPE, COL_PACKAGE, COL_TASK, COL_MESSAGE, COL_ICON, COL_ACTIVE) = (0, 1, 2, 3, 4, 5) | ||
26 | def __init__ (self): | ||
27 | gtk.TreeStore.__init__ (self, | ||
28 | gobject.TYPE_STRING, | ||
29 | gobject.TYPE_STRING, | ||
30 | gobject.TYPE_STRING, | ||
31 | gobject.TYPE_STRING, | ||
32 | gobject.TYPE_STRING, | ||
33 | gobject.TYPE_BOOLEAN) | ||
34 | |||
35 | class RunningBuild (gobject.GObject): | ||
36 | __gsignals__ = { | ||
37 | 'build-succeeded' : (gobject.SIGNAL_RUN_LAST, | ||
38 | gobject.TYPE_NONE, | ||
39 | ()), | ||
40 | 'build-failed' : (gobject.SIGNAL_RUN_LAST, | ||
41 | gobject.TYPE_NONE, | ||
42 | ()) | ||
43 | } | ||
44 | pids_to_task = {} | ||
45 | tasks_to_iter = {} | ||
46 | |||
47 | def __init__ (self): | ||
48 | gobject.GObject.__init__ (self) | ||
49 | self.model = RunningBuildModel() | ||
50 | |||
51 | def handle_event (self, event): | ||
52 | # Handle an event from the event queue, this may result in updating | ||
53 | # the model and thus the UI. Or it may be to tell us that the build | ||
54 | # has finished successfully (or not, as the case may be.) | ||
55 | |||
56 | parent = None | ||
57 | pid = 0 | ||
58 | package = None | ||
59 | task = None | ||
60 | |||
61 | # If we have a pid attached to this message/event try and get the | ||
62 | # (package, task) pair for it. If we get that then get the parent iter | ||
63 | # for the message. | ||
64 | if hassattr(event, 'pid'): | ||
65 | pid = event.pid | ||
66 | if self.pids_to_task.has_key(pid): | ||
67 | (package, task) = self.pids_to_task[pid] | ||
68 | parent = self.tasks_to_iter[(package, task)] | ||
69 | |||
70 | if isinstance(event, bb.msg.Msg): | ||
71 | # Set a pretty icon for the message based on it's type. | ||
72 | if isinstance(event, bb.msg.MsgWarn): | ||
73 | icon = "dialog-warning" | ||
74 | elif isinstance(event, bb.msg.MsgErr): | ||
75 | icon = "dialog-error" | ||
76 | else: | ||
77 | icon = None | ||
78 | |||
79 | # Ignore the "Running task i of n .." messages | ||
80 | if (event._message.startswith ("Running task")): | ||
81 | return | ||
82 | |||
83 | # Add the message to the tree either at the top level if parent is | ||
84 | # None otherwise as a descendent of a task. | ||
85 | self.model.append (parent, | ||
86 | (event.__name__.split()[-1], # e.g. MsgWarn, MsgError | ||
87 | package, | ||
88 | task, | ||
89 | event._message, | ||
90 | icon, | ||
91 | False)) | ||
92 | elif isinstance(event, bb.build.TaskStarted): | ||
93 | (package, task) = (event._package, event._task) | ||
94 | |||
95 | # Save out this PID. | ||
96 | self.pids_to_task[pid] = (package,task) | ||
97 | |||
98 | # Check if we already have this package in our model. If so then | ||
99 | # that can be the parent for the task. Otherwise we create a new | ||
100 | # top level for the package. | ||
101 | if (self.tasks_to_iter.has_key ((package, None))): | ||
102 | parent = self.tasks_to_iter[(package, None)] | ||
103 | else: | ||
104 | parent = self.model.append (None, (None, | ||
105 | package, | ||
106 | None, | ||
107 | "Package: %s" % (package), | ||
108 | None, | ||
109 | False)) | ||
110 | self.tasks_to_iter[(package, None)] = parent | ||
111 | |||
112 | # Because this parent package now has an active child mark it as | ||
113 | # such. | ||
114 | self.model.set(parent, self.model.COL_ICON, "gtk-execute") | ||
115 | |||
116 | # Add an entry in the model for this task | ||
117 | i = self.model.append (parent, (None, | ||
118 | package, | ||
119 | task, | ||
120 | "Task: %s" % (task), | ||
121 | None, | ||
122 | False)) | ||
123 | |||
124 | # Save out the iter so that we can find it when we have a message | ||
125 | # that we need to attach to a task. | ||
126 | self.tasks_to_iter[(package, task)] = i | ||
127 | |||
128 | # Mark this task as active. | ||
129 | self.model.set(i, self.model.COL_ICON, "gtk-execute") | ||
130 | |||
131 | elif isinstance(event, bb.build.Task): | ||
132 | |||
133 | if isinstance(event, bb.build.TaskFailed): | ||
134 | # Mark the task as failed | ||
135 | i = self.tasks_to_iter[(package, task)] | ||
136 | self.model.set(i, self.model.COL_ICON, "dialog-error") | ||
137 | |||
138 | # Mark the parent package as failed | ||
139 | i = self.tasks_to_iter[(package, None)] | ||
140 | self.model.set(i, self.model.COL_ICON, "dialog-error") | ||
141 | else: | ||
142 | # Mark the task as inactive | ||
143 | i = self.tasks_to_iter[(package, task)] | ||
144 | self.model.set(i, self.model.COL_ICON, None) | ||
145 | |||
146 | # Mark the parent package as inactive | ||
147 | i = self.tasks_to_iter[(package, None)] | ||
148 | self.model.set(i, self.model.COL_ICON, None) | ||
149 | |||
150 | |||
151 | # Clear the iters and the pids since when the task goes away the | ||
152 | # pid will no longer be used for messages | ||
153 | del self.tasks_to_iter[(package, task)] | ||
154 | del self.pids_to_task[pid] | ||
155 | |||
156 | elif isinstance(event, bb.event.BuildCompleted): | ||
157 | failures = int (event._failures) | ||
158 | |||
159 | # Emit the appropriate signal depending on the number of failures | ||
160 | if (failures > 1): | ||
161 | self.emit ("build-failed") | ||
162 | else: | ||
163 | self.emit ("build-succeeded") | ||
164 | |||
165 | class RunningBuildTreeView (gtk.TreeView): | ||
166 | def __init__ (self): | ||
167 | gtk.TreeView.__init__ (self) | ||
168 | |||
169 | # The icon that indicates whether we're building or failed. | ||
170 | renderer = gtk.CellRendererPixbuf () | ||
171 | col = gtk.TreeViewColumn ("Status", renderer) | ||
172 | col.add_attribute (renderer, "icon-name", 4) | ||
173 | self.append_column (col) | ||
174 | |||
175 | # The message of the build. | ||
176 | renderer = gtk.CellRendererText () | ||
177 | col = gtk.TreeViewColumn ("Message", renderer, text=3) | ||
178 | self.append_column (col) | ||
179 | |||
180 | |||