]> git.donarmstrong.com Git - biopieces.git/commitdiff
polishing exit in ruby code
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Mon, 21 Jun 2010 12:26:25 +0000 (12:26 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Mon, 21 Jun 2010 12:26:25 +0000 (12:26 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@992 74ccb610-7750-0410-82ae-013aeee3265d

code_ruby/Maasha/lib/biopieces.rb

index f533247633daf9df341988d2bbadf0d98272f782..42391dcf90ad3cfc7312d12c56ab342876e5a83f 100644 (file)
@@ -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__