diff options
| -rw-r--r-- | bitbake-dev/lib/bb/ui/goggle.py | 222 |
1 files changed, 222 insertions, 0 deletions
diff --git a/bitbake-dev/lib/bb/ui/goggle.py b/bitbake-dev/lib/bb/ui/goggle.py new file mode 100644 index 0000000000..651a0449b0 --- /dev/null +++ b/bitbake-dev/lib/bb/ui/goggle.py | |||
| @@ -0,0 +1,222 @@ | |||
| 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 gobject | ||
| 22 | import gtk | ||
| 23 | import threading | ||
| 24 | import bb.ui.uihelper | ||
| 25 | |||
| 26 | def event_handle_idle_func (eventHandler, build): | ||
| 27 | |||
| 28 | # Consume as many messages as we can in the time available to us | ||
| 29 | event = eventHandler.getEvent() | ||
| 30 | while event: | ||
| 31 | build.handle_event (event) | ||
| 32 | event = eventHandler.getEvent() | ||
| 33 | |||
| 34 | return True | ||
| 35 | |||
| 36 | class RunningBuildModel (gtk.TreeStore): | ||
| 37 | (COL_TYPE, COL_PACKAGE, COL_TASK, COL_MESSAGE, COL_ICON, COL_ACTIVE) = (0, 1, 2, 3, 4, 5) | ||
| 38 | def __init__ (self): | ||
| 39 | gtk.TreeStore.__init__ (self, | ||
| 40 | gobject.TYPE_STRING, | ||
| 41 | gobject.TYPE_STRING, | ||
| 42 | gobject.TYPE_STRING, | ||
| 43 | gobject.TYPE_STRING, | ||
| 44 | gobject.TYPE_STRING, | ||
| 45 | gobject.TYPE_BOOLEAN) | ||
| 46 | |||
| 47 | class RunningBuild (gobject.GObject): | ||
| 48 | __gsignals__ = { | ||
| 49 | 'build-finished' : (gobject.SIGNAL_RUN_LAST, | ||
| 50 | gobject.TYPE_NONE, | ||
| 51 | ()) | ||
| 52 | } | ||
| 53 | pids_to_task = {} | ||
| 54 | tasks_to_iter = {} | ||
| 55 | |||
| 56 | def __init__ (self): | ||
| 57 | gobject.GObject.__init__ (self) | ||
| 58 | self.model = RunningBuildModel() | ||
| 59 | |||
| 60 | def handle_event (self, event): | ||
| 61 | # Handle an event from the event queue, this may result in updating | ||
| 62 | # the model and thus the UI. Or it may be to tell us that the build | ||
| 63 | # has finished successfully (or not, as the case may be.) | ||
| 64 | |||
| 65 | parent = None | ||
| 66 | pid = 0 | ||
| 67 | package = None | ||
| 68 | task = None | ||
| 69 | |||
| 70 | # If we have a pid attached to this message/event try and get the | ||
| 71 | # (package, task) pair for it. If we get that then get the parent iter | ||
| 72 | # for the message. | ||
| 73 | if event[1].has_key ('pid'): | ||
| 74 | pid = event[1]['pid'] | ||
| 75 | if self.pids_to_task.has_key(pid): | ||
| 76 | (package, task) = self.pids_to_task[pid] | ||
| 77 | parent = self.tasks_to_iter[(package, task)] | ||
| 78 | |||
| 79 | if event[0].startswith('bb.msg.Msg'): | ||
| 80 | # Set a pretty icon for the message based on it's type. | ||
| 81 | if (event[0].startswith ('bb.msg.MsgWarn')): | ||
| 82 | icon = "dialog-warning" | ||
| 83 | elif (event[0].startswith ('bb.msg.MsgErr')): | ||
| 84 | icon = "dialog-error" | ||
| 85 | else: | ||
| 86 | icon = None | ||
| 87 | |||
| 88 | # Ignore the "Running task i of n .." messages | ||
| 89 | if (event[1]['_message'].startswith ("Running task")): | ||
| 90 | return | ||
| 91 | |||
| 92 | # Add the message to the tree either at the top level if parent is | ||
| 93 | # None otherwise as a descendent of a task. | ||
| 94 | self.model.append (parent, | ||
| 95 | (event[0].split()[-1], # e.g. MsgWarn, MsgError | ||
| 96 | package, | ||
| 97 | task, | ||
| 98 | event[1]['_message'], | ||
| 99 | icon, | ||
| 100 | False)) | ||
| 101 | elif event[0].startswith('bb.build.TaskStarted'): | ||
| 102 | (package, task) = (event[1]['_package'], event[1]['_task']) | ||
| 103 | |||
| 104 | # Save out this PID. | ||
| 105 | self.pids_to_task[pid] = (package,task) | ||
| 106 | |||
| 107 | # Check if we already have this package in our model. If so then | ||
| 108 | # that can be the parent for the task. Otherwise we create a new | ||
| 109 | # top level for the package. | ||
| 110 | if (self.tasks_to_iter.has_key ((package, None))): | ||
| 111 | parent = self.tasks_to_iter[(package, None)] | ||
| 112 | else: | ||
| 113 | parent = self.model.append (None, (None, | ||
| 114 | package, | ||
| 115 | None, | ||
| 116 | "Package: %s" % (package), | ||
| 117 | None, | ||
| 118 | False)) | ||
| 119 | self.tasks_to_iter[(package, None)] = parent | ||
| 120 | |||
| 121 | # Because this parent package now has an active child mark it as | ||
| 122 | # such. | ||
| 123 | self.model.set(parent, self.model.COL_ICON, "gtk-execute") | ||
| 124 | |||
| 125 | # Add an entry in the model for this task | ||
| 126 | i = self.model.append (parent, (None, | ||
| 127 | package, | ||
| 128 | task, | ||
| 129 | "Task: %s" % (task), | ||
| 130 | None, | ||
| 131 | False)) | ||
| 132 | |||
| 133 | # Save out the iter so that we can find it when we have a message | ||
| 134 | # that we need to attach to a task. | ||
| 135 | self.tasks_to_iter[(package, task)] = i | ||
| 136 | |||
| 137 | # Mark this task as active. | ||
| 138 | self.model.set(i, self.model.COL_ICON, "gtk-execute") | ||
| 139 | |||
| 140 | elif event[0].startswith('bb.build.Task'): | ||
| 141 | |||
| 142 | if event[0].startswith('bb.build.TaskFailed'): | ||
| 143 | # Mark the task as failed | ||
| 144 | i = self.tasks_to_iter[(package, task)] | ||
| 145 | self.model.set(i, self.model.COL_ICON, "dialog-error") | ||
| 146 | |||
| 147 | # Mark the parent package as failed | ||
| 148 | i = self.tasks_to_iter[(package, None)] | ||
| 149 | self.model.set(i, self.model.COL_ICON, "dialog-error") | ||
| 150 | else: | ||
| 151 | # Mark the task as inactive | ||
| 152 | i = self.tasks_to_iter[(package, task)] | ||
| 153 | self.model.set(i, self.model.COL_ICON, None) | ||
| 154 | |||
| 155 | # Mark the parent package as inactive | ||
| 156 | i = self.tasks_to_iter[(package, None)] | ||
| 157 | self.model.set(i, self.model.COL_ICON, None) | ||
| 158 | |||
| 159 | |||
| 160 | # Clear the iters and the pids since when the task goes away the | ||
| 161 | # pid will no longer be used for messages | ||
| 162 | del self.tasks_to_iter[(package, task)] | ||
| 163 | del self.pids_to_task[pid] | ||
| 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 | |||
| 181 | class MainWindow (gtk.Window): | ||
| 182 | def __init__ (self): | ||
| 183 | gtk.Window.__init__ (self, gtk.WINDOW_TOPLEVEL) | ||
| 184 | |||
| 185 | # Setup tree view and the scrolled window | ||
| 186 | scrolled_window = gtk.ScrolledWindow () | ||
| 187 | self.add (scrolled_window) | ||
| 188 | self.cur_build_tv = RunningBuildTreeView() | ||
| 189 | scrolled_window.add (self.cur_build_tv) | ||
| 190 | |||
| 191 | def init (server, eventHandler): | ||
| 192 | gobject.threads_init() | ||
| 193 | gtk.gdk.threads_init() | ||
| 194 | |||
| 195 | window = MainWindow () | ||
| 196 | window.show_all () | ||
| 197 | |||
| 198 | # Create the object for the current build | ||
| 199 | running_build = RunningBuild () | ||
| 200 | window.cur_build_tv.set_model (running_build.model) | ||
| 201 | try: | ||
| 202 | cmdline = server.runCommand(["getCmdLineAction"]) | ||
| 203 | print cmdline | ||
| 204 | if not cmdline: | ||
| 205 | return 1 | ||
| 206 | ret = server.runCommand(cmdline) | ||
| 207 | if ret != True: | ||
| 208 | print "Couldn't get default commandline! %s" % ret | ||
| 209 | return 1 | ||
| 210 | except xmlrpclib.Fault, x: | ||
| 211 | print "XMLRPC Fault getting commandline:\n %s" % x | ||
| 212 | return 1 | ||
| 213 | |||
| 214 | # Use a timeout function for probing the event queue to find out if we | ||
| 215 | # have a message waiting for us. | ||
| 216 | gobject.timeout_add (200, | ||
| 217 | event_handle_idle_func, | ||
| 218 | eventHandler, | ||
| 219 | running_build) | ||
| 220 | |||
| 221 | gtk.main() | ||
| 222 | |||
