diff options
author | Christopher Larson <chris_larson@mentor.com> | 2012-10-29 13:01:23 -0700 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2012-11-01 11:46:22 +0000 |
commit | c1c20c02a0eb808a099bebfcc7e90188baa22ba4 (patch) | |
tree | fea4ff816120e77b9e8b5bc547703478387e067d /bitbake/lib/bb/command.py | |
parent | 99fa251b5696dff77358d514175bbb08802a7a02 (diff) | |
download | poky-c1c20c02a0eb808a099bebfcc7e90188baa22ba4.tar.gz |
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>
Diffstat (limited to 'bitbake/lib/bb/command.py')
-rw-r--r-- | bitbake/lib/bb/command.py | 43 |
1 files changed, 27 insertions, 16 deletions
diff --git a/bitbake/lib/bb/command.py b/bitbake/lib/bb/command.py index 27b5171a6e..3f28bca257 100644 --- a/bitbake/lib/bb/command.py +++ b/bitbake/lib/bb/command.py | |||
@@ -44,6 +44,9 @@ class CommandFailed(CommandExit): | |||
44 | self.error = message | 44 | self.error = message |
45 | CommandExit.__init__(self, 1) | 45 | CommandExit.__init__(self, 1) |
46 | 46 | ||
47 | class CommandError(Exception): | ||
48 | pass | ||
49 | |||
47 | class Command: | 50 | class Command: |
48 | """ | 51 | """ |
49 | A queue of asynchronous commands for bitbake | 52 | A queue of asynchronous commands for bitbake |
@@ -57,21 +60,25 @@ class Command: | |||
57 | self.currentAsyncCommand = None | 60 | self.currentAsyncCommand = None |
58 | 61 | ||
59 | def runCommand(self, commandline): | 62 | def runCommand(self, commandline): |
60 | try: | 63 | command = commandline.pop(0) |
61 | command = commandline.pop(0) | 64 | if hasattr(CommandsSync, command): |
62 | if command in CommandsSync.__dict__: | 65 | # Can run synchronous commands straight away |
63 | # Can run synchronous commands straight away | 66 | command_method = getattr(self.cmds_sync, command) |
64 | return getattr(CommandsSync, command)(self.cmds_sync, self, commandline) | 67 | try: |
65 | if self.currentAsyncCommand is not None: | 68 | result = command_method(self, commandline) |
66 | return "Busy (%s in progress)" % self.currentAsyncCommand[0] | 69 | except CommandError as exc: |
67 | if command not in CommandsAsync.__dict__: | 70 | return None, exc.args[0] |
68 | return "No such command" | 71 | except Exception: |
69 | self.currentAsyncCommand = (command, commandline) | 72 | return None, traceback.format_exc() |
70 | self.cooker.server_registration_cb(self.cooker.runCommands, self.cooker) | 73 | else: |
71 | return True | 74 | return result, None |
72 | except: | 75 | if self.currentAsyncCommand is not None: |
73 | import traceback | 76 | return None, "Busy (%s in progress)" % self.currentAsyncCommand[0] |
74 | return traceback.format_exc() | 77 | if command not in CommandsAsync.__dict__: |
78 | return None, "No such command" | ||
79 | self.currentAsyncCommand = (command, commandline) | ||
80 | self.cooker.server_registration_cb(self.cooker.runCommands, self.cooker) | ||
81 | return True, None | ||
75 | 82 | ||
76 | def runAsyncCommand(self): | 83 | def runAsyncCommand(self): |
77 | try: | 84 | try: |
@@ -139,7 +146,11 @@ class CommandsSync: | |||
139 | """ | 146 | """ |
140 | Get any command parsed from the commandline | 147 | Get any command parsed from the commandline |
141 | """ | 148 | """ |
142 | return command.cooker.commandlineAction | 149 | cmd_action = command.cooker.commandlineAction |
150 | if cmd_action['msg']: | ||
151 | raise CommandError(msg) | ||
152 | else: | ||
153 | return cmd_action['action'] | ||
143 | 154 | ||
144 | def getVariable(self, command, params): | 155 | def getVariable(self, command, params): |
145 | """ | 156 | """ |