Module: Kernel

Defined in:
lib/overwrite.rb

Instance Method Summary collapse

Instance Method Details

#`(cmd) ⇒ Object

overwrite backtick operator to catch system errors Override raises an error if cmd returns a non-zero exit status. CH: I do not understand this comment Returns stdout if cmd succeeds. Note that these are simply concatenated; STDERR is not inline. CH: I do not understand this comment


140
141
142
143
144
145
146
147
148
149
150
# File 'lib/overwrite.rb', line 140

def ` cmd
  stdout, stderr = ''
  status = Open4::popen4(cmd) do |pid, stdin_stream, stdout_stream, stderr_stream|
    stdout = stdout_stream.read
    stderr = stderr_stream.read
  end
  internal_server_error "`" + cmd + "` failed.\n" + stdout + stderr unless status.success?
  return stdout
rescue
  internal_server_error $!.message
end

#wait_for_task(uri) ⇒ String

Returns uri of task result, if task fails, an error according to task is raised

Returns:

  • (String)

    uri of task result, if task fails, an error according to task is raised


153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/overwrite.rb', line 153

def wait_for_task uri
  if URI.task?(uri)
    t = OpenTox::Task.new uri
    t.wait
    unless t.completed?
      error = OpenTox::RestClientWrapper.known_errors.select{|error| error[:code] == t.code}.first
      error_method = error ? error[:method] : :internal_server_error
      report = t.error_report
      error_message = report ? report[RDF::OT.message] : $!.message
      error_cause = report ? report[RDF::OT.errorCause] : nil 
      Object.send(error_method,error_message,t.uri,error_cause)
    end
    uri = t.resultURI
  end
  uri
end