lib/taskjuggler/SheetReceiver.rb in taskjuggler-0.0.11 vs lib/taskjuggler/SheetReceiver.rb in taskjuggler-0.1.0
- old
+ new
@@ -11,19 +11,22 @@
# published by the Free Software Foundation.
#
require 'digest/md5'
require 'mail'
-require 'open4'
require 'yaml'
+require 'taskjuggler/apps/Tj3Client'
+require 'taskjuggler/StdIoWrapper'
require 'taskjuggler/SheetHandlerBase'
require 'taskjuggler/RichText'
class TaskJuggler
class SheetReceiver < SheetHandlerBase
+ include StdIoWrapper
+
def initialize(appName, type)
super(appName)
@sheetType = type
# The following settings must be set by the deriving class.
@@ -170,31 +173,30 @@
end
end
end
def checkSheet(sheet)
- err = ''
- status = nil
+ res = nil
begin
# Save a copy of the sheet for debugging purposes.
File.open("#{@failedSheetsDir}/#{@resourceId}-#{@date}.tji", 'w') do |f|
f.write(sheet)
end
- command = "tj3client --silent #{@tj3clientOption} #{@projectId} ."
- status = Open4.popen4(command) do |pid, stdin, stdout, stderr|
- # Send the report to the tj3client process via stdin.
- stdin.write(sheet)
- stdin.close
- # Without errors, the incoming report is pretty printed and returned
- # in RichText format.
- @report = stdout.read
- @warnings = stderr.read
+ command = [ '--unsafe', '--silent', *@tj3clientOption.split(' '),
+ @projectId, '.' ]
+ # Send the report to the tj3client process via stdin.
+ res = stdIoWrapper(sheet) do
+ Tj3Client.new.main(command)
end
+ # Without errors, the incoming report is pretty printed and returned
+ # in RichText format.
+ @report = res.stdOut
+ @warnings = res.stdErr
rescue
fatal("Cannot check #{@sheetType} sheet: #{$!}")
end
- if status.exitstatus == 0
+ if res.returnValue == 0
File.delete("#{@failedSheetsDir}/#{@resourceId}-#{@date}.tji")
return true
end
# The exit status was not 0. The stderr output should not be empty and
@@ -331,11 +333,11 @@
end
sendEmail(@submitter, "Your #{@sheetType} sheet submission failed!",
message)
- exit 1
+ raise TjRuntimeError
end
def fatal(message)
log('FATAL', "#{message}")
@@ -347,10 +349,10 @@
problem and is temporarily out of service. The administrator
has been notified and will try to rectify the situation as
soon as possible. Please re-submit your #{@sheetType} sheet later!
EOT
)
- exit 1
+ raise TjRuntimeError
end
# Load tye resources.yml YAML file into the @resourceList variable.
# The format is Array with one entry per resource. The entry is an Array