Class: Pione::RuleEngine::ActionShellScript

Inherits:
Object
  • Object
show all
Defined in:
lib/pione/rule-engine/action-handler.rb

Overview

ActionShellScript handles action rule's shell script.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env, working_directory, rule_definition, dry_run) ⇒ ActionShellScript

Returns a new instance of ActionShellScript.



229
230
231
232
233
234
235
# File 'lib/pione/rule-engine/action-handler.rb', line 229

def initialize(env, working_directory, rule_definition, dry_run)
  @env = env
  @working_directory = working_directory
  @rule_definition = rule_definition
  @dry_run = dry_run
  @location = @working_directory.location + "__pione__.sh"
end

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



227
228
229
# File 'lib/pione/rule-engine/action-handler.rb', line 227

def location
  @location
end

Instance Method Details

#call(session_id, request_from, client_ui) ⇒ void

This method returns an undefined value.

Call the shell script.

Parameters:

  • session_id (String)

    session id

  • request_from (String)

    address of the client that task requested

  • client_ui (String)

    UI type of the client



272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
# File 'lib/pione/rule-engine/action-handler.rb', line 272

def call(session_id, request_from, client_ui)
  callee_env = {
    "PATH" => (@working_directory.location + "bin").path.to_s + ":" + ENV["PATH"],
    "PIONE_SESSION_ID" => session_id,
    "PIONE_REQUEST_FROM" => request_from.to_s,
    "PIONE_CLIENT_UI" => client_ui.to_s
  }
  command = "./#{@location.basename} > #{stdout.basename} 2> #{stderr.basename}"
  options = {:chdir => @working_directory.location.path.to_s}

  # execute command
  system(callee_env, command, options)

  result = $?.success?
  if result
    # delete .stderr and .stdout files if they are empty
    stdout.delete if stdout.size == 0
    stderr.delete if stderr.size == 0
  end
  return result
#end
end

#stderrLocaiton

Return the location of stderr file.

Returns:

  • (Locaiton)

    location of stderr file



307
308
309
# File 'lib/pione/rule-engine/action-handler.rb', line 307

def stderr
  @working_directory.location + ".stderr"
end

#stdoutLocation

Return the location of stdout file.

Returns:

  • (Location)

    location of stdout file



299
300
301
# File 'lib/pione/rule-engine/action-handler.rb', line 299

def stdout
  @working_directory.location + ".stdout"
end

#writeString

Write the rule action into a shell script.

Returns:

  • (String)

    written shell script



241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
# File 'lib/pione/rule-engine/action-handler.rb', line 241

def write
  content = @rule_definition.action_context.eval(@env).content
  sh = Util::EmbededExprExpander.expand(@env, content)

  # write the action
  if @dry_run
    rule_condition = @rule_definition.rule_condition_context.eval(@env)
    rule_definition.outputs.flatten.each do |output|
      @location.append("touch %s" % output.eval(@env).pieces.first.pattern)
    end
  else
    @location.create(sh)
  end

  # chmod 700
  if @working_directory.location.scheme == "local"
    FileUtils.chmod(0700, @location.path)
  end

  return sh
end