Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## RingyDingy's ring_server
- require 'rinda/ring'
- require 'rinda/tuplespace'
- require 'ringy_dingy'
- require 'optparse'
- ##
- # RingyDingy::RingServer provides a friendly wrapper around Rinda::RingServer.
- #
- # When running on the command line, RingyDingy::RingServer's verbose mode may
- # be toggled remotely via the --set-verbose option.
- #
- # = Usage
- #
- # == Starting a RingServer
- #
- # From the command line:
- #
- # ring_server -d
- #
- # or from Ruby:
- #
- # RingyDingy::RingServer.new.run
- #
- # == List Services
- #
- # From the command line (after starting a RingServer):
- #
- # ring_server -l
- #
- # or from Ruby:
- #
- # RingyDingy::RingServer.list
- #
- # == Verbose mode
- #
- # Changing verbose mode for the server (when not a daemon).
- #
- # ring_server --set-verbose=true/false
- #
- # or from Ruby:
- #
- # RingyDingy::RingServer.set_verbose true/false
- class RingyDingy::RingServer
- ##
- # Process args into an options Hash. See also #new.
- def self.process_args(args)
- options = {}
- options[:Verbose] = false
- op = OptionParser.new do |op|
- op.program_name = 'ring_server'
- op.version = RingyDingy::VERSION
- op.release = nil
- op.banner = "Usage: #{name} [options]"
- op.separator ''
- op.separator 'Run, find, or modify the behavior of a Rinda::RingServer.'
- op.separator ''
- op.separator 'With no arguments a Rinda::RingServer is started and runs in the foreground.'
- op.separator ''
- op.separator 'RingServer options:'
- op.on("-d", "--daemon",
- "Run a RingServer as a daemon") do |val|
- options[:Daemon] = val
- end
- op.on("-v", "--verbose",
- "Enable verbose mode") do |val|
- options[:Verbose] = val
- end
- op.separator ''
- op.separator 'Miscellaneous options:'
- op.on("-l", "--list",
- "List services on available RingServers") do |val|
- options[:List] = val
- end
- op.on( "--set-verbose=BOOLEAN", TrueClass,
- "Enable or disable verbose mode on available",
- "RingServers (except daemon RingServers)") do |val|
- options[:SetVerbose] = val
- end
- end
- op.parse! args
- return options
- end
- ##
- # Run appropriately.
- def self.run(args = ARGV)
- DRb.start_service unless DRb.primary_server
- options = process_args args
- if options.include? :List then
- print_services
- exit
- elsif options.include? :SetVerbose then
- set_verbose options[:SetVerbose]
- exit
- elsif options.include? :Daemon then
- require 'webrick/server'
- WEBrick::Daemon.start
- end
- new(options).run
- end
- ##
- # Prints usage message message if present then OptionParser op .
- def self.usage(op, message = nil)
- if message then
- $stderr.puts message
- $stderr.puts
- end
- $stderr.puts op
- exit 1
- end
- end
- ## lib/tinderbox/gem_tinderbox.rb
- $TESTING = false unless defined? $TESTING
- require 'tinderbox'
- require 'tinderbox/gem_runner'
- require 'tinderbox/build'
- require 'rubygems/source_info_cache'
- require 'optparse'
- require 'rbconfig'
- require 'socket'
- require 'rubygems'
- require 'firebrigade/cache'
- class Tinderbox::GemTinderbox
- attr_accessor :root
- attr_accessor :timeout
- def self.process_args(args)
- opts_file = File.expand_path '~/.gem_tinderbox'
- options = {}
- if File.exist? opts_file then
- File.readlines(opts_file).map { |l| l.chomp.split '=', 2 }.each do |k,v|
- v = true if v == 'true'
- v = false if v == 'false'
- v = Integer(v) if k == 'Timeout'
- options[k.intern] = v
- end
- end
- options[:Daemon] ||= false
- options[:Timeout] ||= 120
- opts = OptionParser.new do |opts|
- opts.banner = "Usage: #{File.basename $0} [options]"
- opts.separator ''
- opts.separator 'Options may also be set in the options file ~/.gem_tinderbox.'
- opts.separator ''
- opts.separator 'Example ~/.gem_tinderbox'
- opts.separator "\tServer=firebrigade.example.com"
- opts.separator "\tUsername=my username"
- opts.separator "\tPassword=my password"
- opts.separator "\tRoot=/path/to/tinderbox/root"
- opts.separator ''
- opts.on("-s", "--server HOST",
- "Firebrigade server host",
- "Default: #{options[:Server].inspect}",
- "Options file name: Server") do |server|
- options[:Server] = server
- end
- opts.on("-u", "--username USERNAME",
- "Firebrigade username",
- "Default: #{options[:Username].inspect}",
- "Options file name: Username") do |username|
- options[:Username] = username
- end
- opts.on("-p", "--password PASSWORD",
- "Firebrigade password",
- "Default: Read from ~/.gem_tinderbox",
- "Options file name: Password") do |password|
- options[:Password] = password
- end
- opts.separator ''
- opts.on("-t", "--timeout TIMEOUT",
- "Maximum time to wait for a gem's tests to",
- "finish",
- "Default: #{options[:Timeout]}",
- Numeric) do |timeout|
- options[:Timeout] = timeout
- end
- opts.on("-r", "--root ROOT",
- "Root directory for gem tinderbox",
- "Default: #{options[:Root]}",
- "Gems will be lit on fire here.") do |root|
- options[:Root] = root
- end
- opts.on("-d", "--daemonize",
- "Run as a daemon process",
- "Default: #{options[:Daemon]}") do |daemon|
- options[:Daemon] = true
- end
- end
- opts.version = Tinderbox::VERSION
- opts.release = nil
- opts.parse! args
- if options[:Server].nil? or
- options[:Username].nil? or
- options[:Password].nil? then
- $stderr.puts opts
- $stderr.puts
- $stderr.puts "Firebrigade Server not set" if options[:Server].nil?
- $stderr.puts "Firebrigade Username not set" if options[:Username].nil?
- $stderr.puts "Firebrigade Password not set" if options[:Password].nil?
- exit 1
- end
- return options
- rescue OptionParser::ParseError
- $stderr.puts opts
- exit 1
- end
- def self.run(args = ARGV)
- options = process_args args
- tinderbox = new options[:Server], options[:Username], options[:Password]
- tinderbox.root = options[:Root]
- tinderbox.timeout = options[:Timeout]
- if options[:Daemon] then
- require 'webrick/server'
- WEBrick::Daemon.start
- end
- tinderbox.run
- rescue Interrupt, SystemExit # ignore
- rescue Exception => e
- puts "#{e.message}(#{e.class}):"
- puts "\t#{e.backtrace.join "\n\t"}"
- exit 1
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement