module Blender::Driver::SSHExec

Public Instance Methods

fixup_sudo(command) click to toggle source
# File lib/blender/drivers/ssh_exec.rb, line 51
def fixup_sudo(command)
  command.sub(/^sudo/, 'sudo -p \'blender sudo password: \'')
end
remote_exec(command, session) click to toggle source
# File lib/blender/drivers/ssh_exec.rb, line 21
def remote_exec(command, session)
  password = config[:password]
  command = fixup_sudo(command)
  exit_status = 0
  channel = session.open_channel do |ch|
    ch.request_pty
    ch.exec(command) do |ch, success|
      unless success
        Blender::Log.debug("Command not found:#{success.inspect}")
        exit_status = -1
      end
      ch.on_data do |c, data|
        stdout << data
        c.send_data("#{password}\n") if data =~ /^blender sudo password: /
      end
      ch.on_extended_data do |c, type, data|
        stderr << data
      end
      ch.on_request "exit-status" do |ichannel, data|
        l = data.read_long
        exit_status = [exit_status, l].max
        Blender::Log.debug("exit_status:#{exit_status} , data:#{l}")
      end
    end
    Blender::Log.debug("Exit(#{exit_status}) Command: '#{command}'")
  end
  channel.wait
  exit_status
end