From e295b5f2988e38b8ddc0163776a9d897a1fd114f Mon Sep 17 00:00:00 2001 From: Steve Kemp Date: Fri, 23 Nov 2012 10:06:18 +0000 Subject: Updated the API for the parser to split parse_file into parse_lines. --- bin/custodian-enqueue | 6 ++++-- lib/custodian/parser.rb | 57 ++++++++++++++++++++++++++----------------------- 2 files changed, 34 insertions(+), 29 deletions(-) diff --git a/bin/custodian-enqueue b/bin/custodian-enqueue index 4dde365..ad8796f 100755 --- a/bin/custodian-enqueue +++ b/bin/custodian-enqueue @@ -144,7 +144,7 @@ if __FILE__ == $0 then # # Create the parser # - mon = Custodian::Parser.new( ENV['FILE'] ) + mon = Custodian::Parser.new() # # Set the timeout @@ -156,7 +156,9 @@ if __FILE__ == $0 then # # Run the parser - and get callbacks when a new job is added. # - mon.parse_file do |test| + mon.parse_file( ENV['FILE'] ) + + mon.jobs.each do |test| if ( ENV['TEST'] ) # nop diff --git a/lib/custodian/parser.rb b/lib/custodian/parser.rb index cd53e1b..42eb855 100644 --- a/lib/custodian/parser.rb +++ b/lib/custodian/parser.rb @@ -63,16 +63,13 @@ module Custodian # # Constructor # - def initialize( filename ) + def initialize( ) @MACROS = Hash.new() @jobs = Array.new() - @file = filename @timeout = 60 - raise ArgumentError, "Missing configuration file!" if ( @file.nil? ) - raise ArgumentError, "File not found: #{@file}" unless ( File.exists?( @file) ) end @@ -327,7 +324,7 @@ module Custodian end end - ret + return ret else raise ArgumentError, "Unknown line: '#{line}'" end @@ -335,21 +332,16 @@ module Custodian - - # - # Parse the configuration file which was named in our constructor. # - # This updates our @jobs array with the tests - and optionally - # invokes our callback. + # Parse a text-snippet, with multiple lines. # - def parse_file( &callback ) + def parse_lines( text ) # - # Parse the configuration file on the command line + # Split on newline # - File.open( @file, "r").each_line do |line| - - ret = parse_line( line) + text.each do |line| + ret = parse_line( line ) # # The return value from the parse_line method @@ -367,22 +359,33 @@ module Custodian @jobs.push( probe ) end end - - # - # If there was an optional callback then invoke it - # with the newly added job/jobs. - # - if ( block_given? ) - if ( ret.kind_of?( Array ) ) - ret.each do |probe| - yield probe.to_s - end - end - end end end + + # + # Parse the configuration file specified. + # + # This updates our @jobs array with the tests. + # + def parse_file( filename ) + + raise ArgumentError, "Missing configuration file!" if ( filename.nil? ) + raise ArgumentError, "File not found: #{@file}" unless ( File.exists?( filename) ) + + # + # Read the configuration file. + # + out = File.open( filename, 'r') {|file| file.readlines.collect} + + # + # Parse it + # + parse_lines( out ) + end + + end -- cgit v1.2.1