diff options
Diffstat (limited to 'bitbake/lib/bb/ui/crumbs/hobeventhandler.py')
| -rw-r--r-- | bitbake/lib/bb/ui/crumbs/hobeventhandler.py | 138 |
1 files changed, 138 insertions, 0 deletions
diff --git a/bitbake/lib/bb/ui/crumbs/hobeventhandler.py b/bitbake/lib/bb/ui/crumbs/hobeventhandler.py new file mode 100644 index 0000000000..699354c610 --- /dev/null +++ b/bitbake/lib/bb/ui/crumbs/hobeventhandler.py | |||
| @@ -0,0 +1,138 @@ | |||
| 1 | # | ||
| 2 | # BitBake Graphical GTK User Interface | ||
| 3 | # | ||
| 4 | # Copyright (C) 2011 Intel Corporation | ||
| 5 | # | ||
| 6 | # Authored by Joshua Lock <josh@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 | from bb.ui.crumbs.progress import ProgressBar | ||
| 23 | |||
| 24 | progress_total = 0 | ||
| 25 | |||
| 26 | class HobHandler(gobject.GObject): | ||
| 27 | |||
| 28 | """ | ||
| 29 | This object does BitBake event handling for the hob gui. | ||
| 30 | """ | ||
| 31 | __gsignals__ = { | ||
| 32 | "machines-updated" : (gobject.SIGNAL_RUN_LAST, | ||
| 33 | gobject.TYPE_NONE, | ||
| 34 | (gobject.TYPE_PYOBJECT,)), | ||
| 35 | "distros-updated" : (gobject.SIGNAL_RUN_LAST, | ||
| 36 | gobject.TYPE_NONE, | ||
| 37 | (gobject.TYPE_PYOBJECT,)), | ||
| 38 | "generating-data" : (gobject.SIGNAL_RUN_LAST, | ||
| 39 | gobject.TYPE_NONE, | ||
| 40 | ()), | ||
| 41 | "data-generated" : (gobject.SIGNAL_RUN_LAST, | ||
| 42 | gobject.TYPE_NONE, | ||
| 43 | ()) | ||
| 44 | } | ||
| 45 | |||
| 46 | def __init__(self, taskmodel, server): | ||
| 47 | gobject.GObject.__init__(self) | ||
| 48 | |||
| 49 | self.model = taskmodel | ||
| 50 | self.server = server | ||
| 51 | self.current_command = None | ||
| 52 | self.building = False | ||
| 53 | |||
| 54 | self.command_map = { | ||
| 55 | "findConfigFilesDistro" : ("findConfigFiles", "MACHINE", "findConfigFilesMachine"), | ||
| 56 | "findConfigFilesMachine" : ("generateTargetsTree", "classes/image.bbclass", None), | ||
| 57 | "generateTargetsTree" : (None, None, None), | ||
| 58 | } | ||
| 59 | |||
| 60 | def run_next_command(self): | ||
| 61 | # FIXME: this is ugly and I *will* replace it | ||
| 62 | if self.current_command: | ||
| 63 | next_cmd = self.command_map[self.current_command] | ||
| 64 | command = next_cmd[0] | ||
| 65 | argument = next_cmd[1] | ||
| 66 | self.current_command = next_cmd[2] | ||
| 67 | if command == "generateTargetsTree": | ||
| 68 | self.emit("generating-data") | ||
| 69 | self.server.runCommand([command, argument]) | ||
| 70 | |||
| 71 | def handle_event(self, event, running_build, pbar=None): | ||
| 72 | if not event: | ||
| 73 | return | ||
| 74 | |||
| 75 | # If we're running a build, use the RunningBuild event handler | ||
| 76 | if self.building: | ||
| 77 | running_build.handle_event(event) | ||
| 78 | elif isinstance(event, bb.event.TargetsTreeGenerated): | ||
| 79 | self.emit("data-generated") | ||
| 80 | if event._model: | ||
| 81 | self.model.populate(event._model) | ||
| 82 | |||
| 83 | elif isinstance(event, bb.event.ConfigFilesFound): | ||
| 84 | var = event._variable | ||
| 85 | if var == "distro": | ||
| 86 | distros = event._values | ||
| 87 | distros.sort() | ||
| 88 | self.emit("distros-updated", distros) | ||
| 89 | elif var == "machine": | ||
| 90 | machines = event._values | ||
| 91 | machines.sort() | ||
| 92 | self.emit("machines-updated", machines) | ||
| 93 | |||
| 94 | elif isinstance(event, bb.command.CommandCompleted): | ||
| 95 | self.run_next_command() | ||
| 96 | elif isinstance(event, bb.event.CacheLoadStarted) and pbar: | ||
| 97 | pbar.set_title("Loading cache") | ||
| 98 | bb.ui.crumbs.hobeventhandler.progress_total = event.total | ||
| 99 | pbar.update(0, bb.ui.crumbs.hobeventhandler.progress_total) | ||
| 100 | elif isinstance(event, bb.event.CacheLoadProgress) and pbar: | ||
| 101 | pbar.update(event.current, bb.ui.crumbs.hobeventhandler.progress_total) | ||
| 102 | elif isinstance(event, bb.event.CacheLoadCompleted) and pbar: | ||
| 103 | pbar.update(bb.ui.crumbs.hobeventhandler.progress_total, bb.ui.crumbs.hobeventhandler.progress_total) | ||
| 104 | elif isinstance(event, bb.event.ParseStarted) and pbar: | ||
| 105 | pbar.set_title("Processing recipes") | ||
| 106 | bb.ui.crumbs.hobeventhandler.progress_total = event.total | ||
| 107 | pbar.update(0, bb.ui.crumbs.hobeventhandler.progress_total) | ||
| 108 | elif isinstance(event, bb.event.ParseProgress) and pbar: | ||
| 109 | pbar.update(event.current, bb.ui.crumbs.hobeventhandler.progress_total) | ||
| 110 | elif isinstance(event, bb.event.ParseCompleted) and pbar: | ||
| 111 | pbar.hide() | ||
| 112 | |||
| 113 | return | ||
| 114 | |||
| 115 | def event_handle_idle_func (self, eventHandler, running_build, pbar): | ||
| 116 | # Consume as many messages as we can in the time available to us | ||
| 117 | event = eventHandler.getEvent() | ||
| 118 | while event: | ||
| 119 | self.handle_event(event, running_build, pbar) | ||
| 120 | event = eventHandler.getEvent() | ||
| 121 | return True | ||
| 122 | |||
| 123 | def set_machine(self, machine): | ||
| 124 | self.server.runCommand(["setVariable", "MACHINE", machine]) | ||
| 125 | self.current_command = "findConfigFilesMachine" | ||
| 126 | self.emit("generating-data") | ||
| 127 | self.run_next_command() | ||
| 128 | |||
| 129 | def set_distro(self, distro): | ||
| 130 | self.server.runCommand(["setVariable", "DISTRO", distro]) | ||
| 131 | |||
| 132 | def run_build(self, targets): | ||
| 133 | self.building = True | ||
| 134 | self.server.runCommand(["buildTargets", targets, "build"]) | ||
| 135 | |||
| 136 | def cancel_build(self): | ||
| 137 | # Note: this may not be the right way to stop an in-progress build | ||
| 138 | self.server.runCommand(["stateStop"]) | ||
