bin/pool in tournament-1.1.0 vs bin/pool in tournament-2.0.0
- old
+ new
@@ -1,12 +1,14 @@
#!/usr/bin/env ruby
-require File.expand_path(
- File.join(File.dirname(__FILE__), '..', 'lib', 'tournament'))
+require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'tournament'))
require 'rubygems'
require 'main'
require 'yaml'
+require 'fileutils'
+require 'net/http'
+require 'uri'
Main do
# Loads the pool from the save file. If the save file
# does not exist, creates a default pool
@@ -18,65 +20,184 @@
params['save-file'].value
end
def init_pool
@pool = Tournament::Pool.ncaa_2008
- @pool.bracket.scoring_strategy = Tournament::Bracket.strategy_for_name(params['scoring'].value)
+ @pool.scoring_strategy = Tournament::ScoringStrategy.strategy_for_name(params['scoring'].value)
end
def save_pool
if @pool
File.open(save_file_name, "w") do |f|
YAML::dump(@pool, f)
end
end
end
- option('save-file', 's') do
- optional
- argument :required
- default 'pool.yml'
- arity 1
- description "Save file for the pool."
+ mode('install_webgui') do
+ description 'Installs the Rails webgui.'
+ option('web-dir', 'W') do
+ required
+ argument :required
+ arity 1
+ description "Installation directory for the Rails application."
+ error(:after) { puts usage.to_s }
+ end
+ option('site-name', 'S') do
+ optional
+ argument :required
+ default 'Tournament'
+ arity 1
+ description "Web site name used in <title> tags an email subject lines."
+ end
+ option('relative-root', 'R') do
+ optional
+ argument :required
+ arity 1
+ description "Relative URL root if you are installing the web application as a subdirectory in an existing website."
+ end
+ option('admin-email') do
+ required
+ argument :required
+ arity 1
+ description "Email address of the admin account."
+ error(:after) { puts usage.to_s }
+ end
+ option('email-server') do
+ optional
+ argument :required
+ arity 1
+ description "SMTP email server name."
+ end
+ option('email-port') do
+ cast :int
+ optional
+ argument :required
+ default 25
+ arity 1
+ description "SMTP email server port."
+ end
+ option('email-domain') do
+ optional
+ argument :required
+ arity 1
+ description "SMTP email server HELO domain."
+ end
+ option('email-user') do
+ optional
+ argument :required
+ arity 1
+ description "SMTP email server user name."
+ end
+ option('email-password') do
+ optional
+ argument :required
+ arity 1
+ description "SMTP email server user name."
+ end
+ option('email-auth') do
+ optional
+ argument :required
+ default 'login'
+ arity 1
+ validate {|ea| ['login', 'plain', 'cram_md5'].include?(ea)}
+ description "SMTP email server authentication type."
+ end
+ option('use-princexml', 'X') do
+ optional
+ argument :required
+ arity 1
+ description "Location of prince xml command line program, or directory into which the program will be installed after being downloaded from the Prince XML website."
+ end
+ option('tmp-dir', 't') do
+ optional
+ argument :required
+ default '/tmp'
+ arity 1
+ description "Temp directory location."
+ end
+ def run
+ installer = Tournament::WebguiInstaller.new(params['web-dir'].value)
+ installer.tmp_dir = params['tmp-dir'].value
+ options = params.to_options
+ if params['use-princexml'].given?
+ prince_xml = params['use-princexml'].value
+ if File.exist?(prince_xml) && File.executable?(prince_xml) && !File.directory?(prince_xml)
+ puts "=> USING PRINCE XML EXECUTABLE #{prince_xml}"
+ elsif File.exist?(prince_xml) && File.executable?(prince_xml) && File.directory?(prince_xml)
+ puts "=> INSTALLING PRINCE XML INTO #{prince_xml}"
+ installer.install_prince(prince_xml)
+ prince_xml = File.join(prince_xml, 'bin', 'prince')
+ else
+ print usage.to_s
+ exit_warn!
+ end
+ options['prince-path'] = prince_xml
+ end
+ puts "=> INSTALLING TOURNAMENT WEB GUI INTO #{installer.install_dir}"
+ installer.install_webgui
+ puts "=> ADJUSTING TOURNAMENT WEB GUI CONFIGURATION"
+ installer.adjust_configuration(options)
+
+ puts "=> INSTALLATION COMPLETE."
+ puts "You should now change to #{installer.install_dir} and"
+ puts "perform the following steps:"
+ puts " 1. RAILS_ENV=production rake db:migrate"
+ puts " 2. RAILS_ENV=production rake \"admin:create[admin,#{params['admin-email'].value},Joe Admin,password]\""
+ puts " You should substitute your desired admin user login, name and password."
+ end
end
+ mixin :savefile do
+ option('save-file', 's') do
+ optional
+ argument :required
+ default 'pool.yml'
+ arity 1
+ description "Save file for the pool."
+ end
+ end
+
mode('setup') do
description "Sets up the pool the first time"
+ mixin :savefile
option('scoring', 'S') do
optional
argument :required
arity 1
default 'basic_scoring_strategy'
- validate {|s| Tournament::Bracket.available_strategies.include?(s)}
- description "Sets the scoring strategy, should be one of #{Tournament::Bracket.available_strategies.join(', ')}"
+ validate {|s| Tournament::ScoringStrategy.available_strategies.include?(s)}
+ description "Sets the scoring strategy, should be one of #{Tournament::ScoringStrategy.available_strategies.join(', ')}"
end
def run
init_pool
puts "Initialized new pool"
puts "Scoring:"
- puts @pool.bracket.scoring_strategy.description
+ puts @pool.scoring_strategy.description
save_pool
end
end
mode('update') do
+ mixin :savefile
option('entry', 'e') do
optional
argument :required
default 'tournament.yml'
arity 1
description "Update the tournament entry using supplied yaml file"
end
def run
load_pool
tournament = YAML::load_file(params['entry'].value)
- @pool.bracket = tournament.picks
+ @pool.tournament_entry = tournament
save_pool
end
end
mode('fee') do
+ mixin :savefile
argument('amount') do
required
cast :integer
arity 1
description "The fee charged per entry."
@@ -87,10 +208,11 @@
save_pool
end
end
mode('payout') do
+ mixin :savefile
option('constant-amount', 'C') do
optional
arity 1
cast :boolean
description "Specify if the payout is a constant amount rather than a percentage."
@@ -120,10 +242,11 @@
save_pool
end
end
mode('entry') do
+ mixin :savefile
option('add', 'a') do
optional
argument :required
arity -1
description "Add an entry yaml file to the pool"
@@ -149,25 +272,26 @@
end
end
end
mode('dump') do
+ mixin :savefile
option('entry', 'e') do
optional
argument :required
default 'tournament.yml'
description "Dump the pool entry object to a yaml file."
end
def run
load_pool
- tournament = Tournament::Entry.new('Tournament', @pool.bracket, 0)
File.open(params['entry'].value, "w") do |f|
- YAML::dump(tournament, f)
+ YAML::dump(@pool.tournament_entry, f)
end
end
end
mode('report') do
+ mixin :savefile
available_reports = Tournament::Pool.instance_methods(false).map do |name|
if idx = name.index("_report")
name[0,idx]
else
nil