Class: Pione::Package::ScenarioHandler

Inherits:
Object
  • Object
show all
Includes:
SimpleIdentity
Defined in:
lib/pione/package/scenario-handler.rb

Overview

ScenarioHandler handles scenario related operations.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(location, info) ⇒ ScenarioHandler

Returns a new instance of ScenarioHandler.

Parameters:

  • location (BasicLocation)

    scenario location

  • info (Hash)

    scenario information table



14
15
16
17
# File 'lib/pione/package/scenario-handler.rb', line 14

def initialize(location, info)
  @location = location
  @info = info
end

Instance Attribute Details

#infoObject (readonly)

Returns the value of attribute info.



8
9
10
# File 'lib/pione/package/scenario-handler.rb', line 8

def info
  @info
end

#locationObject (readonly)

Returns the value of attribute location.



7
8
9
# File 'lib/pione/package/scenario-handler.rb', line 7

def location
  @location
end

Instance Method Details

#inputBasicLocation

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

Returns:

  • (BasicLocation)

    the input location



36
37
38
39
# File 'lib/pione/package/scenario-handler.rb', line 36

def input
  input_location = @location + "input"
  return input_location.exist? ? input_location : nil
end

#inputsBasicLocation

Return list of input data location.

Returns:

  • (BasicLocation)

    input file locations



45
46
47
# File 'lib/pione/package/scenario-handler.rb', line 45

def inputs
  info.inputs.map {|path| @location + path}
end

#outputBasicLocation

Return the output location.

Returns:

  • (BasicLocation)

    the output location



53
54
55
# File 'lib/pione/package/scenario-handler.rb', line 53

def output
  @location + "output"
end

#outputsBasicLocation

Return output file locations.

Returns:

  • (BasicLocation)

    output file locations



61
62
63
# File 'lib/pione/package/scenario-handler.rb', line 61

def outputs
  @info.outputs.map {|path| @location + path}
end

#validate(result_location) ⇒ Object

Validate reheasal results.



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# 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 = {}) ⇒ Object

Write an information file for the scenario.



20
21
22
23
24
25
26
27
28
29
# 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