class Pione::RuleEngine::WorkingDirectory

WorkingDirectory is a directory that action rule executes the shell script.

Public Class Methods

new(env, base_location, inputs) click to toggle source
# File lib/pione/rule-engine/action-handler.rb, line 132
def initialize(env, base_location, inputs)
  @env = env
  @dir = Location[Global.working_directory_generator.mkdir]
  @base_location = base_location
  @inputs = inputs
end

Public Instance Methods

close() click to toggle source

Clear the working directory.

# File lib/pione/rule-engine/action-handler.rb, line 175
def close
  @dir.delete
end
collect_outputs(output_conditions) click to toggle source

Collect output data by names from working directory.

@param output_conditions [Condition]

all output conditions of action rule

@return [Array<Array<String>>]

array of output filenames
# File lib/pione/rule-engine/action-handler.rb, line 161
def collect_outputs(output_conditions)
  filenames = @dir.file_entries.map{|entry| entry.basename}
  output_conditions.map do |condition|
    case condition.distribution
    when :all
      filenames.select{|name| condition.match?(name)}
    when :each
      name = filenames.find {|name| condition.match?(name)}
      name ? [name] : []
    end
  end
end
import() click to toggle source

Synchronize input data into working directory.

# File lib/pione/rule-engine/action-handler.rb, line 144
def import
  @env.variable_set(
    Lang::Variable.new("__WORKING_DIRECTORY__"),
    Lang::StringSequence.of(@dir.path.to_s)
  )

  import_inputs
  import_bins
  import_etc
end
location() click to toggle source
# File lib/pione/rule-engine/action-handler.rb, line 139
def location
  @dir
end

Private Instance Methods

import_bins() click to toggle source
# File lib/pione/rule-engine/action-handler.rb, line 194
def import_bins
  # FIXME: should not copy bin files in the package each time.
  bin = @base_location + "package" + "bin"
  if bin.exist?
    bin.entries.each do |entry|
      dest = @dir + "bin" + entry.basename
      unless dest.exist?
        # copy and set executable flag
        entry.copy(dest)
        dest.path.chmod(0700)
      end
    end
  end
end
import_etc() click to toggle source
# File lib/pione/rule-engine/action-handler.rb, line 209
def import_etc
  # FIXME: should not copy files in the package each time
  file_dir = @base_location + "package" + "etc"
  if file_dir.exist?
    file_dir.entries.each do |entry|
      dest = @dir + "etc" + entry.basename
      unless dest.exist?
        # copy and unset executable flag
        entry.copy(dest)
        dest.path.chmod(0600)
      end
    end
  end
end
import_inputs() click to toggle source
# File lib/pione/rule-engine/action-handler.rb, line 181
def import_inputs
  @inputs.flatten.each do |input|
    # get file path in working directory
    wd_location = @dir + input.name
    # create a link to cache
    cache_location = System::FileCache.get(input.location)
    wd_location.path.make_symlink(cache_location.path)
    unless wd_location.exist?
      raise RuleExecutionError.new(self)
    end
  end
end