From 5107191184da43a30a8e0657b011dc09e254480e Mon Sep 17 00:00:00 2001 From: martinahansen Date: Mon, 21 Jun 2010 12:26:25 +0000 Subject: [PATCH] polishing exit in ruby code git-svn-id: http://biopieces.googlecode.com/svn/trunk@992 74ccb610-7750-0410-82ae-013aeee3265d --- code_ruby/Maasha/lib/biopieces.rb | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/code_ruby/Maasha/lib/biopieces.rb b/code_ruby/Maasha/lib/biopieces.rb index f533247..42391dc 100644 --- a/code_ruby/Maasha/lib/biopieces.rb +++ b/code_ruby/Maasha/lib/biopieces.rb @@ -4,7 +4,6 @@ require 'optparse' require 'open3' require 'pp' - # Biopieces are command line scripts and uses OptionParser to parse command line # options according to a list of casts. Each cast prescribes the long and short # name of the option, the type, if it is mandatory, the default value, and allowed @@ -82,15 +81,16 @@ class Biopieces path end - at_exit { - $stderr.puts "All done, time to make sure to close streams, remove tmpdir, and log entry." - + at_exit do @in.close if @in.respond_to? :close @out.close if @out.respond_to? :close - FileUtils.remove_entry_secure(@status.get_tmpdir) - @status.log - @status.delete - } + + status = Status.new + FileUtils.remove_entry_secure(status.get_tmpdir) + + status.log(@exit_status) + status.delete + end end @@ -480,7 +480,7 @@ class Status end # Write the Biopiece status to the log file. - def log(status="OK") + def log(exit_status) time1 = Time.new.strftime("%Y-%m-%d %X") user = ENV["USER"] script = File.basename($0, ".rb") @@ -493,7 +493,7 @@ class Status command = [script, args].join(" ") log_file = ENV["BP_LOG"] + "/biopieces.log" - File.open(log_file, mode="a") { |file| file.puts [time0, time1, elap, user, status, command].join("\t") } + File.open(log_file, mode="a") { |file| file.puts [time0, time1, elap, user, exit_status, command].join("\t") } end # Delete status file. @@ -594,4 +594,5 @@ class Stream < IO end end + __END__ -- 2.39.5