summaryrefslogtreecommitdiff
path: root/bin/custodian-enqueue
diff options
context:
space:
mode:
authorSteve Kemp <steve@steve.org.uk>2015-03-09 14:41:06 +0000
committerSteve Kemp <steve@steve.org.uk>2015-03-09 14:41:06 +0000
commit26f013750196c5028135216de386496696b02a09 (patch)
tree98b56a4f60db4044d41583985bb2bc535688af81 /bin/custodian-enqueue
parentbababffbba69aa86b7b8d39267471d2ff9b22353 (diff)
Moved usage-information to foot of script.
This removes the nasty self-parsing of the script to generate the help/manual output. I've also removed global-variables and made the code almost-100% warning free.
Diffstat (limited to 'bin/custodian-enqueue')
-rwxr-xr-xbin/custodian-enqueue170
1 files changed, 71 insertions, 99 deletions
diff --git a/bin/custodian-enqueue b/bin/custodian-enqueue
index e8f71f0..f815757 100755
--- a/bin/custodian-enqueue
+++ b/bin/custodian-enqueue
@@ -1,93 +1,41 @@
-#!/usr/bin/ruby -Ilib/ -I../lib/ -rubygems
+#!/usr/bin/ruby -rubygems
#
-# NAME
-# custodian-enqueue - Parse tests from a file and enqueue them.
-#
-# SYNOPSIS
-# custodian-enqueue [ -h | --help ]
-# [ -m | --manual]
-# [ -q | --queue NAME]
-# [ -f | --file FILE]
-# [ -d | --dump ]
-# [ | --test ]
-#
-# OPTIONS
-#
-# -h, --help Show a help message, and exit.
+# Usage information at the end of the script.
#
-# -m, --manual Show this manual, and exit.
-#
-# -d, --dump Dump the parsed tests to the console; don't insert in the queue.
-#
-# --test Test the parsing of the given file, alert on errors.
-#
-# -f, --file FILE Parse the given configuration file.
-#
-#
-#
-# ABOUT
-#
-# This tool reads a single configuration file and parses it into a
-# series of network & protocol tests. These tests are then stored in
-# a queue from which workers can retrieve and execute them.
-#
-# The dequeing process may occur up numerous other hosts.
-#
-# CONFIGURATION FILE
-#
-# The configuration file is 99% compatible with that used in the tool
-# custodian replaces.
-#
-#
-# AUTHOR
-#
-# Steve Kemp <steve@bytemark.co.uk>
-#
-
-
-#
-# Standard modules
-#
require 'getoptlong'
-
-#
-# Our code.
-#
require 'custodian/parser'
require 'custodian/queue'
require 'custodian/settings'
-
-
#
# Entry-point to our code.
#
-if __FILE__ == $PROGRAM_NAME then
+if __FILE__ == $PROGRAM_NAME
- $help = false
- $manual = false
+ help = false
+ manual = false
begin
opts = GetoptLong.new(
- ['--dump', '-d', GetoptLong::NO_ARGUMENT],
- ['--test', GetoptLong::NO_ARGUMENT],
- ['--file', '-f', GetoptLong::REQUIRED_ARGUMENT],
- ['--help', '-h', GetoptLong::NO_ARGUMENT],
- ['--manual', '-m', GetoptLong::NO_ARGUMENT]
+ ['--dump', '-d', GetoptLong::NO_ARGUMENT],
+ ['--test', GetoptLong::NO_ARGUMENT],
+ ['--file', '-f', GetoptLong::REQUIRED_ARGUMENT],
+ ['--help', '-h', GetoptLong::NO_ARGUMENT],
+ ['--manual', '-m', GetoptLong::NO_ARGUMENT]
)
opts.each do |opt, arg|
case opt
when '--dump' then
- ENV['DUMP'] = '1'
+ ENV['DUMP'] = '1'
when '--test' then
- ENV['TEST'] = '1'
- when '--file' then
- ENV['FILE'] = arg
+ ENV['TEST'] = '1'
+ when '--file' then
+ ENV['FILE'] = arg
when '--help' then
- $help = true
+ help = true
when '--manual' then
- $manual = true
+ manual = true
end
end
rescue StandardError => ex
@@ -95,54 +43,31 @@ if __FILE__ == $PROGRAM_NAME then
exit
end
-
#
- # CAUTION! Here be quality kode.
+ # Show the help information.
#
- if $manual or $help
-
- # Open the file, stripping the shebang line
- lines = File.open(__FILE__){|fh| fh.readlines}[1..-1]
-
- found_synopsis = false
-
- lines.each do |line|
-
- line.chomp!
- break if line.empty?
-
- if $help and !found_synopsis
- found_synopsis = (line =~ /^#\s+SYNOPSIS\s*$/)
- next
- end
-
- puts line[2..-1].to_s
-
- break if $help and found_synopsis and line =~ /^#\s*$/
-
+ if manual || help
+ DATA.read.split("\n").each do |line|
+ puts Regexp.last_match(1).dup if line =~ /^# ?(.*)/
end
-
exit 0
end
-
#
# Connected to the queue - be it redis or beanstalkd
#
settings = Custodian::Settings.instance
queue = Custodian::QueueType.create(settings.queue_type)
- if !queue
+ unless queue
puts "Failed to connect to the #{settings.queue_type} queue"
exit 1
end
-
#
# Create the parser object.
#
mon = Custodian::Parser.new
-
#
# Parse our configuration file. If there are errors then we'll
# exit this script.
@@ -156,10 +81,9 @@ if __FILE__ == $PROGRAM_NAME then
end
mon.jobs.each do |test|
-
- if ENV['TEST']
+ if ENV['TEST']
# nop
- elsif ENV['DUMP']
+ elsif ENV['DUMP']
puts test
else
queue.add(test.to_s)
@@ -167,3 +91,51 @@ if __FILE__ == $PROGRAM_NAME then
end
end
+
+
+__END__
+#
+# NAME
+# custodian-enqueue - Parse tests from a file and enqueue them.
+#
+# SYNOPSIS
+# custodian-enqueue [ -h | --help ]
+# [ -m | --manual]
+# [ -q | --queue NAME]
+# [ -f | --file FILE]
+# [ -d | --dump ]
+# [ | --test ]
+#
+# OPTIONS
+#
+# -h, --help Show a help message, and exit.
+#
+# -m, --manual Show this manual, and exit.
+#
+# -d, --dump Dump the parsed tests to the console.
+# (They are not inserted to the queue.)
+#
+# --test Test the parsing of the given file, alert on errors.
+#
+# -f, --file FILE Parse the given configuration file.
+#
+#
+#
+# ABOUT
+#
+# This tool reads a single configuration file and parses it into a
+# series of network & protocol tests. These tests are then stored in
+# a queue from which workers can retrieve and execute them.
+#
+# The dequeing process may occur up numerous other hosts.
+#
+# CONFIGURATION FILE
+#
+# The configuration file is 99% compatible with that used in the tool
+# custodian replaces.
+#
+#
+# AUTHOR
+#
+# Steve Kemp <steve@bytemark.co.uk>
+#