rconf 0.7.10 → 0.7.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -65,7 +65,8 @@ module RightConf
65
65
  # === Return
66
66
  # true:: Always return true
67
67
  def settings(settings)
68
- @all_settings = settings
68
+ default_settings = { :only_if => 'Ruby code that should return true for configurator to proceed' }
69
+ @all_settings = settings.merge(default_settings)
69
70
  true
70
71
  end
71
72
 
@@ -97,7 +98,6 @@ module RightConf
97
98
  # nil:: If settings are valid for this configurator
98
99
  # error(String):: Error message otherwise
99
100
  def validate
100
- init
101
101
  required = self.class.required_settings
102
102
  return nil unless required
103
103
  missing = required.flatten.select { |s| !@settings_values.include?(s) }
@@ -119,12 +119,14 @@ module RightConf
119
119
  # === Return
120
120
  # true:: Always return true
121
121
  def run(*args)
122
- init
123
- sha = Profile.configurator_signature(self.class.key)
122
+ key = "#{self.class.key}-#{@index}"
123
+ sha = Profile.configurator_signature(key)
124
124
  sig = signature
125
125
  if sha != sig
126
- Platform.dispatch(*args) { :run }
127
- Profile.set_configurator_signature(self.class.key, sig)
126
+ if only_if.nil? || instance_eval(only_if)
127
+ Platform.dispatch(*args) { :run }
128
+ Profile.set_configurator_signature(key, sig)
129
+ end
128
130
  end
129
131
  true
130
132
  end
@@ -157,7 +159,6 @@ module RightConf
157
159
  # value:: Value of configuration option if there is one
158
160
  # nil:: Otherwise
159
161
  def [](config_option)
160
- init
161
162
  @settings_values[config_option]
162
163
  end
163
164
 
@@ -173,7 +174,6 @@ module RightConf
173
174
  # res(Object):: Configuration setting value or setter return value if
174
175
  # arguments
175
176
  def method_missing(meth, *args)
176
- init
177
177
  num_args = args.length
178
178
  res = nil
179
179
  if num_args > 0
@@ -189,11 +189,15 @@ module RightConf
189
189
  res || @settings_values[meth]
190
190
  end
191
191
 
192
- # Initialize configuration settings hash
192
+ # Initialize configuration settings hash and index
193
+ #
194
+ # === Parameters
195
+ # index(Fixnum):: Unique index of configurators in rconf file
193
196
  #
194
197
  # === Return
195
198
  # true:: Always return true
196
- def init
199
+ def initialize(index)
200
+ @index = index
197
201
  @settings_values ||= Hash.new
198
202
  true
199
203
  end
@@ -20,11 +20,12 @@ module RightConf
20
20
  description 'Builds a repository using the ./configure, make, make install commands'
21
21
 
22
22
  settings :path => 'Path to source files',
23
+ :tarball_url => 'URL to source code tarball to be downloaded, supports .tgz and .zip',
24
+ :tarball_dir => 'Name of directory created when untaring tarball, required if "tarball_url" is set',
23
25
  :pre_step => 'Command ran prior to ./configure',
24
26
  :message => 'Progress message to display if any while building',
25
27
  :configure_opts => 'Hash of options to be given to the configure script. ' +
26
- 'The keys are the platform families (:darwin, :linux or :windows)',
27
- :only_if => 'Ruby code that should return true for build to proceed'
28
+ 'The keys are the platform families (:darwin, :linux or :windows)'
28
29
 
29
30
  validate_has_settings :path
30
31
 
@@ -33,22 +34,46 @@ module RightConf
33
34
  # === Return
34
35
  # true:: Always return true
35
36
  def run_linux
36
- if only_if.nil? || instance_eval(only_if)
37
- message("Building #{path}") if message.nil?
38
- report_check message
37
+ if tarball_url && tarball_dir.nil?
38
+ report_fatal("tarball_url is specified (#{tarball_url.inspect}) but tarball_dir is missing")
39
+ end
40
+ report_check message if message
41
+ Command.execute('mkdir', '-p', path, :abort_on_failure => "Failed to create #{path}")
42
+ if tarball_url
39
43
  Dir.chdir(path) do
40
- Command.execute(*command_args(pre_step)) if pre_step
41
- opts = configure_opts && configure_opts[Platform.family]
42
- Command.execute(*command_args("./configure #{opts}"))
43
- Command.execute(*command_args('make'))
44
- report_success
45
- report("Please enter you password to run the install step")
46
- Command.sudo('echo')
47
- report_check 'Installing'
48
- Command.sudo(*command_args('make install'))
44
+ filename = File.basename(tarball_url)
45
+ unless File.exists?(File.join(Dir.pwd, filename))
46
+ Command.execute('curl', '-O', '-f', tarball_url, :abort_on_failure => "Failed to curl #{tarball_url}")
47
+ end
48
+ abf = { :abort_on_failure => "Failed to uncompress #{filename}" }
49
+ case filename
50
+ when /\.tar\.gz$|\.tgz$/ then
51
+ Command.execute('tar', '-xzvf', filename, abf)
52
+ when /\.zip$/ then
53
+ Command.execute('unzip', filename, abf)
54
+ when /\.gzip$/ then
55
+ Command.execute('gunzip', filename, abf)
56
+ else
57
+ report_fatal("Unknown file extension #{File.extname(filename)}")
58
+ end
59
+ path File.join(path, tarball_dir)
60
+ if !File.directory?(path)
61
+ report_fatal("Could not find tarball dir #{tarball_dir.inspect} after untaring #{filename}")
62
+ end
49
63
  end
