From: martinahansen Date: Thu, 19 May 2011 11:34:32 +0000 (+0000) Subject: preparing biopieces.rb rewrite X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=6fa99a20ea8cc2513855ea67303724013650e599;p=biopieces.git preparing biopieces.rb rewrite git-svn-id: http://biopieces.googlecode.com/svn/trunk@1411 74ccb610-7750-0410-82ae-013aeee3265d --- diff --git a/code_ruby/lib/maasha/biopieces.rb b/code_ruby/lib/maasha/biopieces.rb index abdf607..8fa985d 100644 --- a/code_ruby/lib/maasha/biopieces.rb +++ b/code_ruby/lib/maasha/biopieces.rb @@ -29,6 +29,7 @@ require 'date' require 'optparse' require 'open3' require 'pp' +require 'maasha/filesys' # 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 @@ -39,7 +40,7 @@ require 'pp' # the parsing and emitting of Biopiece records, which are ASCII text records consisting # of lines with a key/value pair separated by a colon and a white space ': '. # Each record is separated by a line with three dashes '---'. -class Biopieces +class Biopieces < Filesys include Enumerable attr_accessor :out # accessor for out stream _ios_ @@ -59,14 +60,17 @@ class Biopieces casts = Casts.new(cast_list) option_handler = OptionHandler.new(argv, casts, script_path, @test) @options = option_handler.options_parse + + @in = Stream.open(@options, mode="r", @input) + + @options end # Open Biopiece input stream if not open and iterate over all Biopiece # records in the stream. def each_record - @in = Stream::open(@options, mode="r", @input) unless @in.is_a? IO return if @in.nil? - + record = {} @in.each_line do |line| @@ -90,7 +94,7 @@ class Biopieces # Open Biopiece output stream if not open and puts record to the stream. def puts(record) - @out = Stream::open(@options, mode="w", @output) unless @out.is_a? IO + @out = Stream.open(@options, mode="w", @output) unless @out.is_a? IO record.each do |key,value| @out.print "#{key.to_s}: #{value}\n" @@ -652,9 +656,10 @@ class Stream < IO end end - +# Set status when 'biopieces' is required. Status.new.set +# Clean up when 'biopieces' exists. at_exit do exit_status = $! ? $!.inspect : "OK" diff --git a/code_ruby/test/maasha/test_biopieces.rb b/code_ruby/test/maasha/test_biopieces.rb index 49d10a5..f5204c8 100755 --- a/code_ruby/test/maasha/test_biopieces.rb +++ b/code_ruby/test/maasha/test_biopieces.rb @@ -305,7 +305,7 @@ class BiopiecesTest < Test::Unit::TestCase # TODO replace the absolute part below the file location with File.dirname(__FILE__) def test_Biopieces_parse_with_glob_argument_expands_correctly - flunk("This test is weird") + flunk("This test is flawed and need fixing") argv = ["--foo", "/Users/maasha/unit_test/foo*,/Users/maasha/unit_test/my_dir/*.fna", "-I", DUMMY_FILE] casts = [{:long=>"foo", :short=>"f", :type=>"files!", :mandatory=>false, :default=>nil, :allowed=>nil, :disallowed=>nil}] options = @bp.parse(argv, casts, SCRIPT_PATH)