ui/hob: replace the ugly static command map

The command_map was never a good idea, what's implemented here is a
fraction less ugly but a significant factor more readable and therefore
easy to maintain.
The method implemented in this patch also has the advantage of not being
static meaning we can determine the desired runCommand arguments
dynamically at call time.

(Bitbake rev: 8b11c68ffcda355d0ba49cfc27790d245192ae24)

Signed-off-by: Joshua Lock <josh@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Joshua Lock 2011-07-13 16:01:43 -07:00 committed by Richard Purdie
parent f7233d7612
commit 5c3f42dbcf
2 changed files with 35 additions and 27 deletions

View File

@ -61,8 +61,11 @@ class HobHandler(gobject.GObject):
gobject.TYPE_STRING)),
}
(CFG_PATH_LOCAL, CFG_PATH_HOB, CFG_PATH_LAYERS, CFG_FILES_DISTRO, CFG_FILES_MACH, CFG_FILES_SDK, FILES_MATCH_CLASS, GENERATE_TGTS) = range(8)
def __init__(self, taskmodel, server):
gobject.GObject.__init__(self)
self.current_command = None
self.building = None
self.gplv3_excluded = False
@ -76,30 +79,37 @@ class HobHandler(gobject.GObject):
self.image_output_types = self.server.runCommand(["getVariable", "IMAGE_FSTYPES"]).split(" ")
self.command_map = {
"findConfigFilePathLocal" : ("findConfigFilePath", ["hob.local.conf"], "findConfigFilePathHobLocal"),
"findConfigFilePathHobLocal" : ("findConfigFilePath", ["bblayers.conf"], "findConfigFilePathLayers"),
"findConfigFilePathLayers" : ("findConfigFiles", ["DISTRO"], "findConfigFilesDistro"),
"findConfigFilesDistro" : ("findConfigFiles", ["MACHINE"], "findConfigFilesMachine"),
"findConfigFilesMachine" : ("findConfigFiles", ["MACHINE-SDK"], "findConfigFilesSdkMachine"),
"findConfigFilesSdkMachine" : ("findFilesMatchingInDir", ["rootfs_", "classes"], "findFilesMatchingPackage"),
"findFilesMatchingPackage" : ("generateTargetsTree", ["classes/image.bbclass"], None),
"generateTargetsTree" : (None, [], None),
}
def run_next_command(self):
# FIXME: this is ugly and I *will* replace it
if self.current_command:
if not self.generating:
self.emit("generating-data")
self.generating = True
next_cmd = self.command_map[self.current_command]
command = next_cmd[0]
argument = next_cmd[1]
self.current_command = next_cmd[2]
args = [command]
args.extend(argument)
self.server.runCommand(args)
if self.current_command and not self.generating:
self.emit("generating-data")
self.generating = True
if self.current_command == self.CFG_PATH_LOCAL:
self.current_command = self.CFG_PATH_HOB
self.server.runCommand(["findConfigFilePath", "hob.local.conf"])
elif self.current_command == self.CFG_PATH_HOB:
self.current_command = self.CFG_PATH_LAYERS
self.server.runCommand(["findConfigFilePath", "bblayers.conf"])
elif self.current_command == self.CFG_PATH_LAYERS:
self.current_command = self.CFG_FILES_DISTRO
self.server.runCommand(["findConfigFiles", "DISTRO"])
elif self.current_command == self.CFG_FILES_DISTRO:
self.current_command = self.CFG_FILES_MACH
self.server.runCommand(["findConfigFiles", "MACHINE"])
elif self.current_command == self.CFG_FILES_MACH:
self.current_command = self.CFG_FILES_SDK
self.server.runCommand(["findConfigFiles", "MACHINE-SDK"])
elif self.current_command == self.CFG_FILES_SDK:
self.current_command = self.FILES_MATCH_CLASS
self.server.runCommand(["findFilesMatchingInDir", "rootfs_", "classes"])
elif self.current_command == self.FILES_MATCH_CLASS:
self.current_command = self.GENERATE_TGTS
self.server.runCommand(["generateTargetsTree", "classes/image.bbclass"])
elif self.current_command == self.GENERATE_TGTS:
if self.generating:
self.emit("data-generated")
self.generating = False
self.current_command = None
def handle_event(self, event, running_build, pbar):
if not event:
@ -109,8 +119,6 @@ class HobHandler(gobject.GObject):
if self.building:
running_build.handle_event(event)
elif isinstance(event, bb.event.TargetsTreeGenerated):
self.emit("data-generated")
self.generating = False
if event._model:
self.model.populate(event._model)
elif isinstance(event, bb.event.ConfigFilesFound):
@ -188,7 +196,7 @@ class HobHandler(gobject.GObject):
selected_packages, _ = self.model.get_selected_packages()
self.emit("reload-triggered", img, " ".join(selected_packages))
self.server.runCommand(["reparseFiles"])
self.current_command = "findConfigFilePathLayers"
self.current_command = self.CFG_PATH_LAYERS
self.run_next_command()
def set_bbthreads(self, threads):

View File

@ -929,7 +929,7 @@ def main (server, eventHandler):
try:
# kick the while thing off
handler.current_command = "findConfigFilePathLocal"
handler.current_command = handler.CFG_PATH_LOCAL
server.runCommand(["findConfigFilePath", "local.conf"])
except xmlrpclib.Fault:
print("XMLRPC Fault getting commandline:\n %s" % x)