Sha256: 779668a074f8b65b5d7e558c825b5029c12942c6f20eb7171b1ab8f6ff65da13

Contents?: true

Size: 1.96 KB

Versions: 1

Compression:

Stored size: 1.96 KB

Contents

# frozen_string_literal: true

require_relative '../application'

##
# ExportManager is used by CaseManager to export output reports
module ExportManager
  ##
  # Run export function
  # @param main_report (Report)
  # @param cases (Array)
  # @param input (Hash) Selected export options
  # rubocop: disable Metrics/AbcSize
  def self.run(main_report, cases, input)
    args = {}
    input.each_pair do |key, value|
      if value.class == String
        args[key] = value.to_sym
      else
        args[key] = value
      end
    end

    # default :mode=>:all, :format=>:txt
    format = args[:format] || Application.instance.default[:format]
    mode = args[:mode] || :all
    # Step 1: Export case reports
    if %i[details all].include? mode
      threads = []
      cases.each { |c| threads << Thread.new { c.export format } }
      threads.each(&:join)
    end
    # Step 2: Export resume report
    main_report.export_resume format if %i[resume all].include? mode
    # Step 3: Preserve files if required
    preserve_files if args[:preserve] == true
  end
  # rubocop:enable Metrics/AbcSize

  ##
  # Preserve output files for current project
  # rubocop:disable Metrics/AbcSize
  # rubocop:disable Metrics/MethodLength
  # rubocop:disable Layout/LineLength
  private_class_method def self.preserve_files
    app = Application.instance
    t = Time.now
    data = { year: t.year, month: t.month, day: t.day,
             hour: t.hour, min: t.min, sec: t.sec }
    subdir = format('%<year>s%<month>02d%<day>02d-' \
                    '%<hour>02d%<min>02d%<sec>02d', data)
    logdir = File.join(app.output_basedir, app.global[:tt_testname], subdir)
    srcdir = File.join(app.output_basedir, app.global[:tt_testname])
    puts "[INFO] Preserving files => #{logdir}"
    FileUtils.mkdir(logdir)
    Dir.glob(File.join(srcdir, '**.*')).each { |file| FileUtils.cp(file, logdir) }
  end
  # rubocop:enable Metrics/AbcSize
  # rubocop:enable Metrics/MethodLength
  # rubocop:enable Layout/LineLength
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
teuton-2.1.11 lib/teuton/case_manager/export_manager.rb