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/knotty.py | 46 +++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-) (limited to 'bitbake/lib/bb/ui/knotty.py') diff --git a/bitbake/lib/bb/ui/knotty.py b/bitbake/lib/bb/ui/knotty.py index 3799018fe3..8c63d74d9c 100644 --- a/bitbake/lib/bb/ui/knotty.py +++ b/bitbake/lib/bb/ui/knotty.py @@ -217,9 +217,19 @@ class TerminalFilter(object): def main(server, eventHandler, tf = TerminalFilter): # Get values of variables which control our output - includelogs = server.runCommand(["getVariable", "BBINCLUDELOGS"]) - loglines = server.runCommand(["getVariable", "BBINCLUDELOGS_LINES"]) - consolelogfile = server.runCommand(["getVariable", "BB_CONSOLELOG"]) + includelogs, error = server.runCommand(["getVariable", "BBINCLUDELOGS"]) + if error: + logger.error("Unable to get the value of BBINCLUDELOGS variable: %s" % error) + return 1 + loglines, error = server.runCommand(["getVariable", "BBINCLUDELOGS_LINES"]) + if error: + logger.error("Unable to get the value of BBINCLUDELOGS_LINES variable: %s" % error) + return 1 + consolelogfile, error = server.runCommand(["getVariable", "BB_CONSOLELOG"]) + if error: + logger.error("Unable to get the value of BB_CONSOLELOG variable: %s" % error) + return 1 + if sys.stdin.isatty() and sys.stdout.isatty(): log_exec_tty = True else: @@ -240,19 +250,22 @@ def main(server, eventHandler, tf = TerminalFilter): logger.addHandler(consolelog) try: - cmdline = server.runCommand(["getCmdLineAction"]) - if not cmdline: + cmdline, error = server.runCommand(["getCmdLineAction"]) + if error: + logger.error("Unable to get bitbake commandline arguments: %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['action']: - print(cmdline['msg']) + ret, error = server.runCommand(cmdline) + if error: + logger.error("Command '%s' failed: %s" % (cmdline, error)) return 1 - ret = server.runCommand(cmdline['action']) - if ret != True: - print("Couldn't get default commandline! %s" % ret) + elif ret != True: + logger.error("Command '%s' failed: returned %s" % (cmdline, ret)) return 1 except xmlrpclib.Fault as x: - print("XMLRPC Fault getting commandline:\n %s" % x) + logger.error("XMLRPC Fault getting commandline:\n %s" % x) return 1 parseprogress = None @@ -447,14 +460,19 @@ def main(server, eventHandler, tf = TerminalFilter): if ioerror.args[0] == 4: pass except KeyboardInterrupt: + import time termfilter.clearFooter() if main.shutdown == 1: print("\nSecond Keyboard Interrupt, stopping...\n") - server.runCommand(["stateStop"]) + _, error = server.runCommand(["stateStop"]) + if error: + logger.error("Unable to cleanly stop: %s" % error) if main.shutdown == 0: - interrupted = True print("\nKeyboard Interrupt, closing down...\n") - server.runCommand(["stateShutdown"]) + interrupted = True + _, error = server.runCommand(["stateShutdown"]) + if error: + logger.error("Unable to cleanly shutdown: %s" % error) main.shutdown = main.shutdown + 1 pass -- cgit v1.2.3-54-g00ecf