class UIAutoMonkey::LogDecoder

Public Class Methods

new(log_list) click to toggle source
# File lib/smart_monkey/monkey_runner.rb, line 620
def initialize(log_list)
  @log_list = log_list
end

Public Instance Methods

decode_latest(num=10, drop_useless_img, drop_dir) { |hash| ... } click to toggle source
# File lib/smart_monkey/monkey_runner.rb, line 629
def decode_latest(num=10, drop_useless_img, drop_dir)
  hash = {}
  ret = []
  used_imgs = []
  @log_list.reverse.each do |log|
    break if num == 0
    if log[LOG_TYPE] == 'Screenshot'
      if log[MESSAGE] =~ /^action/
        hash[:action_image] = log[MESSAGE]
      elsif log[MESSAGE] =~ /^monkey[^external]*$/
        hash[:screen_image] = log[MESSAGE]
        used_imgs << log[MESSAGE]
        hash[:timestamp] = log[TIMESTAMP]
        
        # emit and init
        if block_given?
          yield(hash)
        else
          ret << hash
        end
        hash = {}
        num -= 1
      end
    elsif log[LOG_TYPE] == 'Debug' && log[MESSAGE] =~ /^target./
      # hash[:message] = log[MESSAGE] unless log[MESSAGE] =~ /^target.captureRectWithName/ && log[MESSAGE] =~ /switcherScrollView/
      hash[:message] = log[MESSAGE] unless log[MESSAGE] =~ /size:{height:0.00,width:0.00}/ || log[MESSAGE] =~ /switcherScrollView/
    end
  end
  #drop unused imgs
  if drop_useless_img
    puts "Drop useless images..."
    rm_unused_imgs(used_imgs, drop_dir)
  end
  if !@log_list.empty?
    #add screen_size
    hash = {}
    hash[:screen_size] = @log_list[0][MESSAGE]
    ret << hash
  end
  ret
end
rm_unused_imgs(used_imgs, dir) click to toggle source
# File lib/smart_monkey/monkey_runner.rb, line 624
def rm_unused_imgs(used_imgs, dir)
  used_strs = used_imgs.join("\\|")
  `cd "#{dir}";find . -type 'f' -name '*.png' | grep -v "#{used_strs}" | xargs -I{} rm {}`
end