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: 717831b8315cb3904d9b590e633000bc897e8fb6) Signed-off-by: Christopher Larson <chris_larson@mentor.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
parent
99fa251b56
commit
c1c20c02a0
|
@ -44,6 +44,9 @@ class CommandFailed(CommandExit):
|
||||||
self.error = message
|
self.error = message
|
||||||
CommandExit.__init__(self, 1)
|
CommandExit.__init__(self, 1)
|
||||||
|
|
||||||
|
class CommandError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
class Command:
|
class Command:
|
||||||
"""
|
"""
|
||||||
A queue of asynchronous commands for bitbake
|
A queue of asynchronous commands for bitbake
|
||||||
|
@ -57,21 +60,25 @@ class Command:
|
||||||
self.currentAsyncCommand = None
|
self.currentAsyncCommand = None
|
||||||
|
|
||||||
def runCommand(self, commandline):
|
def runCommand(self, commandline):
|
||||||
try:
|
command = commandline.pop(0)
|
||||||
command = commandline.pop(0)
|
if hasattr(CommandsSync, command):
|
||||||
if command in CommandsSync.__dict__:
|
# Can run synchronous commands straight away
|
||||||
# Can run synchronous commands straight away
|
command_method = getattr(self.cmds_sync, command)
|
||||||
return getattr(CommandsSync, command)(self.cmds_sync, self, commandline)
|
try:
|
||||||
if self.currentAsyncCommand is not None:
|
result = command_method(self, commandline)
|
||||||
return "Busy (%s in progress)" % self.currentAsyncCommand[0]
|
except CommandError as exc:
|
||||||
if command not in CommandsAsync.__dict__:
|
return None, exc.args[0]
|
||||||
return "No such command"
|
except Exception:
|
||||||
self.currentAsyncCommand = (command, commandline)
|
return None, traceback.format_exc()
|
||||||
self.cooker.server_registration_cb(self.cooker.runCommands, self.cooker)
|
else:
|
||||||
return True
|
return result, None
|
||||||
except:
|
if self.currentAsyncCommand is not None:
|
||||||
import traceback
|
return None, "Busy (%s in progress)" % self.currentAsyncCommand[0]
|
||||||
return traceback.format_exc()
|
if command not in CommandsAsync.__dict__:
|
||||||
|
return None, "No such command"
|
||||||
|
self.currentAsyncCommand = (command, commandline)
|
||||||
|
self.cooker.server_registration_cb(self.cooker.runCommands, self.cooker)
|
||||||
|
return True, None
|
||||||
|
|
||||||
def runAsyncCommand(self):
|
def runAsyncCommand(self):
|
||||||
try:
|
try:
|
||||||
|
@ -139,7 +146,11 @@ class CommandsSync:
|
||||||
"""
|
"""
|
||||||
Get any command parsed from the commandline
|
Get any command parsed from the commandline
|
||||||
"""
|
"""
|
||||||
return command.cooker.commandlineAction
|
cmd_action = command.cooker.commandlineAction
|
||||||
|
if cmd_action['msg']:
|
||||||
|
raise CommandError(msg)
|
||||||
|
else:
|
||||||
|
return cmd_action['action']
|
||||||
|
|
||||||
def getVariable(self, command, params):
|
def getVariable(self, command, params):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -48,7 +48,7 @@ class ServerCommunicator():
|
||||||
if self.connection.poll(.5):
|
if self.connection.poll(.5):
|
||||||
return self.connection.recv()
|
return self.connection.recv()
|
||||||
else:
|
else:
|
||||||
return None
|
return None, "Timeout while attempting to communicate with bitbake server"
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
@ -108,13 +108,9 @@ class HobHandler(gobject.GObject):
|
||||||
|
|
||||||
def runCommand(self, commandline):
|
def runCommand(self, commandline):
|
||||||
try:
|
try:
|
||||||
result = self.server.runCommand(commandline)
|
result, error = self.server.runCommand(commandline)
|
||||||
result_str = str(result)
|
if error:
|
||||||
if (result_str.startswith("Busy (") or
|
raise Exception("Error running command '%s': %s" % (commandline, error))
|
||||||
result_str == "No such command"):
|
|
||||||
raise Exception('%s has failed with output "%s". ' %
|
|
||||||
(str(commandline), result_str) +
|
|
||||||
"We recommend that you restart Hob.")
|
|
||||||
return result
|
return result
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.commands_async = []
|
self.commands_async = []
|
||||||
|
|
|
@ -198,17 +198,23 @@ class gtkthread(threading.Thread):
|
||||||
|
|
||||||
def main(server, eventHandler):
|
def main(server, eventHandler):
|
||||||
try:
|
try:
|
||||||
cmdline = server.runCommand(["getCmdLineAction"])
|
cmdline, error = server.runCommand(["getCmdLineAction"])
|
||||||
if cmdline and not cmdline['action']:
|
if error:
|
||||||
print(cmdline['msg'])
|
print("Error getting bitbake commandline: %s" % error)
|
||||||
return
|
return 1
|
||||||
elif not cmdline or (cmdline['action'] and cmdline['action'][0] != "generateDotGraph"):
|
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")
|
print("This UI is only compatible with the -g option")
|
||||||
return
|
return 1
|
||||||
ret = server.runCommand(["generateDepTreeEvent", cmdline['action'][1], cmdline['action'][2]])
|
ret, error = server.runCommand(["generateDepTreeEvent", cmdline[1], cmdline[2]])
|
||||||
if ret != True:
|
if error:
|
||||||
print("Couldn't run command! %s" % ret)
|
print("Error running command '%s': %s" % (cmdline, error))
|
||||||
return
|
return 1
|
||||||
|
elif ret != True:
|
||||||
|
print("Error running command '%s': returned %s" % (cmdline, ret))
|
||||||
|
return 1
|
||||||
except xmlrpclib.Fault as x:
|
except xmlrpclib.Fault as x:
|
||||||
print("XMLRPC Fault getting commandline:\n %s" % x)
|
print("XMLRPC Fault getting commandline:\n %s" % x)
|
||||||
return
|
return
|
||||||
|
@ -234,7 +240,9 @@ def main(server, eventHandler):
|
||||||
try:
|
try:
|
||||||
event = eventHandler.waitEvent(0.25)
|
event = eventHandler.waitEvent(0.25)
|
||||||
if gtkthread.quit.isSet():
|
if gtkthread.quit.isSet():
|
||||||
server.runCommand(["stateStop"])
|
_, error = server.runCommand(["stateStop"])
|
||||||
|
if error:
|
||||||
|
print('Unable to cleanly stop: %s' % error)
|
||||||
break
|
break
|
||||||
|
|
||||||
if event is None:
|
if event is None:
|
||||||
|
@ -310,9 +318,13 @@ def main(server, eventHandler):
|
||||||
break
|
break
|
||||||
if shutdown == 1:
|
if shutdown == 1:
|
||||||
print("\nSecond Keyboard Interrupt, stopping...\n")
|
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:
|
if shutdown == 0:
|
||||||
print("\nKeyboard Interrupt, closing down...\n")
|
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
|
shutdown = shutdown + 1
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -80,16 +80,19 @@ def main (server, eventHandler):
|
||||||
running_build.connect ("build-failed", running_build_failed_cb)
|
running_build.connect ("build-failed", running_build_failed_cb)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
cmdline = server.runCommand(["getCmdLineAction"])
|
cmdline, error = server.runCommand(["getCmdLineAction"])
|
||||||
if not cmdline:
|
if err:
|
||||||
|
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.")
|
print("Nothing to do. Use 'bitbake world' to build everything, or run 'bitbake --help' for usage information.")
|
||||||
return 1
|
return 1
|
||||||
elif not cmdline['action']:
|
ret, error = server.runCommand(cmdline)
|
||||||
print(cmdline['msg'])
|
if error:
|
||||||
|
print("Error running command '%s': %s" % (cmdline, error))
|
||||||
return 1
|
return 1
|
||||||
ret = server.runCommand(cmdline['action'])
|
elif ret != True:
|
||||||
if ret != True:
|
print("Error running command '%s': returned %s" % (cmdline, ret))
|
||||||
print("Couldn't get default commandline! %s" % ret)
|
|
||||||
return 1
|
return 1
|
||||||
except xmlrpclib.Fault as x:
|
except xmlrpclib.Fault as x:
|
||||||
print("XMLRPC Fault getting commandline:\n %s" % x)
|
print("XMLRPC Fault getting commandline:\n %s" % x)
|
||||||
|
|
|
@ -217,9 +217,19 @@ class TerminalFilter(object):
|
||||||
def main(server, eventHandler, tf = TerminalFilter):
|
def main(server, eventHandler, tf = TerminalFilter):
|
||||||
|
|
||||||
# Get values of variables which control our output
|
# Get values of variables which control our output
|
||||||
includelogs = server.runCommand(["getVariable", "BBINCLUDELOGS"])
|
includelogs, error = server.runCommand(["getVariable", "BBINCLUDELOGS"])
|
||||||
loglines = server.runCommand(["getVariable", "BBINCLUDELOGS_LINES"])
|
if error:
|
||||||
consolelogfile = server.runCommand(["getVariable", "BB_CONSOLELOG"])
|
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():
|
if sys.stdin.isatty() and sys.stdout.isatty():
|
||||||
log_exec_tty = True
|
log_exec_tty = True
|
||||||
else:
|
else:
|
||||||
|
@ -240,19 +250,22 @@ def main(server, eventHandler, tf = TerminalFilter):
|
||||||
logger.addHandler(consolelog)
|
logger.addHandler(consolelog)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
cmdline = server.runCommand(["getCmdLineAction"])
|
cmdline, error = server.runCommand(["getCmdLineAction"])
|
||||||
if not cmdline:
|
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.")
|
print("Nothing to do. Use 'bitbake world' to build everything, or run 'bitbake --help' for usage information.")
|
||||||
return 1
|
return 1
|
||||||
elif not cmdline['action']:
|
ret, error = server.runCommand(cmdline)
|
||||||
print(cmdline['msg'])
|
if error:
|
||||||
|
logger.error("Command '%s' failed: %s" % (cmdline, error))
|
||||||
return 1
|
return 1
|
||||||
ret = server.runCommand(cmdline['action'])
|
elif ret != True:
|
||||||
if ret != True:
|
logger.error("Command '%s' failed: returned %s" % (cmdline, ret))
|
||||||
print("Couldn't get default commandline! %s" % ret)
|
|
||||||
return 1
|
return 1
|
||||||
except xmlrpclib.Fault as x:
|
except xmlrpclib.Fault as x:
|
||||||
print("XMLRPC Fault getting commandline:\n %s" % x)
|
logger.error("XMLRPC Fault getting commandline:\n %s" % x)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
parseprogress = None
|
parseprogress = None
|
||||||
|
@ -447,14 +460,19 @@ def main(server, eventHandler, tf = TerminalFilter):
|
||||||
if ioerror.args[0] == 4:
|
if ioerror.args[0] == 4:
|
||||||
pass
|
pass
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
|
import time
|
||||||
termfilter.clearFooter()
|
termfilter.clearFooter()
|
||||||
if main.shutdown == 1:
|
if main.shutdown == 1:
|
||||||
print("\nSecond Keyboard Interrupt, stopping...\n")
|
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:
|
if main.shutdown == 0:
|
||||||
interrupted = True
|
|
||||||
print("\nKeyboard Interrupt, closing down...\n")
|
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
|
main.shutdown = main.shutdown + 1
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
@ -236,15 +236,18 @@ class NCursesUI:
|
||||||
shutdown = 0
|
shutdown = 0
|
||||||
|
|
||||||
try:
|
try:
|
||||||
cmdline = server.runCommand(["getCmdLineAction"])
|
cmdline, error = server.runCommand(["getCmdLineAction"])
|
||||||
if not cmdline:
|
if not cmdline:
|
||||||
print("Nothing to do. Use 'bitbake world' to build everything, or run 'bitbake --help' for usage information.")
|
print("Nothing to do. Use 'bitbake world' to build everything, or run 'bitbake --help' for usage information.")
|
||||||
return
|
return
|
||||||
elif not cmdline['action']:
|
elif error:
|
||||||
print(cmdline['msg'])
|
print("Error getting bitbake commandline: %s" % error)
|
||||||
return
|
return
|
||||||
ret = server.runCommand(cmdline['action'])
|
ret, error = server.runCommand(cmdline)
|
||||||
if ret != True:
|
if error:
|
||||||
|
print("Error running command '%s': %s" % (cmdline, error))
|
||||||
|
return
|
||||||
|
elif ret != True:
|
||||||
print("Couldn't get default commandlind! %s" % ret)
|
print("Couldn't get default commandlind! %s" % ret)
|
||||||
return
|
return
|
||||||
except xmlrpclib.Fault as x:
|
except xmlrpclib.Fault as x:
|
||||||
|
@ -345,10 +348,14 @@ class NCursesUI:
|
||||||
exitflag = True
|
exitflag = True
|
||||||
if shutdown == 1:
|
if shutdown == 1:
|
||||||
mw.appendText("Second Keyboard Interrupt, stopping...\n")
|
mw.appendText("Second Keyboard Interrupt, stopping...\n")
|
||||||
server.runCommand(["stateStop"])
|
_, error = server.runCommand(["stateStop"])
|
||||||
|
if error:
|
||||||
|
print("Unable to cleanly stop: %s" % error)
|
||||||
if shutdown == 0:
|
if shutdown == 0:
|
||||||
mw.appendText("Keyboard Interrupt, closing down...\n")
|
mw.appendText("Keyboard Interrupt, closing down...\n")
|
||||||
server.runCommand(["stateShutdown"])
|
_, error = server.runCommand(["stateShutdown"])
|
||||||
|
if error:
|
||||||
|
print("Unable to cleanly shutdown: %s" % error)
|
||||||
shutdown = shutdown + 1
|
shutdown = shutdown + 1
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue