class Pione::Package::ScenarioHandler

ScenarioHandler handles scenario related operations.

Attributes

info[R]
location[R]

Public Class Methods

new(location, info) click to toggle source

@param location [BasicLocation]

scenario location

@param info [Hash]

scenario information table
# File lib/pione/package/scenario-handler.rb, line 14
def initialize(location, info)
  @location = location
  @info = info
end

Public Instance Methods

input() click to toggle source

Return input location of the scenario. If the scenario doesn’t have input location, return nil.

@return [BasicLocation]

the input location
# File lib/pione/package/scenario-handler.rb, line 36
def input
  input_location = @location + "input"
  return input_location.exist? ? input_location : nil
end
inputs() click to toggle source

Return list of input data location.

@return [BasicLocation]

input file locations
# File lib/pione/package/scenario-handler.rb, line 45
def inputs
  info.inputs.map {|path| @location + path}
end
output() click to toggle source

Return the output location.

@return [BasicLocation]

the output location
# File lib/pione/package/scenario-handler.rb, line 53
def output
  @location + "output"
end
outputs() click to toggle source

Return output file locations.

@return [BasicLocation]

output file locations
# File lib/pione/package/scenario-handler.rb, line 61
def outputs
  @info.outputs.map {|path| @location + path}
end
validate(result_location) click to toggle source

Validate reheasal results.

# File lib/pione/package/scenario-handler.rb, line 66
def validate(result_location)
  return [] unless output.exist?

  errors = []
  output.entries.each do |entry|
    name = entry.basename
    result = result_location + name
    if result.exist?
      if entry.read != result.read
        errors << RehearsalResult.new(:different, name)
      end
    else
      errors << RehearsalResult.new(:not_exist, name)
    end
  end
  return errors
end
write_info_file(option={}) click to toggle source

Write an information file for the scenario.

# File lib/pione/package/scenario-handler.rb, line 20
def write_info_file(option={})
  last_time = Util::LastTime.get(@info.filepaths.map{|path| @location + path})

  # update the scenario info file
  location = @location + "pione-scenario.json"
  if option[:force] or not(location.exist?) or last_time > location.mtime
    location.write(JSON.pretty_generate(@info))
    Log::SystemLog.info("update the scenario info file: %s" % location.address)
  end
end