Sha256: fc97841599da00f9f0b8f1dbe07cf13453fc1d97d6cb1649a4f870eb866616f0

Contents?: true

Size: 1.7 KB

Versions: 4

Compression:

Stored size: 1.7 KB

Contents

#!/usr/bin/env ruby
require 'fileutils'
require 'instalatron'
require 'yaml'

def record_session(vm_name, session_name = "instalatron_rec_" + Time.now.strftime("%F_%H%M"))
  puts "Recording session #{session_name}\n\n"
  script = []
  $stdout.sync = true
  screen_count = 1
  Dir.mkdir session_name if not File.directory?(session_name)
  begin 
    print "Press ENTER to grab screen..."
    $stdin.gets
    loop do
      step = {}
      img = Instalatron.detect_screen(vm_name)

      # Get step name
      puts "Screen captured\n\n"
      print "Step name: "
      step[:name] = $stdin.gets.strip.chomp

      # Capture key sequence
      print "Key sequence: "
      step[:sequence] = $stdin.gets.strip.chomp
      if step[:sequence].empty?
        step[:sequence] = "<Enter>"
      end
      
      # Copy screenshot to session dir
      step[:image] = "#{step[:name].gsub(' ','_').downcase}.png"
      FileUtils.cp img, "#{session_name}/#{step[:image]}"

      script << step
      puts 
      Instalatron.command_window(step[:sequence], vm_name)
      screen_count += 1
      print "Press ENTER to grab screen (#{screen_count})..."
      $stdin.gets
    end
  rescue SystemExit, Interrupt
    puts "Aborting..."
    File.open "#{session_name}/script.yml", 'w' do |f|
      f.puts script.to_yaml
    end
  end
end

vm_name = ARGV[0]
running_vms = []
`VBoxManage list runningvms`.each_line do |l|
  vm = l.split[0].gsub('"', '')
  running_vms << vm
end
if not running_vms.include?(vm_name)
  $stderr.puts "Running VM #{vm_name} not found.\n\n"

  $stderr.puts "Usage: instalatron-record <vm_name> [session_name]"
  exit 1
end

session_name = ARGV[1] || "instalatron_rec_" + Time.now.strftime("%F_%H%M")

record_session  vm_name, session_name

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
instalatron-0.1.3 bin/instalatron-record
instalatron-0.1.2 bin/instalatron-record
instalatron-0.1.1 bin/instalatron-record
instalatron-0.1 bin/instalatron-record