cerberus 0.3.5 → 0.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES +159 -129
- data/LICENSE +21 -21
- data/README +75 -75
- data/Rakefile +161 -159
- data/bin/cerberus +2 -2
- data/lib/cerberus/builder/maven2.rb +38 -38
- data/lib/cerberus/builder/rake.rb +7 -7
- data/lib/cerberus/builder/rant.rb +7 -7
- data/lib/cerberus/builder/rspec.rb +13 -0
- data/lib/cerberus/builder/ruby_base.rb +48 -47
- data/lib/cerberus/cli.rb +73 -70
- data/lib/cerberus/component_lazy_loader.rb +2 -0
- data/lib/cerberus/config.example.yml +28 -28
- data/lib/cerberus/config.rb +47 -46
- data/lib/cerberus/constants.rb +8 -8
- data/lib/cerberus/latch.rb +26 -26
- data/lib/cerberus/manager.rb +296 -267
- data/lib/cerberus/publisher/base.rb +47 -47
- data/lib/cerberus/publisher/gmailer.rb +17 -0
- data/lib/cerberus/publisher/irc.rb +27 -27
- data/lib/cerberus/publisher/jabber.rb +25 -25
- data/lib/cerberus/publisher/mail.rb +36 -36
- data/lib/cerberus/publisher/netsmtp_tls_fix.rb +66 -66
- data/lib/cerberus/publisher/rss.rb +27 -28
- data/lib/cerberus/scm/cvs.rb +48 -48
- data/lib/cerberus/scm/darcs.rb +70 -70
- data/lib/cerberus/scm/svn.rb +83 -83
- data/lib/cerberus/utils.rb +156 -156
- data/test/config_test.rb +45 -45
- data/test/functional_test.rb +288 -287
- data/test/integration_test.rb +104 -104
- data/test/irc_publisher_test.rb +18 -18
- data/test/jabber_publisher_test.rb +21 -21
- data/test/mail_publisher_test.rb +25 -25
- data/test/maven2_builer_test.rb +81 -81
- data/test/mock/irc.rb +20 -20
- data/test/mock/manager.rb +10 -10
- data/test/mock/xmpp4r.rb +19 -19
- data/test/rss_publisher_test.rb +21 -21
- data/test/test_helper.rb +105 -105
- metadata +58 -40
- data/lib/cerberus/helper/xchar.rb +0 -61
data/lib/cerberus/scm/cvs.rb
CHANGED
@@ -1,48 +1,48 @@
|
|
1
|
-
require 'cerberus/utils'
|
2
|
-
|
3
|
-
class Cerberus::SCM::CVS
|
4
|
-
def initialize(path, config = {})
|
5
|
-
raise "Path can't be nil" unless path
|
6
|
-
|
7
|
-
@path, @config = path.strip, config
|
8
|
-
@encoded_path = (@path.include?(' ') ? "\"#{@path}\"" : @path)
|
9
|
-
end
|
10
|
-
|
11
|
-
def installed?
|
12
|
-
exec_successful? "#{@config[:bin_path]}cvs --version"
|
13
|
-
end
|
14
|
-
|
15
|
-
def update!
|
16
|
-
if test(?d, @path + '/CVS')
|
17
|
-
@status = execute("update")
|
18
|
-
else
|
19
|
-
FileUtils.mkpath(@path) unless test(?d,@path)
|
20
|
-
@status = execute("checkout", nil, @config[:scm, :url])
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def has_changes?
|
25
|
-
@status =~ /^[U|P|C] (.*)/
|
26
|
-
end
|
27
|
-
|
28
|
-
def current_revision
|
29
|
-
raise NotImplementedError
|
30
|
-
end
|
31
|
-
|
32
|
-
def url
|
33
|
-
raise NotImplementedError
|
34
|
-
end
|
35
|
-
|
36
|
-
def last_commit_message
|
37
|
-
raise NotImplementedError
|
38
|
-
end
|
39
|
-
|
40
|
-
def last_author
|
41
|
-
raise NotImplementedError
|
42
|
-
end
|
43
|
-
|
44
|
-
private
|
45
|
-
def execute(command, parameters = nil, pre_parameters = nil)
|
46
|
-
`#{@config[:bin_path]}cvs #{command} #{pre_parameters} #{@encoded_path} #{parameters}`
|
47
|
-
end
|
48
|
-
end
|
1
|
+
require 'cerberus/utils'
|
2
|
+
|
3
|
+
class Cerberus::SCM::CVS
|
4
|
+
def initialize(path, config = {})
|
5
|
+
raise "Path can't be nil" unless path
|
6
|
+
|
7
|
+
@path, @config = path.strip, config
|
8
|
+
@encoded_path = (@path.include?(' ') ? "\"#{@path}\"" : @path)
|
9
|
+
end
|
10
|
+
|
11
|
+
def installed?
|
12
|
+
exec_successful? "#{@config[:bin_path]}cvs --version"
|
13
|
+
end
|
14
|
+
|
15
|
+
def update!
|
16
|
+
if test(?d, @path + '/CVS')
|
17
|
+
@status = execute("update")
|
18
|
+
else
|
19
|
+
FileUtils.mkpath(@path) unless test(?d,@path)
|
20
|
+
@status = execute("checkout", nil, @config[:scm, :url])
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def has_changes?
|
25
|
+
@status =~ /^[U|P|C] (.*)/
|
26
|
+
end
|
27
|
+
|
28
|
+
def current_revision
|
29
|
+
raise NotImplementedError
|
30
|
+
end
|
31
|
+
|
32
|
+
def url
|
33
|
+
raise NotImplementedError
|
34
|
+
end
|
35
|
+
|
36
|
+
def last_commit_message
|
37
|
+
raise NotImplementedError
|
38
|
+
end
|
39
|
+
|
40
|
+
def last_author
|
41
|
+
raise NotImplementedError
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
def execute(command, parameters = nil, pre_parameters = nil)
|
46
|
+
`#{@config[:bin_path]}cvs #{command} #{pre_parameters} #{@encoded_path} #{parameters}`
|
47
|
+
end
|
48
|
+
end
|
data/lib/cerberus/scm/darcs.rb
CHANGED
@@ -1,70 +1,70 @@
|
|
1
|
-
require 'cerberus/utils'
|
2
|
-
|
3
|
-
class Cerberus::SCM::Darcs
|
4
|
-
def initialize(path, config = {})
|
5
|
-
raise "Path can't be nil" unless path
|
6
|
-
|
7
|
-
@path, @config = path.strip, config
|
8
|
-
@encoded_path = (@path.include?(' ') ? "\"#{@path}\"" : @path)
|
9
|
-
end
|
10
|
-
|
11
|
-
def installed?
|
12
|
-
exec_successful? "#{@config[:bin_path]}darcs --version"
|
13
|
-
end
|
14
|
-
|
15
|
-
def update!
|
16
|
-
if test(?d, @path + '/_darcs')
|
17
|
-
@status = execute('pull', '-v -a')
|
18
|
-
else
|
19
|
-
FileUtils.rm_rf(@path) if test(?d,@path)
|
20
|
-
FileUtils.mkpath(File.basename(@path)) unless test(?d,File.basename(@path))
|
21
|
-
|
22
|
-
encoded_url = (@config[:scm, :url].include?(' ') ? "\"#{@config[:scm, :url]}\"" : @config[:scm, :url])
|
23
|
-
@status = execute("get", "--partial #{encoded_url}")
|
24
|
-
end
|
25
|
-
|
26
|
-
extract_last_commit_info
|
27
|
-
end
|
28
|
-
|
29
|
-
def has_changes?
|
30
|
-
return false if @status =~ /No remote changes to pull in!/
|
31
|
-
return true if @status =~ /We have the following new \(to them\) patches:/
|
32
|
-
return true if @status =~ /Copying patch \d+ of \d+\.\.\. done!/
|
33
|
-
return false
|
34
|
-
end
|
35
|
-
|
36
|
-
def current_revision
|
37
|
-
@date
|
38
|
-
end
|
39
|
-
|
40
|
-
def url
|
41
|
-
@path
|
42
|
-
end
|
43
|
-
|
44
|
-
def last_commit_message
|
45
|
-
@message
|
46
|
-
end
|
47
|
-
|
48
|
-
def last_author
|
49
|
-
@author
|
50
|
-
end
|
51
|
-
|
52
|
-
def output
|
53
|
-
@status
|
54
|
-
end
|
55
|
-
|
56
|
-
private
|
57
|
-
def execute(command, parameters = nil, with_path = true)
|
58
|
-
cmd = "#{@config[:bin_path]}darcs #{command} #{parameters} --repodir=#{@encoded_path}"
|
59
|
-
`#{cmd}`
|
60
|
-
end
|
61
|
-
|
62
|
-
def extract_last_commit_info
|
63
|
-
xml_message = execute('changes', "--last 1 --xml-output")
|
64
|
-
require 'rexml/document'
|
65
|
-
xml = REXML::Document.new(xml_message)
|
66
|
-
@author = xml.elements["changelog/patch/@author"].value
|
67
|
-
@date = xml.elements["changelog/patch/@date"].value
|
68
|
-
@message = xml.elements["changelog/patch/name"].get_text.value
|
69
|
-
end
|
70
|
-
end
|
1
|
+
require 'cerberus/utils'
|
2
|
+
|
3
|
+
class Cerberus::SCM::Darcs
|
4
|
+
def initialize(path, config = {})
|
5
|
+
raise "Path can't be nil" unless path
|
6
|
+
|
7
|
+
@path, @config = path.strip, config
|
8
|
+
@encoded_path = (@path.include?(' ') ? "\"#{@path}\"" : @path)
|
9
|
+
end
|
10
|
+
|
11
|
+
def installed?
|
12
|
+
exec_successful? "#{@config[:bin_path]}darcs --version"
|
13
|
+
end
|
14
|
+
|
15
|
+
def update!
|
16
|
+
if test(?d, @path + '/_darcs')
|
17
|
+
@status = execute('pull', '-v -a')
|
18
|
+
else
|
19
|
+
FileUtils.rm_rf(@path) if test(?d,@path)
|
20
|
+
FileUtils.mkpath(File.basename(@path)) unless test(?d,File.basename(@path))
|
21
|
+
|
22
|
+
encoded_url = (@config[:scm, :url].include?(' ') ? "\"#{@config[:scm, :url]}\"" : @config[:scm, :url])
|
23
|
+
@status = execute("get", "--partial #{encoded_url}")
|
24
|
+
end
|
25
|
+
|
26
|
+
extract_last_commit_info
|
27
|
+
end
|
28
|
+
|
29
|
+
def has_changes?
|
30
|
+
return false if @status =~ /No remote changes to pull in!/
|
31
|
+
return true if @status =~ /We have the following new \(to them\) patches:/
|
32
|
+
return true if @status =~ /Copying patch \d+ of \d+\.\.\. done!/
|
33
|
+
return false
|
34
|
+
end
|
35
|
+
|
36
|
+
def current_revision
|
37
|
+
@date
|
38
|
+
end
|
39
|
+
|
40
|
+
def url
|
41
|
+
@path
|
42
|
+
end
|
43
|
+
|
44
|
+
def last_commit_message
|
45
|
+
@message
|
46
|
+
end
|
47
|
+
|
48
|
+
def last_author
|
49
|
+
@author
|
50
|
+
end
|
51
|
+
|
52
|
+
def output
|
53
|
+
@status
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
def execute(command, parameters = nil, with_path = true)
|
58
|
+
cmd = "#{@config[:bin_path]}darcs #{command} #{parameters} --repodir=#{@encoded_path}"
|
59
|
+
`#{cmd}`
|
60
|
+
end
|
61
|
+
|
62
|
+
def extract_last_commit_info
|
63
|
+
xml_message = execute('changes', "--last 1 --xml-output")
|
64
|
+
require 'rexml/document'
|
65
|
+
xml = REXML::Document.new(xml_message)
|
66
|
+
@author = xml.elements["changelog/patch/@author"].value
|
67
|
+
@date = xml.elements["changelog/patch/@date"].value
|
68
|
+
@message = xml.elements["changelog/patch/name"].get_text.value
|
69
|
+
end
|
70
|
+
end
|
data/lib/cerberus/scm/svn.rb
CHANGED
@@ -1,83 +1,83 @@
|
|
1
|
-
require 'cerberus/utils'
|
2
|
-
|
3
|
-
class Cerberus::SCM::SVN
|
4
|
-
def initialize(path, config = {})
|
5
|
-
raise "Path can't be nil" unless path
|
6
|
-
|
7
|
-
@path, @config = path.strip, config
|
8
|
-
@encoded_path = (@path.include?(' ') ? "\"#{@path}\"" : @path)
|
9
|
-
end
|
10
|
-
|
11
|
-
def installed?
|
12
|
-
exec_successful? "#{@config[:bin_path]}svn --version"
|
13
|
-
end
|
14
|
-
|
15
|
-
def update!
|
16
|
-
if test(?d, @path + '/.svn') #check first that it was not locked
|
17
|
-
execute("cleanup") if locked?
|
18
|
-
say "Could not unlock svn directory #{@encoded_path}. Please do it manually." if locked? #In case if we could not unlock from command line - ask user to do it
|
19
|
-
end
|
20
|
-
|
21
|
-
if test(?d, @path + '/.svn')
|
22
|
-
@status = execute("update")
|
23
|
-
else
|
24
|
-
FileUtils.mkpath(@path) unless test(?d,@path)
|
25
|
-
@status = execute("checkout", nil, @config[:scm, :url])
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def has_changes?
|
30
|
-
@status =~ /[A-Z]\s+[\w\/]+/ ? true : false
|
31
|
-
end
|
32
|
-
|
33
|
-
def current_revision
|
34
|
-
info['Revision'].to_i
|
35
|
-
end
|
36
|
-
|
37
|
-
def url
|
38
|
-
info['URL']
|
39
|
-
end
|
40
|
-
|
41
|
-
def last_commit_message
|
42
|
-
message = execute("log", "--limit 1 -v")
|
43
|
-
#strip first line that contains command line itself (svn log --limit ...)
|
44
|
-
if (idx = message.index('-'*72))
|
45
|
-
message[idx..-1]
|
46
|
-
else
|
47
|
-
message
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def last_author
|
52
|
-
info['Last Changed Author']
|
53
|
-
end
|
54
|
-
|
55
|
-
private
|
56
|
-
def locked?
|
57
|
-
execute("st") =~ /^..L/
|
58
|
-
end
|
59
|
-
|
60
|
-
def info
|
61
|
-
unless @info
|
62
|
-
output = execute("info")
|
63
|
-
@info = YAML.load(output)
|
64
|
-
|
65
|
-
if not @info.is_a?(Hash) or @info['Repository UUID'].nil? #.size > 8
|
66
|
-
say "Could not parse svn output. Seems source directory #{@encoded_path} is corrupted.\n#{output}"
|
67
|
-
end
|
68
|
-
end
|
69
|
-
@info
|
70
|
-
end
|
71
|
-
|
72
|
-
def execute(command, parameters = nil, pre_parameters = nil)
|
73
|
-
`#{@config[:bin_path]}svn #{command} #{auth_options()} #{pre_parameters} #{@encoded_path} #{parameters}`
|
74
|
-
end
|
75
|
-
|
76
|
-
def auth_options
|
77
|
-
auth = []
|
78
|
-
auth << "--username #{@config[:scm, :user_name]}" if @config[:scm, :user_name]
|
79
|
-
auth << "--password #{@config[:scm, :password]}" if @config[:scm, :password]
|
80
|
-
|
81
|
-
auth.join(' ')
|
82
|
-
end
|
83
|
-
end
|
1
|
+
require 'cerberus/utils'
|
2
|
+
|
3
|
+
class Cerberus::SCM::SVN
|
4
|
+
def initialize(path, config = {})
|
5
|
+
raise "Path can't be nil" unless path
|
6
|
+
|
7
|
+
@path, @config = path.strip, config
|
8
|
+
@encoded_path = (@path.include?(' ') ? "\"#{@path}\"" : @path)
|
9
|
+
end
|
10
|
+
|
11
|
+
def installed?
|
12
|
+
exec_successful? "#{@config[:bin_path]}svn --version"
|
13
|
+
end
|
14
|
+
|
15
|
+
def update!
|
16
|
+
if test(?d, @path + '/.svn') #check first that it was not locked
|
17
|
+
execute("cleanup") if locked?
|
18
|
+
say "Could not unlock svn directory #{@encoded_path}. Please do it manually." if locked? #In case if we could not unlock from command line - ask user to do it
|
19
|
+
end
|
20
|
+
|
21
|
+
if test(?d, @path + '/.svn')
|
22
|
+
@status = execute("update")
|
23
|
+
else
|
24
|
+
FileUtils.mkpath(@path) unless test(?d,@path)
|
25
|
+
@status = execute("checkout", nil, @config[:scm, :url])
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def has_changes?
|
30
|
+
@status =~ /[A-Z]\s+[\w\/]+/ ? true : false
|
31
|
+
end
|
32
|
+
|
33
|
+
def current_revision
|
34
|
+
info['Revision'].to_i
|
35
|
+
end
|
36
|
+
|
37
|
+
def url
|
38
|
+
info['URL']
|
39
|
+
end
|
40
|
+
|
41
|
+
def last_commit_message
|
42
|
+
message = execute("log", "--limit 1 -v")
|
43
|
+
#strip first line that contains command line itself (svn log --limit ...)
|
44
|
+
if (idx = message.index('-'*72))
|
45
|
+
message[idx..-1]
|
46
|
+
else
|
47
|
+
message
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def last_author
|
52
|
+
info['Last Changed Author']
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
def locked?
|
57
|
+
execute("st") =~ /^..L/
|
58
|
+
end
|
59
|
+
|
60
|
+
def info
|
61
|
+
unless @info
|
62
|
+
output = execute("info")
|
63
|
+
@info = YAML.load(output)
|
64
|
+
|
65
|
+
if not @info.is_a?(Hash) or @info['Repository UUID'].nil? #.size > 8
|
66
|
+
say "Could not parse svn output. Seems source directory #{@encoded_path} is corrupted.\n#{output}"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
@info
|
70
|
+
end
|
71
|
+
|
72
|
+
def execute(command, parameters = nil, pre_parameters = nil)
|
73
|
+
`#{@config[:bin_path]}svn #{command} #{auth_options()} #{pre_parameters} #{@encoded_path} #{parameters}`
|
74
|
+
end
|
75
|
+
|
76
|
+
def auth_options
|
77
|
+
auth = []
|
78
|
+
auth << "--username #{@config[:scm, :user_name]}" if @config[:scm, :user_name]
|
79
|
+
auth << "--password #{@config[:scm, :password]}" if @config[:scm, :password]
|
80
|
+
|
81
|
+
auth.join(' ')
|
82
|
+
end
|
83
|
+
end
|
data/lib/cerberus/utils.rb
CHANGED
@@ -1,156 +1,156 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
|
3
|
-
module Cerberus
|
4
|
-
module Utils
|
5
|
-
def say(msg)
|
6
|
-
STDERR << msg
|
7
|
-
exit 1
|
8
|
-
end
|
9
|
-
|
10
|
-
def os
|
11
|
-
case RUBY_PLATFORM
|
12
|
-
when /mswin/
|
13
|
-
:windows
|
14
|
-
else
|
15
|
-
:unix
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def dump_yml(file, what, overwrite = true)
|
20
|
-
if overwrite or not File.exists?(file)
|
21
|
-
FileUtils.mkpath(File.dirname(file))
|
22
|
-
File.open(file, 'w') {|f| YAML::dump(what, f) }
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def load_yml(file_name, default = {})
|
27
|
-
File.exists?(file_name) ? YAML::load(IO.read(file_name)) : default
|
28
|
-
end
|
29
|
-
|
30
|
-
def silence_stream(stream)
|
31
|
-
old_stream = stream.dup
|
32
|
-
stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')
|
33
|
-
stream.sync = true
|
34
|
-
yield
|
35
|
-
ensure
|
36
|
-
stream.reopen(old_stream)
|
37
|
-
end
|
38
|
-
|
39
|
-
def exec_successful?(cmd)
|
40
|
-
begin
|
41
|
-
`#{cmd}`
|
42
|
-
return true
|
43
|
-
rescue
|
44
|
-
return false
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def interpret_state(state, with_default = true)
|
49
|
-
case
|
50
|
-
when state == 'all'
|
51
|
-
[:setup, :successful, :revival, :broken, :failed]
|
52
|
-
when state == 'none'
|
53
|
-
[]
|
54
|
-
when state == 'default' && with_default
|
55
|
-
[:setup, :revival, :broken, :failed] #the same as 'all' except successful
|
56
|
-
else
|
57
|
-
state.scan(/\w+/).map{|s| s.to_sym}
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
include Cerberus::Utils
|
64
|
-
|
65
|
-
alias __exec `
|
66
|
-
def `(cmd)
|
67
|
-
begin
|
68
|
-
__exec(cmd)
|
69
|
-
rescue Exception => e
|
70
|
-
raise "Unable to execute: #{cmd}"
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
class Hash
|
75
|
-
def deep_merge!(second)
|
76
|
-
second.each_pair do |k,v|
|
77
|
-
if self[k].is_a?(Hash) and second[k].is_a?(Hash)
|
78
|
-
self[k].deep_merge!(second[k])
|
79
|
-
else
|
80
|
-
self[k] = second[k]
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
class HashWithIndifferentAccess < Hash
|
87
|
-
def initialize(constructor = {})
|
88
|
-
if constructor.is_a?(Hash)
|
89
|
-
super()
|
90
|
-
update(constructor)
|
91
|
-
else
|
92
|
-
super(constructor)
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
def default(key)
|
97
|
-
self[key.to_s] if key.is_a?(Symbol)
|
98
|
-
end
|
99
|
-
|
100
|
-
alias_method :regular_writer, :[]= unless method_defined?(:regular_writer)
|
101
|
-
alias_method :regular_update, :update unless method_defined?(:regular_update)
|
102
|
-
|
103
|
-
def []=(key, value)
|
104
|
-
regular_writer(convert_key(key), convert_value(value))
|
105
|
-
end
|
106
|
-
|
107
|
-
def update(other_hash)
|
108
|
-
other_hash.each_pair { |key, value| regular_writer(convert_key(key), convert_value(value)) }
|
109
|
-
self
|
110
|
-
end
|
111
|
-
|
112
|
-
alias_method :merge!, :update
|
113
|
-
|
114
|
-
def key?(key)
|
115
|
-
super(convert_key(key))
|
116
|
-
end
|
117
|
-
|
118
|
-
alias_method :include?, :key?
|
119
|
-
alias_method :has_key?, :key?
|
120
|
-
alias_method :member?, :key?
|
121
|
-
|
122
|
-
def fetch(key, *extras)
|
123
|
-
super(convert_key(key), *extras)
|
124
|
-
end
|
125
|
-
|
126
|
-
def values_at(*indices)
|
127
|
-
indices.collect {|key| self[convert_key(key)]}
|
128
|
-
end
|
129
|
-
|
130
|
-
def dup
|
131
|
-
HashWithIndifferentAccess.new(self)
|
132
|
-
end
|
133
|
-
|
134
|
-
def merge(hash)
|
135
|
-
self.dup.update(hash)
|
136
|
-
end
|
137
|
-
|
138
|
-
def delete(key)
|
139
|
-
super(convert_key(key))
|
140
|
-
end
|
141
|
-
|
142
|
-
protected
|
143
|
-
def convert_key(key)
|
144
|
-
key.kind_of?(Symbol) ? key.to_s : key
|
145
|
-
end
|
146
|
-
def convert_value(value)
|
147
|
-
value.is_a?(Hash) ? HashWithIndifferentAccess.new(value) : value
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
|
152
|
-
class IO
|
153
|
-
def self.write(filename, str)
|
154
|
-
File.open(filename, 'w'){|f| f.write str}
|
155
|
-
end
|
156
|
-
end
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module Cerberus
|
4
|
+
module Utils
|
5
|
+
def say(msg)
|
6
|
+
STDERR << msg << "\n"
|
7
|
+
exit 1
|
8
|
+
end
|
9
|
+
|
10
|
+
def os
|
11
|
+
case RUBY_PLATFORM
|
12
|
+
when /mswin/
|
13
|
+
:windows
|
14
|
+
else
|
15
|
+
:unix
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def dump_yml(file, what, overwrite = true)
|
20
|
+
if overwrite or not File.exists?(file)
|
21
|
+
FileUtils.mkpath(File.dirname(file))
|
22
|
+
File.open(file, 'w') {|f| YAML::dump(what, f) }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def load_yml(file_name, default = {})
|
27
|
+
File.exists?(file_name) ? YAML::load(IO.read(file_name)) : default
|
28
|
+
end
|
29
|
+
|
30
|
+
def silence_stream(stream)
|
31
|
+
old_stream = stream.dup
|
32
|
+
stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')
|
33
|
+
stream.sync = true
|
34
|
+
yield
|
35
|
+
ensure
|
36
|
+
stream.reopen(old_stream)
|
37
|
+
end
|
38
|
+
|
39
|
+
def exec_successful?(cmd)
|
40
|
+
begin
|
41
|
+
`#{cmd}`
|
42
|
+
return true
|
43
|
+
rescue
|
44
|
+
return false
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def interpret_state(state, with_default = true)
|
49
|
+
case
|
50
|
+
when state == 'all'
|
51
|
+
[:setup, :successful, :revival, :broken, :failed]
|
52
|
+
when state == 'none'
|
53
|
+
[]
|
54
|
+
when state == 'default' && with_default
|
55
|
+
[:setup, :revival, :broken, :failed] #the same as 'all' except successful
|
56
|
+
else
|
57
|
+
state.scan(/\w+/).map{|s| s.to_sym}
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
include Cerberus::Utils
|
64
|
+
|
65
|
+
alias __exec `
|
66
|
+
def `(cmd)
|
67
|
+
begin
|
68
|
+
__exec(cmd)
|
69
|
+
rescue Exception => e
|
70
|
+
raise "Unable to execute: #{cmd}"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
class Hash
|
75
|
+
def deep_merge!(second)
|
76
|
+
second.each_pair do |k,v|
|
77
|
+
if self[k].is_a?(Hash) and second[k].is_a?(Hash)
|
78
|
+
self[k].deep_merge!(second[k])
|
79
|
+
else
|
80
|
+
self[k] = second[k]
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
class HashWithIndifferentAccess < Hash
|
87
|
+
def initialize(constructor = {})
|
88
|
+
if constructor.is_a?(Hash)
|
89
|
+
super()
|
90
|
+
update(constructor)
|
91
|
+
else
|
92
|
+
super(constructor)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def default(key)
|
97
|
+
self[key.to_s] if key.is_a?(Symbol)
|
98
|
+
end
|
99
|
+
|
100
|
+
alias_method :regular_writer, :[]= unless method_defined?(:regular_writer)
|
101
|
+
alias_method :regular_update, :update unless method_defined?(:regular_update)
|
102
|
+
|
103
|
+
def []=(key, value)
|
104
|
+
regular_writer(convert_key(key), convert_value(value))
|
105
|
+
end
|
106
|
+
|
107
|
+
def update(other_hash)
|
108
|
+
other_hash.each_pair { |key, value| regular_writer(convert_key(key), convert_value(value)) }
|
109
|
+
self
|
110
|
+
end
|
111
|
+
|
112
|
+
alias_method :merge!, :update
|
113
|
+
|
114
|
+
def key?(key)
|
115
|
+
super(convert_key(key))
|
116
|
+
end
|
117
|
+
|
118
|
+
alias_method :include?, :key?
|
119
|
+
alias_method :has_key?, :key?
|
120
|
+
alias_method :member?, :key?
|
121
|
+
|
122
|
+
def fetch(key, *extras)
|
123
|
+
super(convert_key(key), *extras)
|
124
|
+
end
|
125
|
+
|
126
|
+
def values_at(*indices)
|
127
|
+
indices.collect {|key| self[convert_key(key)]}
|
128
|
+
end
|
129
|
+
|
130
|
+
def dup
|
131
|
+
HashWithIndifferentAccess.new(self)
|
132
|
+
end
|
133
|
+
|
134
|
+
def merge(hash)
|
135
|
+
self.dup.update(hash)
|
136
|
+
end
|
137
|
+
|
138
|
+
def delete(key)
|
139
|
+
super(convert_key(key))
|
140
|
+
end
|
141
|
+
|
142
|
+
protected
|
143
|
+
def convert_key(key)
|
144
|
+
key.kind_of?(Symbol) ? key.to_s : key
|
145
|
+
end
|
146
|
+
def convert_value(value)
|
147
|
+
value.is_a?(Hash) ? HashWithIndifferentAccess.new(value) : value
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
|
152
|
+
class IO
|
153
|
+
def self.write(filename, str)
|
154
|
+
File.open(filename, 'w'){|f| f.write str}
|
155
|
+
end
|
156
|
+
end
|