64
+ end
65
+ Dir.chdir(path) do
66
+ Command.execute(*command_args(pre_step)) if pre_step
67
+ opts = configure_opts && configure_opts[Platform.family]
68
+ Command.execute(*command_args("./configure #{opts}"))
69
+ Command.execute(*command_args('make'))
50
70
  report_success
71
+ report("Please enter you password to run the install step")
72
+ Command.sudo('echo')
73
+ report_check 'Installing'
74
+ Command.sudo(*command_args('make install'))
51
75
  end
76
+ report_success if message
52
77
  true
53
78
  end
54
79
  alias :run_darwin :run_linux
@@ -77,7 +77,7 @@ module RightConf
77
77
  if blk
78
78
  klass = ConfiguratorRegistry[meth]
79
79
  if klass
80
- configurator = klass.new(*args)
80
+ configurator = klass.new(@configurators.size)
81
81
  configurator.instance_eval(&blk)
82
82
  error = configurator.validate
83
83
  @validation_errors << error if error
@@ -28,7 +28,11 @@ module RightConf
28
28
  # true:: If bash resource or profile file was updated
29
29
  # false:: Otherwise
30
30
  def self.update(code, dependencies=[])
31
- candidates = ['.bashrc', '.bash_profile']
31
+ if Platform.darwin?
32
+ candidates = [ '.bash_profile' ]
33
+ else
34
+ candidates = ['.bash_profile', '.bashrc']
35
+ end
32
36
  candidates.map! { |c| File.join(ENV['HOME'], c) }
33
37
  bashrc_path = candidates.detect { |c| File.exist?(c) }
34
38
  updated = false
@@ -13,7 +13,7 @@ module RightConf
13
13
 
14
14
  MAJOR = 0
15
15
  MINOR = 7
16
- BUILD = 10
16
+ BUILD = 11
17
17
 
18
18
  VERSION = [MAJOR, MINOR, BUILD].map(&:to_s).join('.')
19
19
 
@@ -32,7 +32,7 @@ describe RightConf::Configurator do
32
32
  end
33
33
 
34
34
  before(:each) do
35
- @configurator = TestConfigurator.new
35
+ @configurator = TestConfigurator.new(1)
36
36
  end
37
37
 
38
38
  it 'should register configurators' do
@@ -67,7 +67,7 @@ describe RightConf::Configurator do
67
67
  end
68
68
 
69
69
  it 'should skip configurators that have already run' do
70
- flexmock(RightConf::Profile.instance).should_receive(:configurator_signature).with(:test).and_return('42')
70
+ flexmock(RightConf::Profile.instance).should_receive(:configurator_signature).with('test-1').and_return('42')
71
71
  flexmock(@configurator).should_receive(:signature).and_return('42')
72
72
  flexmock(RightConf::Platform.instance).should_receive(:dispatch).never
73
73
  @configurator.run
@@ -18,12 +18,13 @@ describe RightConf::BuildConfigurator do
18
18
  end
19
19
 
20
20
  it 'should build' do
21
+ should_execute('mkdir', '-p', '../source', {:abort_on_failure=>"Failed to create ../source"}).once.ordered
21
22
  flexmock(Dir).should_receive(:chdir).with('../source', Proc).once.and_yield
22
23
  should_execute('./configure', {:abort_on_failure=>"Failed to run ./configure"}).once.ordered
23
24
  should_execute('make', {:abort_on_failure=>"Failed to run make"}).once.ordered
24
25
  should_sudo('echo').once.ordered
25
26
  should_sudo('make', 'install', {:abort_on_failure=>"Failed to run make install"}).once.ordered
26
- @configurator.run
27
+ @configurator.run_linux
27
28
  end
28
29
 
29
30
  it 'should honor only_if' do
@@ -62,7 +62,7 @@ end
62
62
  describe 'bashrc update' do
63
63
 
64
64
  before(:each) do
65
- flexmock(File).should_receive(:exist?).with(File.join(ENV['HOME'], '.bashrc')).once.and_return(true)
65
+ flexmock(File).should_receive(:exist?).with(File.join(ENV['HOME'], '.bash_profile')).once.and_return(true)
66
66
  flexmock(File).should_receive(:exist?).with('.rvmrc').and_return(true)
67
67
  flexmock(FileUtils).should_receive(:mv).and_return(true)
68
68
  f = flexmock('f')
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: rconf
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.7.10
5
+ version: 0.7.11
6
6
  platform: ruby
7
7
  authors:
8
8
  - Raphael Simon
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-31 00:00:00 -07:00
13
+ date: 2011-04-05 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency