Class: Pione::RuleEngine::ActionShellScript
- Inherits:
-
Object
- Object
- Pione::RuleEngine::ActionShellScript
- Defined in:
- lib/pione/rule-engine/action-handler.rb
Overview
ActionShellScript handles action rule's shell script.
Instance Attribute Summary collapse
-
#location ⇒ Object
readonly
Returns the value of attribute location.
Instance Method Summary collapse
-
#call(session_id, request_from, client_ui) ⇒ void
Call the shell script.
-
#initialize(env, working_directory, rule_definition, dry_run) ⇒ ActionShellScript
constructor
A new instance of ActionShellScript.
-
#stderr ⇒ Locaiton
Return the location of stderr file.
-
#stdout ⇒ Location
Return the location of stdout file.
-
#write ⇒ String
Write the rule action into a shell script.
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
#location ⇒ Object (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.
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}" = {:chdir => @working_directory.location.path.to_s} # execute command system(callee_env, command, ) 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 |
#stderr ⇒ Locaiton
Return the location of stderr file.
307 308 309 |
# File 'lib/pione/rule-engine/action-handler.rb', line 307 def stderr @working_directory.location + ".stderr" end |
#stdout ⇒ Location
Return the location of stdout file.
299 300 301 |
# File 'lib/pione/rule-engine/action-handler.rb', line 299 def stdout @working_directory.location + ".stdout" end |
#write ⇒ String
Write the rule action into a 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.(@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 |