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.



526
527
528
# File 'lib/smart_monkey/monkey_runner.rb', line 526

def initialize(log_list)
  @log_list = log_list
end

Instance Method Details

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



535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
# File 'lib/smart_monkey/monkey_runner.rb', line 535

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/
        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/
    # elsif log[LOG_TYPE] == 'Default' && log[MESSAGE] =~ /^DeviceInfo/
    #   hash[:screen_size] = log[MESSAGE]
    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



530
531
532
533
# File 'lib/smart_monkey/monkey_runner.rb', line 530

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