Class: UIAutoMonkey::LogDecoder

Inherits:
Object
  • Object
show all
Defined in:
lib/smart_monkey/monkey_runner.rb

Instance Method Summary collapse

Constructor Details

#initialize(log_list) ⇒ LogDecoder

Returns a new instance of LogDecoder.



620
621
622
# File 'lib/smart_monkey/monkey_runner.rb', line 620

def initialize(log_list)
  @log_list = log_list
end

Instance Method Details

#decode_latest(num = 10, drop_useless_img, drop_dir) ⇒ Object



629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
# 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) ⇒ Object



624
625
626
627
# 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