Class: Blender::Driver::Ruby

Inherits:
Base
  • Object
show all
Defined in:
lib/blender/drivers/ruby.rb

Instance Attribute Summary

Attributes inherited from Base

#config, #events, #stderr, #stdout

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Blender::Driver::Base

Instance Method Details

#execute(tasks, hosts) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/blender/drivers/ruby.rb', line 23

def execute(tasks, hosts)
  tasks.each do |task|
    hosts.each do |host|
      cmd = run_command(task.command, host)
      if cmd.exitstatus != 0 and !task.[:ignore_failure]
        raise ExecutionFailed, cmd.stderr
      end
    end
  end
end

#run_command(command, host) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/blender/drivers/ruby.rb', line 34

def run_command(command, host)
  exit_status = 0
  err = ''
  current_stdout = STDOUT.clone
  current_stderr = STDERR.clone
  begin
    STDOUT.reopen(stdout)
    STDERR.reopen(stderr)
    command.call(host)
  rescue StandardError => e
    err = e.message + "\nBacktrace:" + e.backtrace.join("\n")
    exit_status = -1
  ensure
    STDOUT.reopen(current_stdout)
    STDERR.reopen(current_stderr)
  end
  ExecOutput.new(exit_status, '', err)
end