diff options
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 fd8912ab40..00b854e240 100644 --- a/bitbake/lib/bb/command.py +++ b/bitbake/lib/bb/command.py @@ -44,6 +44,9 @@ class CommandFailed(CommandExit): self.error = message CommandExit.__init__(self, 1) +class CommandError(Exception): + pass + class Command: """ A queue of asynchronous commands for bitbake @@ -57,21 +60,25 @@ class Command: self.currentAsyncCommand = None def runCommand(self, commandline): - try: - command = commandline.pop(0) - if command in CommandsSync.__dict__: - # Can run synchronous commands straight away - return getattr(CommandsSync, command)(self.cmds_sync, self, commandline) - if self.currentAsyncCommand is not None: - return "Busy (%s in progress)" % self.currentAsyncCommand[0] - if command not in CommandsAsync.__dict__: - return "No such command" - self.currentAsyncCommand = (command, commandline) - self.cooker.server_registration_cb(self.cooker.runCommands, self.cooker) - return True - except: - import traceback - return traceback.format_exc() + command = commandline.pop(0) + if hasattr(CommandsSync, command): + # Can run synchronous commands straight away + command_method = getattr(self.cmds_sync, command) + try: + result = command_method(self, commandline) + except CommandError as exc: + return None, exc.args[0] + except Exception: + return None, traceback.format_exc() + else: + return result, None + if self.currentAsyncCommand is not None: + return None, "Busy (%s in progress)" % self.currentAsyncCommand[0] + 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): try: @@ -139,7 +146,11 @@ class CommandsSync: """ 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): """ |