rconf 0.9.25 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/bin/rconf +42 -15
- data/lib/rconf/configurator.rb +29 -34
- data/lib/rconf/configurators/build_configurator.rb +6 -8
- data/lib/rconf/configurators/bundler_configurator.rb +4 -6
- data/lib/rconf/configurators/cassandra_configurator.rb +5 -7
- data/lib/rconf/configurators/execute_configurator.rb +3 -5
- data/lib/rconf/configurators/git_repo_configurator.rb +3 -5
- data/lib/rconf/configurators/mercurial_configurator.rb +1 -1
- data/lib/rconf/configurators/packages_configurator.rb +5 -5
- data/lib/rconf/configurators/passenger_configurator.rb +3 -3
- data/lib/rconf/configurators/ruby_configurator.rb +3 -5
- data/lib/rconf/overrides_language.rb +145 -0
- data/lib/rconf/version.rb +2 -2
- data/lib/rconf.rb +1 -0
- data/rconf.rconf +2 -2
- data/spec/configurator_spec.rb +14 -2
- data/spec/configurators/bundler_configurator_spec.rb +9 -0
- data/spec/language_spec.rb +12 -3
- data/spec/overrides_language_spec.rb +37 -0
- metadata +20 -7
data/.gitignore
CHANGED
data/bin/rconf
CHANGED
@@ -22,7 +22,7 @@ module RightConf
|
|
22
22
|
|
23
23
|
def self.run
|
24
24
|
opts = Trollop::options do
|
25
|
-
version "rconf #{VERSION} (c)
|
25
|
+
version "rconf #{VERSION} (c) 2012 RightScale"
|
26
26
|
banner <<-EOS
|
27
27
|
#{DESCRIPTION}
|
28
28
|
|
@@ -34,11 +34,12 @@ where [options] are:
|
|
34
34
|
|
35
35
|
opt :configurators, 'Show available configurators'
|
36
36
|
opt :platform, 'Show current platform'
|
37
|
+
opt :overrides, 'Show current overrides'
|
37
38
|
opt :update, 'Update rconf to latest version'
|
38
39
|
opt :remove, 'Remove rconf from all gemsets'
|
39
40
|
opt :config, 'Set path to configuration file', :type => :string
|
40
41
|
opt :output, 'Output file (output to STDOUT by default)', :type => :string
|
41
|
-
opt :reconfigure, 'Bypass all checks and force configuration'
|
42
|
+
opt :reconfigure, 'Bypass all checks and force configuration and ignore overrides'
|
42
43
|
opt :force, 'Run rconf even if configuration file has not changed'
|
43
44
|
opt :verbose,'Print debug output'
|
44
45
|
end
|
@@ -62,6 +63,8 @@ where [options] are:
|
|
62
63
|
new.list_configurators
|
63
64
|
elsif opts[:platform]
|
64
65
|
new.show_platform
|
66
|
+
elsif opts[:overrides]
|
67
|
+
new.show_overrides
|
65
68
|
elsif opts[:update]
|
66
69
|
new.update
|
67
70
|
elsif opts[:remove]
|
@@ -81,16 +84,14 @@ where [options] are:
|
|
81
84
|
puts "== #{key} ==".bold
|
82
85
|
puts configurator.desc
|
83
86
|
puts 'Settings:'
|
84
|
-
max_size = configurator.all_settings.
|
85
|
-
configurator.all_settings.each do |
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
puts
|
93
|
-
end
|
87
|
+
max_size = configurator.all_settings.map { |s| s[:name] }.map(&:size).max
|
88
|
+
configurator.all_settings.each do |setting|
|
89
|
+
name = setting[:name]
|
90
|
+
desc = setting[:description]
|
91
|
+
options = setting[:options].keys.map { |k| "[#{k}]" }.join(' ')
|
92
|
+
num_spaces = max_size - name.size + 1
|
93
|
+
print " - #{name.blue}:#{' ' * num_spaces}#{desc}"
|
94
|
+
puts ' ' + options.green
|
94
95
|
end
|
95
96
|
puts
|
96
97
|
end
|
@@ -107,6 +108,32 @@ where [options] are:
|
|
107
108
|
puts "Release: #{Platform.release}"
|
108
109
|
end
|
109
110
|
|
111
|
+
# List current overrides as defined in ~/.rconf_overrides
|
112
|
+
#
|
113
|
+
# === Return
|
114
|
+
# true:: Always return true
|
115
|
+
def show_overrides
|
116
|
+
if !File.readable?(OverridesLanguage::OVERRIDES_FILE)
|
117
|
+
puts "No rconf overrides file at #{OverridesLanguage::OVERRIDES_FILE}"
|
118
|
+
else
|
119
|
+
overrides = OverridesLanguage.load
|
120
|
+
if overrides
|
121
|
+
puts "Loading overrides from #{OverridesLanguage::OVERRIDES_FILE}"
|
122
|
+
msg = ''
|
123
|
+
overrides.each do |key, setting|
|
124
|
+
msg += "* #{key}\n" +
|
125
|
+
msg += setting.inject([]) do |m, (name, value)|
|
126
|
+
m << " - #{name} = #{value}"
|
127
|
+
m
|
128
|
+
end.join("\n")
|
129
|
+
end
|
130
|
+
puts msg
|
131
|
+
else
|
132
|
+
puts "Failed to load overrides from #{OverridesLanguage::OVERRIDES_FILE}: #{OverridesLanguage.parse_error.error_message}"
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
110
137
|
# Update rconf to latest in all installed rubies
|
111
138
|
#
|
112
139
|
# === Return
|
@@ -116,7 +143,7 @@ where [options] are:
|
|
116
143
|
report_check 'Retrieving latest rconf...'
|
117
144
|
json = Command.execute('curl', '-s', 'http://rubygems.org/api/v1/gems/rconf.json').output
|
118
145
|
json =~ /"version":"([^"]+)"/
|
119
|
-
|
146
|
+
version = Regexp.last_match(1)
|
120
147
|
report_fatal 'Failed to retrieve rconf gem information, check network connectivity' unless version
|
121
148
|
report_success
|
122
149
|
report('Latest rconf version is ' + version.blue)
|
@@ -166,11 +193,11 @@ where [options] are:
|
|
166
193
|
report_check("Checking rconf for #{ruby}@#{gs}")
|
167
194
|
rconf = Command.execute('rvm', "#{ruby}@#{gs}", 'gem', 'list', 'rconf').output
|
168
195
|
if rconf =~ /rconf \(#{version}/
|
169
|
-
|
196
|
+
report_success
|
170
197
|
elsif rconf =~ /^rconf /
|
171
198
|
report_failure
|
172
199
|
report_check("Updating rconf for #{ruby}@#{gs}")
|
173
|
-
res = Command.execute('rvm', "#{ruby}@#{gs}", 'gem', 'install',
|
200
|
+
res = Command.execute('rvm', "#{ruby}@#{gs}", 'gem', 'install',
|
174
201
|
'rconf', '-v', version, '--no-ri', '--no-rdoc')
|
175
202
|
report_result(res.success?)
|
176
203
|
else
|
data/lib/rconf/configurator.rb
CHANGED
@@ -22,16 +22,13 @@ module RightConf
|
|
22
22
|
|
23
23
|
# Key associated with configurator
|
24
24
|
attr_reader :key
|
25
|
-
|
25
|
+
|
26
26
|
# Description
|
27
27
|
attr_reader :desc
|
28
28
|
|
29
29
|
# Access to settings for documentation
|
30
30
|
attr_reader :all_settings
|
31
31
|
|
32
|
-
# Access to required settings for validation
|
33
|
-
attr_reader :required_settings
|
34
|
-
|
35
32
|
# Associate configurator with given key
|
36
33
|
#
|
37
34
|
# === Parameters
|
@@ -57,32 +54,25 @@ module RightConf
|
|
57
54
|
true
|
58
55
|
end
|
59
56
|
|
60
|
-
# Store
|
57
|
+
# Store setting definition
|
58
|
+
# A definition consists of a name, a description and optionally options
|
59
|
+
# Possible options are:
|
60
|
+
# :required => true|false Whether the setting is required
|
61
61
|
#
|
62
62
|
# === Parameters
|
63
63
|
# settings(Hash):: Settings descriptions indexed by names
|
64
64
|
#
|
65
65
|
# === Return
|
66
66
|
# true:: Always return true
|
67
|
-
def
|
68
|
-
|
69
|
-
|
67
|
+
def setting(name, description, options={})
|
68
|
+
@all_settings ||= [{ :name => 'only_if',
|
69
|
+
:description => 'Ruby code that should return true for configurator to proceed',
|
70
|
+
:options => {} }]
|
71
|
+
@all_settings << { :name => name, :description => description, :options => options || {} }
|
70
72
|
true
|
71
73
|
end
|
72
74
|
|
73
|
-
|
74
|
-
#
|
75
|
-
# === Parameters
|
76
|
-
# settings(Array):: List of settings that should be checked
|
77
|
-
#
|
78
|
-
# === Return
|
79
|
-
# true:: Always return true
|
80
|
-
def validate_has_settings(*settings)
|
81
|
-
@required_settings = settings.flatten
|
82
|
-
true
|
83
|
-
end
|
84
|
-
|
85
|
-
end
|
75
|
+
end
|
86
76
|
|
87
77
|
# Extend base class with ClassMethods module methods
|
88
78
|
#
|
@@ -98,16 +88,21 @@ module RightConf
|
|
98
88
|
# nil:: If settings are valid for this configurator
|
99
89
|
# error(String):: Error message otherwise
|
100
90
|
def validate
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
91
|
+
@settings_values.merge!(OverridesLanguage.overrides_for(self.class.key.to_s)) unless Profile.force_reconfigure?
|
92
|
+
if e = OverridesLanguage.parse_error
|
93
|
+
error = "Could not load overrides file '#{OverridesLanguage::OVERRIDES_FILE}' (#{e.message})"
|
94
|
+
else
|
95
|
+
required = self.class.all_settings.select { |s| s[:options][:required] }.map { |s| s[:name] }
|
96
|
+
return nil unless required
|
97
|
+
missing = required.select { |s| !@settings_values.include?(s) }
|
98
|
+
error = case missing.size
|
99
|
+
when 0 then nil
|
100
|
+
when 1 then "Required setting #{missing.first} is "
|
101
|
+
else
|
102
|
+
"Required settings #{missing.join(', ')} are "
|
103
|
+
end
|
104
|
+
error += "missing for configuration section '#{self.class.key}'" if error
|
109
105
|
end
|
110
|
-
error += "missing for configuration section '#{self.class.key}'" if error
|
111
106
|
error
|
112
107
|
end
|
113
108
|
|
@@ -124,7 +119,7 @@ module RightConf
|
|
124
119
|
#
|
125
120
|
# === Parameters
|
126
121
|
# args:: Pass-through arguments, given to platform specific implementation
|
127
|
-
#
|
122
|
+
#
|
128
123
|
# === Return
|
129
124
|
# true:: Always return true
|
130
125
|
def run(*args)
|
@@ -168,7 +163,7 @@ module RightConf
|
|
168
163
|
# value:: Value of configuration option if there is one
|
169
164
|
# nil:: Otherwise
|
170
165
|
def [](config_option)
|
171
|
-
@settings_values[config_option]
|
166
|
+
@settings_values[config_option.to_s]
|
172
167
|
end
|
173
168
|
|
174
169
|
protected
|
@@ -192,10 +187,10 @@ module RightConf
|
|
192
187
|
if self.public_methods.include?("#{method_name}=")
|
193
188
|
res = self.send("#{method_name}=", value)
|
194
189
|
else
|
195
|
-
res = @settings_values[meth] = value
|
190
|
+
res = @settings_values[meth.to_s] = value
|
196
191
|
end
|
197
192
|
end
|
198
|
-
res || @settings_values[meth]
|
193
|
+
res || @settings_values[meth.to_s]
|
199
194
|
end
|
200
195
|
|
201
196
|
# Initialize configuration settings hash and index
|
@@ -19,16 +19,14 @@ module RightConf
|
|
19
19
|
|
20
20
|
description 'Builds a repository using the ./configure, make, make install commands'
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
22
|
+
setting 'path', 'Path to source files', :required => true
|
23
|
+
setting 'tarball_url', 'URL to source code tarball to be downloaded, supports .tgz and .zip'
|
24
|
+
setting 'tarball_dir', 'Name of directory created when untaring tarball, required if "tarball_url" is set'
|
25
|
+
setting 'pre_step', 'Command ran prior to ./configure'
|
26
|
+
setting 'message', 'Progress message to display if any while building'
|
27
|
+
setting 'configure_opts', 'Hash of options to be given to the configure script. ' +
|
28
28
|
'The keys are the platform families (:darwin, :linux or :windows)'
|
29
29
|
|
30
|
-
validate_has_settings :path
|
31
|
-
|
32
30
|
# No way to check, return false
|
33
31
|
#
|
34
32
|
# === Return
|
@@ -21,12 +21,10 @@ module RightConf
|
|
21
21
|
|
22
22
|
description 'Installs bundler and runs "bundle install"'
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
validate_has_settings :version
|
24
|
+
setting 'version', 'Version of bundler gem, e.g. "1.0.21"', :required => true
|
25
|
+
setting 'exclusions', 'Comma separated list of gem groups to be excluded when installing bundle'
|
26
|
+
setting 'bundle_path', 'Path where bundle should be installed'
|
27
|
+
setting 'gem_path', 'Path to bundler gem, e.g. "vendor/system_gems/cache"'
|
30
28
|
|
31
29
|
# Check whether bundler is already installed
|
32
30
|
#
|
@@ -22,13 +22,11 @@ module RightConf
|
|
22
22
|
|
23
23
|
description 'Installs Cassandra'
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
'is writable by the current user or ~/cassandra otherwise by default'
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
validate_has_settings :version
|
25
|
+
setting 'version', 'Cassandra version to install', :required => true
|
26
|
+
setting 'install_path', 'Path to Cassandra installation directory, uses /opt/cassandra if it ' +
|
27
|
+
'is writable by the current user or ~/cassandra otherwise by default'
|
28
|
+
setting 'abort_on_failure','Whether to abort if Cassandra failed to install (false by default)'
|
29
|
+
setting 'endpoint_snitch', 'Set custom endpoint snitch for installed cassandra'
|
32
30
|
|
33
31
|
# Check whether Cassandra is installed
|
34
32
|
#
|
@@ -19,13 +19,11 @@ module RightConf
|
|
19
19
|
|
20
20
|
description 'Run arbitrary shell commands'
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
setting 'command_line', 'Command line to run', :required => true
|
23
|
+
setting 'message', 'Progress message to display if any while command is running'
|
24
|
+
setting 'abort_on_failure', 'Message to display when aborting configuration if command fails. ' +
|
25
25
|
'Do not abort if not set'
|
26
26
|
|
27
|
-
validate_has_settings :command_line
|
28
|
-
|
29
27
|
# No way to check, return false
|
30
28
|
#
|
31
29
|
# === Return
|
@@ -19,11 +19,9 @@ module RightConf
|
|
19
19
|
|
20
20
|
description 'Clone git repository and build if needed'
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
validate_has_settings :repo, :path
|
22
|
+
setting 'repo','git repo URL', :required => true
|
23
|
+
setting 'path','Path where git repo should be cloned to', :required => true
|
24
|
+
setting 'tag', 'git tag or branch or sha that should be checked out ("master" by default)'
|
27
25
|
|
28
26
|
# Check whether repo was already cloned
|
29
27
|
#
|
@@ -24,7 +24,7 @@ module RightConf
|
|
24
24
|
|
25
25
|
description 'Installs Mercurial'
|
26
26
|
|
27
|
-
|
27
|
+
setting 'abort_on_failure', 'Whether to abort if Mercurial failed to install (false by default)'
|
28
28
|
|
29
29
|
# Check whether Mercurial is installed
|
30
30
|
#
|
@@ -19,11 +19,11 @@ module RightConf
|
|
19
19
|
|
20
20
|
description 'Installs packages defined for running platform'
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
setting 'debian', 'Packages to be installed on Debian based Linux'
|
23
|
+
setting 'centos', 'Packages to be installed on RedHat / Centos'
|
24
|
+
setting 'windows', 'Softwared to be downloaded and installed on Windows'
|
25
|
+
setting 'darwin', 'Brew packages to be installed on Mac OS X (https://github.com/mxcl/homebrew)'
|
26
|
+
setting 'abort_on_failure', 'Whether to abort if packages failed to install (false by default)'
|
27
27
|
|
28
28
|
# Let package manager check for idempotency, return false
|
29
29
|
#
|
@@ -28,9 +28,9 @@ module RightConf
|
|
28
28
|
'passenger section then that ruby will be used, otherwise ' +
|
29
29
|
'the default ruby will.'
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
setting 'library_src_path', "Path to library sources, #{File.expand_path(File.join(Dir.getwd, '..', 'library'))} by default"
|
32
|
+
setting 'gem_version', "Passenger gem version #{PASSENGER_GEM_VERSION} by default"
|
33
|
+
setting 'install_path', 'Path to nginx installation directory, uses /opt/nginx if it ' +
|
34
34
|
'is writable by the current user or ~/nginx otherwise by default'
|
35
35
|
|
36
36
|
# Check that passenger gem is installed and that passenger+nginx is installed
|
@@ -20,11 +20,9 @@ module RightConf
|
|
20
20
|
description "Installs ruby interpreter and rubygems.\n" +
|
21
21
|
'Installs and uses rvm on supported (i.e. non-Windows) platforms'
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
validate_has_settings :version
|
23
|
+
setting 'version', 'Ruby version using rvm notation (see "rvm list known")', :required => true
|
24
|
+
setting 'rubygems', 'Rubygems version, e.g. "1.3.7"'
|
25
|
+
setting 'gemset', 'Gemset to be used for platforms supporting rvm'
|
28
26
|
|
29
27
|
# RVM version used to install rubies
|
30
28
|
RVM_VERSION = '1.10.2'
|
@@ -0,0 +1,145 @@
|
|
1
|
+
# Copyright (C) 2011-2012 RightScale, Inc, All Rights Reserved Worldwide.
|
2
|
+
#
|
3
|
+
# THIS PROGRAM IS CONFIDENTIAL AND PROPRIETARY TO RIGHTSCALE
|
4
|
+
# AND CONSTITUTES A VALUABLE TRADE SECRET. Any unauthorized use,
|
5
|
+
# reproduction, modification, or disclosure of this program is
|
6
|
+
# strictly prohibited. Any use of this program by an authorized
|
7
|
+
# licensee is strictly subject to the terms and conditions,
|
8
|
+
# including confidentiality obligations, set forth in the applicable
|
9
|
+
# License Agreement between RightScale.com, Inc. and
|
10
|
+
# the licensee
|
11
|
+
|
12
|
+
module RightConf
|
13
|
+
|
14
|
+
# Defines ~/.rconf_overrides file DSL
|
15
|
+
class OverridesLanguage
|
16
|
+
|
17
|
+
# Path to overrides file
|
18
|
+
OVERRIDES_FILE = File.join(ENV['HOME'], '.rconf_overrides')
|
19
|
+
|
20
|
+
# Return override for given configurator setting if any
|
21
|
+
#
|
22
|
+
# === Parameters
|
23
|
+
# key(String):: Configurator key
|
24
|
+
# setting(String):: Setting name
|
25
|
+
#
|
26
|
+
# === Return
|
27
|
+
# value(String||Nil):: Override value if any, nil otherwise
|
28
|
+
def self.overrides_for(key)
|
29
|
+
self.load unless @overrides
|
30
|
+
@overrides && @overrides[key] || {}
|
31
|
+
end
|
32
|
+
|
33
|
+
# Load overrides from file
|
34
|
+
#
|
35
|
+
# === Return
|
36
|
+
# overrides(Hash):: Loaded overrides
|
37
|
+
def self.load
|
38
|
+
return @overrides if @overrides
|
39
|
+
return {} unless File.readable?(OVERRIDES_FILE)
|
40
|
+
@overrides = self.parse(IO.read(OVERRIDES_FILE)) || {}
|
41
|
+
end
|
42
|
+
|
43
|
+
# Persist overrides to overrides file
|
44
|
+
#
|
45
|
+
# === Return
|
46
|
+
# true:: Always return true
|
47
|
+
def self.save
|
48
|
+
File.open(OVERRIDES_FILE, 'w') do |f|
|
49
|
+
@overrides.each do |key, settings|
|
50
|
+
settings.each do |name, value|
|
51
|
+
f.puts "#{key}.#{name}=#{value}"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
true
|
56
|
+
end
|
57
|
+
|
58
|
+
# Return parse errors from last call to 'parse' if any
|
59
|
+
def self.parse_error
|
60
|
+
@parse_error
|
61
|
+
end
|
62
|
+
|
63
|
+
protected
|
64
|
+
|
65
|
+
# Load overrides from config file and produce hash of
|
66
|
+
# overrides keyed by configurator and setting name
|
67
|
+
#
|
68
|
+
# === Parameters
|
69
|
+
# source(String):: Overrides text
|
70
|
+
#
|
71
|
+
# === Return
|
72
|
+
# overrides(Hash):: Overrides hash
|
73
|
+
def self.parse(source)
|
74
|
+
@parse_error = nil
|
75
|
+
@overrides = nil
|
76
|
+
overrides = Object.new
|
77
|
+
ConfiguratorRegistry.each do |key, configurator|
|
78
|
+
klass, code = override_class_code(key, configurator)
|
79
|
+
overrides.class.class_eval(code)
|
80
|
+
overrides.instance_eval("@#{key} = #{klass}.new")
|
81
|
+
end
|
82
|
+
begin
|
83
|
+
source.split("\n").each do |o|
|
84
|
+
operands = o.gsub(/\s+/, '').split('=')
|
85
|
+
if operands.size != 2
|
86
|
+
raise "Invalid syntax '#{o}', must be of the form 'key.setting=value'"
|
87
|
+
end
|
88
|
+
if operands[1].start_with?('"') || operands[1].start_with?("'")
|
89
|
+
value = operands[1]
|
90
|
+
else
|
91
|
+
value = "'#{operands[1]}'"
|
92
|
+
end
|
93
|
+
overrides.instance_eval("@#{operands[0]}=#{value}")
|
94
|
+
end
|
95
|
+
rescue Exception => e
|
96
|
+
@overrides = nil
|
97
|
+
@parse_error = e
|
98
|
+
end
|
99
|
+
@overrides
|
100
|
+
end
|
101
|
+
|
102
|
+
# Add override read from overrides file
|
103
|
+
#
|
104
|
+
# === Paramaters
|
105
|
+
# key(String):: Configurator key
|
106
|
+
# setting(String):: Setting name
|
107
|
+
# value(String):: Override value
|
108
|
+
#
|
109
|
+
# === Return
|
110
|
+
# true:: Always return true
|
111
|
+
def self.add_override(key, setting, value)
|
112
|
+
@overrides ||= {}
|
113
|
+
@overrides[key] ||= {}
|
114
|
+
@overrides[key][setting] = value
|
115
|
+
true
|
116
|
+
end
|
117
|
+
|
118
|
+
# Build code for override class associated with given configurator
|
119
|
+
# That class defines one setter method per setting which sets
|
120
|
+
# the value in the @overrides class variable of *this*
|
121
|
+
# (OverridesLanguage) class
|
122
|
+
#
|
123
|
+
# === Parameters
|
124
|
+
# key(String):: Configurator key
|
125
|
+
# configurator(Class):: Configurator class
|
126
|
+
#
|
127
|
+
# === Return
|
128
|
+
# res(Array):: Pair of class name and class ruby code
|
129
|
+
def self.override_class_code(key, configurator)
|
130
|
+
klass = key.capitalize
|
131
|
+
code = "class #{klass}\n"
|
132
|
+
configurator.all_settings.each do |s|
|
133
|
+
code += <<-EOS
|
134
|
+
def #{s[:name]}=(val)
|
135
|
+
OverridesLanguage.add_override('#{key}', '#{s[:name]}', val)
|
136
|
+
end
|
137
|
+
EOS
|
138
|
+
end
|
139
|
+
code += 'end'
|
140
|
+
[klass, code]
|
141
|
+
end
|
142
|
+
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
data/lib/rconf/version.rb
CHANGED
data/lib/rconf.rb
CHANGED
@@ -18,6 +18,7 @@ require File.join(BASE_DIR, 'command')
|
|
18
18
|
require File.join(BASE_DIR, 'configurator_registry')
|
19
19
|
require File.join(BASE_DIR, 'configurator')
|
20
20
|
require File.join(BASE_DIR, 'language')
|
21
|
+
require File.join(BASE_DIR, 'overrides_language')
|
21
22
|
require File.join(BASE_DIR, 'platform')
|
22
23
|
require File.join(BASE_DIR, 'profile')
|
23
24
|
require File.join(BASE_DIR, 'trollop')
|
data/rconf.rconf
CHANGED
data/spec/configurator_spec.rb
CHANGED
@@ -16,8 +16,8 @@ describe RightConf::Configurator do
|
|
16
16
|
class TestConfigurator
|
17
17
|
include RightConf::Configurator
|
18
18
|
register :test
|
19
|
-
|
20
|
-
|
19
|
+
attr_accessor :custom_setting
|
20
|
+
setting 'required', 'required setting', :required => true
|
21
21
|
def test_setter(value)
|
22
22
|
@custom_setting = value
|
23
23
|
end
|
@@ -34,10 +34,22 @@ describe RightConf::Configurator do
|
|
34
34
|
register :another
|
35
35
|
end
|
36
36
|
|
37
|
+
before(:all) do
|
38
|
+
# Disable overrides
|
39
|
+
RightConf::OverridesLanguage.instance_variable_set(:@overrides, {})
|
40
|
+
end
|
41
|
+
|
37
42
|
before(:each) do
|
38
43
|
@configurator = TestConfigurator.new(1)
|
39
44
|
end
|
40
45
|
|
46
|
+
after(:all) do
|
47
|
+
confs = RightConf::ConfiguratorRegistry.instance.instance_variable_get(:@configurators)
|
48
|
+
confs.delete(:test)
|
49
|
+
confs.delete(:another)
|
50
|
+
RightConf::OverridesLanguage.instance_variable_set(:@overrides, nil)
|
51
|
+
end
|
52
|
+
|
41
53
|
it 'should register configurators' do
|
42
54
|
RightConf::ConfiguratorRegistry[:test].should == TestConfigurator
|
43
55
|
RightConf::ConfiguratorRegistry[:another].should == AnotherConfigurator
|
@@ -17,6 +17,15 @@ describe RightConf::BundlerConfigurator do
|
|
17
17
|
flexmock('res', :success? => true, :output => output)
|
18
18
|
end
|
19
19
|
|
20
|
+
before(:all) do
|
21
|
+
# Disable overrides
|
22
|
+
RightConf::OverridesLanguage.instance_variable_set(:@overrides, {})
|
23
|
+
end
|
24
|
+
|
25
|
+
after(:all) do
|
26
|
+
RightConf::OverridesLanguage.instance_variable_set(:@overrides, nil)
|
27
|
+
end
|
28
|
+
|
20
29
|
before(:each) do
|
21
30
|
@configurator = create_configurator('bundler { version "0" }')
|
22
31
|
RightConf::Command.instance.instance_variable_set(:@rvm_prefix, 'r@g')
|
data/spec/language_spec.rb
CHANGED
@@ -13,6 +13,15 @@ require File.join(File.dirname(__FILE__), 'spec_helper')
|
|
13
13
|
|
14
14
|
describe RightConf::Language do
|
15
15
|
|
16
|
+
before(:all) do
|
17
|
+
# Disable overrides
|
18
|
+
RightConf::OverridesLanguage.instance_variable_set(:@overrides, {})
|
19
|
+
end
|
20
|
+
|
21
|
+
after(:all) do
|
22
|
+
RightConf::OverridesLanguage.instance_variable_set(:@overrides, nil)
|
23
|
+
end
|
24
|
+
|
16
25
|
it 'should invalidate missing blocks' do
|
17
26
|
lang = RightConf::Language.parse('toto')
|
18
27
|
lang.validation_errors.size.should == 1
|
@@ -31,7 +40,7 @@ describe RightConf::Language do
|
|
31
40
|
lang.configurators.size.should == 1
|
32
41
|
lang.configurators.first.class.should == RightConf::RubyConfigurator
|
33
42
|
lang.configurators.first.instance_variable_get(:@settings_values).should ==
|
34
|
-
{
|
43
|
+
{ 'version' => '1', 'rubygems' => '2' }
|
35
44
|
end
|
36
45
|
|
37
46
|
it 'should parse multiple configurations' do
|
@@ -49,10 +58,10 @@ describe RightConf::Language do
|
|
49
58
|
lang.configurators.size.should == 2
|
50
59
|
lang.configurators[0].class.should == RightConf::RubyConfigurator
|
51
60
|
lang.configurators[0].instance_variable_get(:@settings_values).should ==
|
52
|
-
{
|
61
|
+
{ 'version' => '1', 'rubygems' => '2' }
|
53
62
|
lang.configurators[1].class.should == RightConf::BundlerConfigurator
|
54
63
|
lang.configurators[1].instance_variable_get(:@settings_values).should ==
|
55
|
-
{
|
64
|
+
{ 'version' => '3' }
|
56
65
|
end
|
57
66
|
|
58
67
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# Copyright (C) 2011-2012 RightScale, Inc, All Rights Reserved Worldwide.
|
2
|
+
#
|
3
|
+
# THIS PROGRAM IS CONFIDENTIAL AND PROPRIETARY TO RIGHTSCALE
|
4
|
+
# AND CONSTITUTES A VALUABLE TRADE SECRET. Any unauthorized use,
|
5
|
+
# reproduction, modification, or disclosure of this program is
|
6
|
+
# strictly prohibited. Any use of this program by an authorized
|
7
|
+
# licensee is strictly subject to the terms and conditions,
|
8
|
+
# including confidentiality obligations, set forth in the applicable
|
9
|
+
# License Agreement between RightScale.com, Inc. and
|
10
|
+
# the licensee
|
11
|
+
|
12
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
13
|
+
|
14
|
+
describe RightConf::OverridesLanguage do
|
15
|
+
|
16
|
+
it 'should load overrides' do
|
17
|
+
hash = RightConf::OverridesLanguage.parse("ruby.version='2.0'\nbundler.version = 3.0")
|
18
|
+
if e = RightConf::OverridesLanguage.parse_error
|
19
|
+
puts "Failed to parse overrides: #{e.message}"
|
20
|
+
end
|
21
|
+
hash.size.should == 2
|
22
|
+
hash['ruby'].size.should == 1
|
23
|
+
hash['ruby']['version'].should == '2.0'
|
24
|
+
hash['bundler'].size.should == 1
|
25
|
+
hash['bundler']['version'].should == '3.0'
|
26
|
+
RightConf::OverridesLanguage.parse_error.should be_nil
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should catch errors' do
|
30
|
+
hash = RightConf::OverridesLanguage.parse('foo')
|
31
|
+
hash.should be_nil
|
32
|
+
RightConf::OverridesLanguage.parse_error.should_not be_nil
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rconf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-11-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: '2.5'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '2.5'
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: flexmock
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ~>
|
@@ -32,7 +37,12 @@ dependencies:
|
|
32
37
|
version: '0.9'
|
33
38
|
type: :development
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0.9'
|
36
46
|
description: ! 'rconf configures the environment for a given application. rconf reads
|
37
47
|
|
38
48
|
the content of an application configuration file and installs and/or
|
@@ -76,6 +86,7 @@ files:
|
|
76
86
|
- lib/rconf/configurators/passenger_configurator.rb
|
77
87
|
- lib/rconf/configurators/ruby_configurator.rb
|
78
88
|
- lib/rconf/language.rb
|
89
|
+
- lib/rconf/overrides_language.rb
|
79
90
|
- lib/rconf/platform.rb
|
80
91
|
- lib/rconf/platforms/darwin.rb
|
81
92
|
- lib/rconf/platforms/linux.rb
|
@@ -102,6 +113,7 @@ files:
|
|
102
113
|
- spec/configurators/passenger_configurator_spec.rb
|
103
114
|
- spec/configurators/ruby_configurator_spec.rb
|
104
115
|
- spec/language_spec.rb
|
116
|
+
- spec/overrides_language_spec.rb
|
105
117
|
- spec/platform_spec.rb
|
106
118
|
- spec/profile_spec.rb
|
107
119
|
- spec/progress_reporters/base_reporter_spec.rb
|
@@ -130,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
130
142
|
version: '0'
|
131
143
|
requirements: []
|
132
144
|
rubyforge_project: rconf
|
133
|
-
rubygems_version: 1.8.
|
145
|
+
rubygems_version: 1.8.24
|
134
146
|
signing_key:
|
135
147
|
specification_version: 3
|
136
148
|
summary: Cross platform environment configuration
|
@@ -144,6 +156,7 @@ test_files:
|
|
144
156
|
- spec/configurators/passenger_configurator_spec.rb
|
145
157
|
- spec/configurators/ruby_configurator_spec.rb
|
146
158
|
- spec/language_spec.rb
|
159
|
+
- spec/overrides_language_spec.rb
|
147
160
|
- spec/platform_spec.rb
|
148
161
|
- spec/profile_spec.rb
|
149
162
|
- spec/progress_reporters/base_reporter_spec.rb
|