Sha256: 18fe4b6b39b4cb07c3444a849550acb175152e5bd40640137b66fbfc8ddc5d5b

Contents?: true

Size: 1.69 KB

Versions: 4

Compression:

Stored size: 1.69 KB

Contents

require 'veewee/util/scancode'
require 'veewee/util/tcp'
require 'veewee/util/shell'

module Veewee
  module Builder
    module Virtualbox
      module BoxHelper
      def console_type(sequence)
        send_virtualbox_sequence(sequence)
      end
      
      def send_virtualbox_sequence(sequence)

        env.ui.info ""

        counter=0
        sequence.each { |s|
          counter=counter+1

          env.ui.info "Typing:[#{counter}]: "+s

          keycodes=Veewee::Util::Scancode.string_to_keycode(s)

          # VBox seems to have issues with sending the scancodes as one big
          # .join()-ed string. It seems to get them out or order or ignore some.
          # A workaround is to send the scancodes one-by-one.
          codes=""
          for keycode in keycodes.split(' ') do           
            unless keycode=="wait"
              send_keycode(keycode)    
              sleep 0.01                  
            else
              sleep 1
            end
          end
          #sleep after each sequence (needs to be param)
          sleep 0.5
        }

        env.ui.info "Done typing."
        env.ui.info ""

      end

      def send_keycode(keycode)
        command= "#{@vboxcmd} controlvm '#{name}' keyboardputscancode #{keycode}"
        env.logger.info "#{command}"
        sshresult=shell_exec("#{command}",{:mute => true})
        unless sshresult.stdout.index("E_ACCESSDENIED").nil?
          env.ui.error "There was an error typing the commands on the console"
          env.ui.error "Probably the VM did not get started."
          env.ui.error ""
          env.ui.error "#{sshresult.stdout}"
          exit -1
        end
      end
      
end #Module
end #Module
end #Module
end #Module

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
veewee-0.3.0.alpha4 lib/veewee/builder/virtualbox/helper/console_type.rb
veewee-0.3.0.alpha3 lib/veewee/builder/virtualbox/helper/console_type.rb
veewee-0.3.0.alpha2 lib/veewee/builder/virtualbox/helper/console_type.rb
veewee-0.3.0.alpha1 lib/veewee/builder/virtualbox/helper/console_type.rb