skaes / railsbench

benchmarking tool for rails applications

This URL has Read+Write access

railsbench / install.rb
100755 71 lines (58 sloc) 2.211 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env ruby
 
require 'fileutils'
if ARGV.include?('--dry-run')
  include FileUtils::DryRun
else
  include FileUtils::Verbose
end
 
require 'yaml'
 
unless ENV['RAILS_ROOT']
  if File.exists? "config/environment.rb"
    ENV['RAILS_ROOT'] = File.expand_path "."
  else
    $stderr.puts "RAILS_ROOT must be fined in your environment"
    exit 1
  end
end
 
RAILS_ROOT = ENV['RAILS_ROOT']
RAILS_CONFIG = RAILS_ROOT + "/config/"
RAILS_ENVS = RAILS_ROOT + "/config/environments/"
RAILSBENCH_BASE = File.expand_path(File.dirname(__FILE__)) unless defined? RAILSBENCH_BASE
 
if ARGV.first == 'help'
  File.open("#{RAILSBENCH_BASE}/INSTALL").each_line{|l| puts l}
end
 
install("#{RAILSBENCH_BASE}/config/benchmarks.rb", RAILS_CONFIG, :mode => 0644) unless
  File.exists?(RAILS_CONFIG + "benchmarks.rb")
 
install("#{RAILSBENCH_BASE}/config/benchmarks.yml", RAILS_CONFIG, :mode => 0644) unless
  File.exists?(RAILS_CONFIG + "benchmarks.yml")
 
cp(RAILS_ENVS + "production.rb", RAILS_ENVS + "benchmarking.rb") unless
  File.exists?(RAILS_ENVS + "benchmarking.rb")
 
database = YAML::load(File.open(RAILS_CONFIG + "database.yml"))
unless database["benchmarking"]
  puts "creating database configuration: benchmarking"
  File.open(RAILS_CONFIG + "database.yml", "ab") do |file|
    file.puts "\nbenchmarking:\n"
    database['development'].each do |k, v|
      file.puts " #{k}: #{v}"
    end
  end
end
 
__END__
 
### Local Variables: ***
### mode:ruby ***
### End: ***
 
# Copyright (C) 2005-2008 Stefan Kaes
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA