def _ExecuteBinaryWithStreaming(cmd, in_str=None): exit_code = execution_utils.ExecWithStreamingOutput( args=cmd, no_exit=True, in_str=in_str) if exit_code != 0: raise ClientException( 'The bulk-export command could not finish correctly.') log.status.Print('\nExport complete.') return exit_code
def _Execute(self, cmd, stdin=None, env=None, **kwargs): """Execute binary and return operation result. Will parse args from kwargs into a list of args to pass to underlying binary and then attempt to execute it. Will use configured stdout, stderr and failure handlers for this operation if configured or module defaults. Args: cmd: [str], command to be executed with args stdin: str, data to send to binary on stdin env: {str, str}, environment vars to send to binary. **kwargs: mapping of additional arguments to pass to the underlying executor. Returns: OperationResult: execution result for this invocation of the binary. Raises: ArgumentError, if there is an error parsing the supplied arguments. BinaryOperationError, if there is an error executing the binary. """ op_context = { 'env': env, 'stdin': stdin, 'exec_dir': kwargs.get('execution_dir') } result_holder = self.OperationResult(command_str=cmd, execution_context=op_context) std_out_handler = self.std_out_handler( result_holder=result_holder, capture_output=self.capture_output) std_err_handler = self.std_err_handler( result_holder=result_holder, capture_output=self.capture_output) short_cmd_name = os.path.basename(cmd[0]) # useful for error messages try: working_dir = kwargs.get('execution_dir') if working_dir and not os.path.isdir(working_dir): raise InvalidWorkingDirectoryError(short_cmd_name, working_dir) exit_code = execution_utils.ExecWithStreamingOutput( args=cmd, no_exit=True, out_func=std_out_handler, err_func=std_err_handler, in_str=stdin, cwd=working_dir, env=env) except (execution_utils.PermissionError, execution_utils.InvalidCommandError) as e: raise ExecutionError(short_cmd_name, e) result_holder.exit_code = exit_code self.set_failure_status(result_holder, kwargs.get('show_exec_error', False)) return result_holder
def RunExec(self, args, env=None, no_exit=False, out_func=None, err_func=None, in_str=None, **extra_popen_kwargs): return execution_utils.ExecWithStreamingOutput(args, env, no_exit, out_func, err_func, in_str, **extra_popen_kwargs)
def _ExecuteBinaryWithStreaming(cmd, in_str=None): exit_code = execution_utils.ExecWithStreamingOutput(args=cmd, in_str=in_str) if exit_code != 0: raise client_base.ClientException( 'The bulk-export command could not finish correctly.')