From 3b9a640f8d19cd50d64ae2722304ace80453149e Mon Sep 17 00:00:00 2001 From: Christopher Larson Date: Mon, 29 Oct 2012 13:01:23 -0700 Subject: bitbake: command: add error to return of runCommand Currently, command.py can return an error message from runCommand, due to being unable to run the command, yet few of our UIs (just hob) can handle it today. This can result in seeing a TypeError with traceback in certain rare circumstances. To resolve this, we need a clean way to get errors back from runCommand, without having to isinstance() the return value. This implements such a thing by making runCommand also return an error (or None if no error occurred). As runCommand now has a method of returning errors, we can also alter the getCmdLineAction bits such that the returned value is just the action, not an additional message. If a sync command wants to return an error, it raises CommandError(message), and the message will be passed to the caller appropriately. Example Usage: result, error = server.runCommand(...) if error: log.error('Unable to run command: %s' % error) return 1 (Bitbake rev: d1002e33e05d45a7e1bd65d79537419a4057e43a) Signed-off-by: Christopher Larson Signed-off-by: Richard Purdie --- bitbake/lib/bb/ui/depexp.py | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) (limited to 'bitbake/lib/bb/ui/depexp.py') diff --git a/bitbake/lib/bb/ui/depexp.py b/bitbake/lib/bb/ui/depexp.py index 1a716a88bf..85910f6925 100644 --- a/bitbake/lib/bb/ui/depexp.py +++ b/bitbake/lib/bb/ui/depexp.py @@ -198,17 +198,23 @@ class gtkthread(threading.Thread): def main(server, eventHandler): try: - cmdline = server.runCommand(["getCmdLineAction"]) - if cmdline and not cmdline['action']: - print(cmdline['msg']) - return - elif not cmdline or (cmdline['action'] and cmdline['action'][0] != "generateDotGraph"): + cmdline, error = server.runCommand(["getCmdLineAction"]) + if error: + print("Error getting bitbake commandline: %s" % error) + return 1 + elif not cmdline: + print("Nothing to do. Use 'bitbake world' to build everything, or run 'bitbake --help' for usage information.") + return 1 + elif not cmdline or cmdline[0] != "generateDotGraph": print("This UI is only compatible with the -g option") - return - ret = server.runCommand(["generateDepTreeEvent", cmdline['action'][1], cmdline['action'][2]]) - if ret != True: - print("Couldn't run command! %s" % ret) - return + return 1 + ret, error = server.runCommand(["generateDepTreeEvent", cmdline[1], cmdline[2]]) + if error: + print("Error running command '%s': %s" % (cmdline, error)) + return 1 + elif ret != True: + print("Error running command '%s': returned %s" % (cmdline, ret)) + return 1 except xmlrpclib.Fault as x: print("XMLRPC Fault getting commandline:\n %s" % x) return @@ -234,7 +240,9 @@ def main(server, eventHandler): try: event = eventHandler.waitEvent(0.25) if gtkthread.quit.isSet(): - server.runCommand(["stateStop"]) + _, error = server.runCommand(["stateStop"]) + if error: + print('Unable to cleanly stop: %s' % error) break if event is None: @@ -310,9 +318,13 @@ def main(server, eventHandler): break if shutdown == 1: print("\nSecond Keyboard Interrupt, stopping...\n") - server.runCommand(["stateStop"]) + _, error = server.runCommand(["stateStop"]) + if error: + print('Unable to cleanly stop: %s' % error) if shutdown == 0: print("\nKeyboard Interrupt, closing down...\n") - server.runCommand(["stateShutdown"]) + _, error = server.runCommand(["stateShutdown"]) + if error: + print('Unable to cleanly shutdown: %s' % error) shutdown = shutdown + 1 pass -- cgit v1.2.3-54-g00ecf