Parent

Tournament::WebguiInstaller

Constants

PRINCE_TARBALL
(Not documented)
RAILS_ENV
(Not documented)

Attributes

tmp_dir[RW]

(Not documented)

install_dir[R]

(Not documented)

source_dir[R]

(Not documented)

Public Class Methods

download(url, local_file, binary = false) click to toggle source

(Not documented)

    # File lib/tournament/webgui_installer.rb, line 18
18:   def self.download(url, local_file, binary = false)
19:     url = URI.parse(url)
20:     open_flag = binary ? "wb" : "w"
21:     Net::HTTP.start(url.host) do |http|
22:       File.open(local_file, open_flag) do |file|
23:         resp = http.get(url.path)
24:         file.write(resp.body)
25:       end
26:     end
27:   end
new(install_dir) click to toggle source

(Not documented)

    # File lib/tournament/webgui_installer.rb, line 13
13:   def initialize(install_dir)
14:     @install_dir = install_dir
15:     @source_dir = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'webgui'))
16:   end

Public Instance Methods

adjust_configuration(config_options = {}) click to toggle source

(Not documented)

    # File lib/tournament/webgui_installer.rb, line 35
35:   def adjust_configuration(config_options = {})
36:     config_file = File.expand_path(File.join(@source_dir, 'config', 'initializers', 'pool.rb'))
37:     target_config = File.expand_path(File.join(@install_dir, 'config', 'initializers', 'pool.rb'))
38:     puts "  -> Adjusting #{config_file} -> #{target_config}"
39:     config_contents = File.read(config_file)
40:     if config_options['email-server']
41:       smtp_config = {}
42:       smtp_config[:address] = config_options['email-server']
43:       smtp_config[:port] = config_options['email-port']
44:       smtp_config[:domain] = config_options['email-domain'] if config_options['email-domain']
45:       smtp_config[:user_name] = config_options['email-user'] if config_options['email-user']
46:       smtp_config[:password] = config_options['email-password'] if config_options['email-password']
47:       smtp_config[:authentication] = config_options['email-auth'].to_sym if config_options['email-auth']
48:       config_options['smtp-configuration'] = smtp_config
49:     end
50:     [
51:       ['site-name', 'TOURNAMENT_TITLE'],
52:       ['admin-email', 'ADMIN_EMAIL'],
53:       ['relative-root', 'RELATIVE_URL_ROOT'],
54:       ['smtp-configuration', 'SMTP_CONFIGURATION'],
55:       ['prince-path', 'PRINCE_PATH']
56:     ].each do |config_name, constant_name|
57:       if config_options[config_name]
58:         puts "  -> Setting config option #{config_name} to #{config_options[config_name]}"
59:         re = /#{constant_name} =([^\n]+)/m
60:         config_contents.gsub!(re) do |m|
61:           "#{constant_name} = #{config_options[config_name].inspect}\n"
62:         end
63:       else
64:         puts "  -> Not setting config option #{config_name}"
65:       end
66:     end
67: 
68:     puts "  -> Writing #{target_config}"
69:     File.open(target_config, "w") do |f|
70:       f.write config_contents
71:     end
72:   end
install_prince(prince_install_dir) click to toggle source

(Not documented)

     # File lib/tournament/webgui_installer.rb, line 74
 74:   def install_prince(prince_install_dir)
 75:     # install prince-xml if necessary
 76:     has_prince = ''
 77:     Open3.popen3('which prince') do |stdin, stdout, stderr|
 78:       has_prince << stdout.read
 79:       has_prince << stderr.read
 80:     end
 81:     if has_prince.empty? || has_prince =~ /no prince/
 82:       puts "Installing prince-xml ..."
 83:       Tournament::WebguiInstaller.download(PRINCE_TARBALL, "#{@tmp_dir}/prince.tgz", true)
 84:       system "tar xzf #{@tmp_dir}/prince.tgz -C #{@tmp_dir}"
 85: 
 86:       use_sudo = nil
 87:       if !File.exist?(prince_install_dir)
 88:         begin
 89:           FileUtils.makedirs(prince_install_dir)
 90:         rescue
 91:           puts "Could not create install dir for prince, using sudo"
 92:           use_sudo = "sudo "
 93:         end
 94:       elsif !File.writable?(prince_install_dir)
 95:         puts "Prince install directory is not writable, using sudo. You may be asked for your password."
 96:         use_sudo = "sudo "
 97:       end
 98:       puts "cd #{@tmp_dir}/prince-6.0r8-linux && #{use_sudo}bash install.sh"
 99:       system "cd #{@tmp_dir}/prince-6.0r8-linux && #{use_sudo}bash install.sh"
100:     else
101:       puts "prince-xml already installed: #{has_prince}"
102:     end
103:   end
install_webgui() click to toggle source

(Not documented)

    # File lib/tournament/webgui_installer.rb, line 29
29:   def install_webgui
30:     raise "Installation target #{@install_dir} exists and is NOT a directory." if File.exist?(@install_dir) && !File.directory?(@install_dir)
31:     FileUtils.mkdir_p(@install_dir) unless File.exist?(@install_dir)
32:     FileUtils.cp_r("#{@source_dir}/.", @install_dir, :preserve => false, :verbose => true)
33:   end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.