aboutsummaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/ui/crumbs/hobeventhandler.py
blob: 699354c610ccea286f9c7c0ec8c37a605918906b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#
# BitBake Graphical GTK User Interface
#
# Copyright (C) 2011        Intel Corporation
#
# Authored by Joshua Lock <josh@linux.intel.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

import gobject
from bb.ui.crumbs.progress import ProgressBar

progress_total = 0

class HobHandler(gobject.GObject):

    """
    This object does BitBake event handling for the hob gui.
    """
    __gsignals__ = {
         "machines-updated" : (gobject.SIGNAL_RUN_LAST,
	                       gobject.TYPE_NONE,
			       (gobject.TYPE_PYOBJECT,)),
	 "distros-updated" : (gobject.SIGNAL_RUN_LAST,
	 		      gobject.TYPE_NONE,
			      (gobject.TYPE_PYOBJECT,)),
         "generating-data" : (gobject.SIGNAL_RUN_LAST,
                              gobject.TYPE_NONE,
                              ()),
         "data-generated" : (gobject.SIGNAL_RUN_LAST,
                             gobject.TYPE_NONE,
                             ())
    }

    def __init__(self, taskmodel, server):
        gobject.GObject.__init__(self)

        self.model = taskmodel
        self.server = server
        self.current_command = None
        self.building = False

        self.command_map = {
            "findConfigFilesDistro" : ("findConfigFiles", "MACHINE", "findConfigFilesMachine"),
            "findConfigFilesMachine" : ("generateTargetsTree", "classes/image.bbclass", None),
            "generateTargetsTree"  : (None, None, None),
            }

    def run_next_command(self):
        # FIXME: this is ugly and I *will* replace it
        if self.current_command:
            next_cmd = self.command_map[self.current_command]
            command = next_cmd[0]
            argument = next_cmd[1]
            self.current_command = next_cmd[2]
            if command == "generateTargetsTree":
                self.emit("generating-data")
            self.server.runCommand([command, argument])

    def handle_event(self, event, running_build, pbar=None):
        if not event:
	    return

        # If we're running a build, use the RunningBuild event handler
        if self.building:
            running_build.handle_event(event)
        elif isinstance(event, bb.event.TargetsTreeGenerated):
            self.emit("data-generated")
            if event._model:
                self.model.populate(event._model)
                
        elif isinstance(event, bb.event.ConfigFilesFound):
            var = event._variable
	    if var == "distro":
		distros = event._values
		distros.sort()
		self.emit("distros-updated", distros)
	    elif var == "machine":
	        machines = event._values
		machines.sort()
		self.emit("machines-updated", machines)

        elif isinstance(event, bb.command.CommandCompleted):
            self.run_next_command()
        elif isinstance(event, bb.event.CacheLoadStarted) and pbar:
            pbar.set_title("Loading cache")
            bb.ui.crumbs.hobeventhandler.progress_total = event.total
            pbar.update(0, bb.ui.crumbs.hobeventhandler.progress_total)
        elif isinstance(event, bb.event.CacheLoadProgress) and pbar:
            pbar.update(event.current, bb.ui.crumbs.hobeventhandler.progress_total)
        elif isinstance(event, bb.event.CacheLoadCompleted) and pbar:
            pbar.update(bb.ui.crumbs.hobeventhandler.progress_total, bb.ui.crumbs.hobeventhandler.progress_total)
        elif isinstance(event, bb.event.ParseStarted) and pbar:
            pbar.set_title("Processing recipes")
            bb.ui.crumbs.hobeventhandler.progress_total = event.total
            pbar.update(0, bb.ui.crumbs.hobeventhandler.progress_total)
        elif isinstance(event, bb.event.ParseProgress) and pbar:
            pbar.update(event.current, bb.ui.crumbs.hobeventhandler.progress_total)
        elif isinstance(event, bb.event.ParseCompleted) and pbar:
            pbar.hide()
            
        return

    def event_handle_idle_func (self, eventHandler, running_build, pbar):
        # Consume as many messages as we can in the time available to us
        event = eventHandler.getEvent()
        while event:
            self.handle_event(event, running_build, pbar)
            event = eventHandler.getEvent()
        return True

    def set_machine(self, machine):
        self.server.runCommand(["setVariable", "MACHINE", machine])
        self.current_command = "findConfigFilesMachine"
        self.emit("generating-data")
        self.run_next_command()

    def set_distro(self, distro):
        self.server.runCommand(["setVariable", "DISTRO", distro])

    def run_build(self, targets):
        self.building = True
        self.server.runCommand(["buildTargets", targets, "build"])

    def cancel_build(self):
        # Note: this may not be the right way to stop an in-progress build
        self.server.runCommand(["stateStop"])