bleetz 1.5 → 2.0
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/lib/bleetz.rb +18 -1
- data/lib/bleetz/conf.rb +63 -4
- metadata +58 -47
data/lib/bleetz.rb
CHANGED
@@ -6,7 +6,7 @@ require 'bleetz/object.rb'
|
|
6
6
|
|
7
7
|
class Bleetz
|
8
8
|
|
9
|
-
VERSION = "
|
9
|
+
VERSION = "2.0"
|
10
10
|
|
11
11
|
USAGE = <<-EOF
|
12
12
|
Usage: bleetz [-c conf_file -h -l -s][[-t -v -c conf_file] action]
|
@@ -107,7 +107,13 @@ EOF
|
|
107
107
|
|
108
108
|
def test
|
109
109
|
puts "Simulation, command printing without SSH. No excution."
|
110
|
+
unless @@before[@action.to_sym].nil?
|
111
|
+
@@before[@action.to_sym].each { |b| puts "before ssh (local): #{b}" }
|
112
|
+
end
|
110
113
|
@cmd_to_exec.each { |c| puts c }
|
114
|
+
unless @@after[@action.to_sym].nil?
|
115
|
+
@@after[@action.to_sym].each { |a| puts "after ssh (local): #{a}" }
|
116
|
+
end
|
111
117
|
exit(0)
|
112
118
|
end
|
113
119
|
|
@@ -120,6 +126,9 @@ EOF
|
|
120
126
|
|
121
127
|
def connect
|
122
128
|
abort "You have to configure SSH options." if @@options.empty?
|
129
|
+
unless @ssh_test
|
130
|
+
@@before[@action.to_sym].each { |b| execute!(b) } unless @@before[@action.to_sym].nil?
|
131
|
+
end
|
123
132
|
begin
|
124
133
|
Timeout::timeout(@@options.delete(:timeout) || 10) {
|
125
134
|
Net::SSH.start(@@options.delete(:host), @@options.delete(:username), @@options) { |ssh|
|
@@ -143,6 +152,14 @@ EOF
|
|
143
152
|
rescue Timeout::Error
|
144
153
|
abort "Timed out trying to get a connection."
|
145
154
|
end
|
155
|
+
unless @ssh_test
|
156
|
+
@@after[@action.to_sym].each { |a| execute!(a) } unless @@after[@action.to_sym].nil?
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
def execute!(cmd)
|
161
|
+
out = `#{cmd} 2>&1`
|
162
|
+
puts out if @verbose
|
146
163
|
end
|
147
164
|
|
148
165
|
def usage
|
data/lib/bleetz/conf.rb
CHANGED
@@ -8,7 +8,9 @@ end
|
|
8
8
|
|
9
9
|
module Conf
|
10
10
|
|
11
|
+
@@before = {}
|
11
12
|
@@actions = {}
|
13
|
+
@@after = {}
|
12
14
|
@@tasks = {}
|
13
15
|
@@options = {}
|
14
16
|
|
@@ -34,10 +36,56 @@ module Conf
|
|
34
36
|
@@tasks = @@tasks.merge(t)
|
35
37
|
end
|
36
38
|
|
39
|
+
def before(action)
|
40
|
+
check_main_call(:before)
|
41
|
+
@before = []
|
42
|
+
begin
|
43
|
+
yield
|
44
|
+
rescue Exception => e
|
45
|
+
if e.class.eql? RuntimeError
|
46
|
+
raise BleetzException.new(e.message)
|
47
|
+
else
|
48
|
+
raise BleetzException.new("#{e.class}: #{e.message} in #{e.backtrace[0]}")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
h = { action.to_sym => @before }
|
52
|
+
if @@before[action.to_sym].nil?
|
53
|
+
@@before = @@before.merge(h)
|
54
|
+
else
|
55
|
+
raise "You specified two 'before' callbacks for :#{action} action."
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def after(action)
|
60
|
+
@after = []
|
61
|
+
check_main_call(:after)
|
62
|
+
begin
|
63
|
+
yield
|
64
|
+
rescue Exception => e
|
65
|
+
if e.class.eql? RuntimeError
|
66
|
+
raise BleetzException.new(e.message)
|
67
|
+
else
|
68
|
+
raise BleetzException.new("#{e.class}: #{e.message} in #{e.backtrace[0]}")
|
69
|
+
end
|
70
|
+
end
|
71
|
+
h = { action.to_sym => @after }
|
72
|
+
if @@before[action.to_sym].nil?
|
73
|
+
@@after = @@after.merge(h)
|
74
|
+
else
|
75
|
+
raise "You specified two 'after' callbacks for :#{action} action."
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
37
79
|
def shell(cmd)
|
38
|
-
|
80
|
+
check_sub_call_for_shell
|
39
81
|
raise "'shell' needs a String as parameter." unless cmd.is_a? String
|
40
|
-
|
82
|
+
if caller[1][/`([^']*)'/, 1].eql?("action")
|
83
|
+
@cmds << cmd
|
84
|
+
elsif caller[1][/`([^']*)'/, 1].eql?("before")
|
85
|
+
@before << cmd
|
86
|
+
else
|
87
|
+
@after << cmd
|
88
|
+
end
|
41
89
|
end
|
42
90
|
|
43
91
|
def call(action)
|
@@ -55,12 +103,23 @@ module Conf
|
|
55
103
|
|
56
104
|
def check_main_call(func)
|
57
105
|
method = caller[2][/`([^']*)'/, 1]
|
58
|
-
|
106
|
+
unless method.eql?("load")
|
107
|
+
raise "#{caller[1].split(" ")[0]} '#{func}'. Main functions cannot be called in functions."
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def check_sub_call_for_shell
|
112
|
+
method = caller[2][/`([^']*)'/, 1]
|
113
|
+
if !method.eql?("action") && !method.eql?("before") && !method.eql?("after")
|
114
|
+
raise "#{caller[1].split(" ")[0]} 'shell'. 'shell' has to be called in 'action', 'before' or 'after' functions."
|
115
|
+
end
|
59
116
|
end
|
60
117
|
|
61
118
|
def check_sub_call(func)
|
62
119
|
method = caller[2][/`([^']*)'/, 1]
|
63
|
-
|
120
|
+
unless method.eql?("action")
|
121
|
+
raise "#{caller[1].split(" ")[0]} '#{func}'. '#{func}' has to be called in 'action' function."
|
122
|
+
end
|
64
123
|
end
|
65
124
|
|
66
125
|
end
|
metadata
CHANGED
@@ -1,84 +1,95 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: bleetz
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 3
|
5
5
|
prerelease:
|
6
|
+
segments:
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
version: "2.0"
|
6
10
|
platform: ruby
|
7
|
-
authors:
|
11
|
+
authors:
|
8
12
|
- Thibaut Deloffre
|
9
13
|
autorequire:
|
10
14
|
bindir: bin
|
11
15
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
16
|
+
|
17
|
+
date: 2013-01-02 00:00:00 Z
|
18
|
+
dependencies:
|
19
|
+
- !ruby/object:Gem::Dependency
|
15
20
|
name: highline
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
|
-
requirements:
|
19
|
-
- - ! '>='
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: '0'
|
22
|
-
type: :runtime
|
23
21
|
prerelease: false
|
24
|
-
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ! '>='
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '0'
|
30
|
-
- !ruby/object:Gem::Dependency
|
31
|
-
name: net-ssh
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
33
23
|
none: false
|
34
|
-
requirements:
|
35
|
-
- -
|
36
|
-
- !ruby/object:Gem::Version
|
37
|
-
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
hash: 3
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
38
31
|
type: :runtime
|
32
|
+
version_requirements: *id001
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: net-ssh
|
39
35
|
prerelease: false
|
40
|
-
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
37
|
none: false
|
42
|
-
requirements:
|
43
|
-
- -
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
hash: 3
|
42
|
+
segments:
|
43
|
+
- 0
|
44
|
+
version: "0"
|
45
|
+
type: :runtime
|
46
|
+
version_requirements: *id002
|
46
47
|
description: Fast KISS deployment tool
|
47
48
|
email: tib@rocknroot.org
|
48
|
-
executables:
|
49
|
+
executables:
|
49
50
|
- bleetz
|
50
51
|
extensions: []
|
51
|
-
|
52
|
+
|
53
|
+
extra_rdoc_files:
|
52
54
|
- LICENSE.txt
|
53
|
-
files:
|
55
|
+
files:
|
54
56
|
- lib/bleetz.rb
|
55
57
|
- lib/bleetz/conf.rb
|
56
58
|
- lib/bleetz/object.rb
|
57
59
|
- LICENSE.txt
|
58
60
|
- bin/bleetz
|
59
61
|
homepage: https://github.com/TibshoOT/bleetz
|
60
|
-
licenses:
|
62
|
+
licenses:
|
61
63
|
- BSD
|
62
64
|
post_install_message:
|
63
65
|
rdoc_options: []
|
64
|
-
|
66
|
+
|
67
|
+
require_paths:
|
65
68
|
- lib
|
66
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
70
|
none: false
|
68
|
-
requirements:
|
69
|
-
- -
|
70
|
-
- !ruby/object:Gem::Version
|
71
|
-
|
72
|
-
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
hash: 3
|
75
|
+
segments:
|
76
|
+
- 0
|
77
|
+
version: "0"
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
79
|
none: false
|
74
|
-
requirements:
|
75
|
-
- -
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
hash: 3
|
84
|
+
segments:
|
85
|
+
- 0
|
86
|
+
version: "0"
|
78
87
|
requirements: []
|
88
|
+
|
79
89
|
rubyforge_project:
|
80
90
|
rubygems_version: 1.8.24
|
81
91
|
signing_key:
|
82
92
|
specification_version: 3
|
83
93
|
summary: Fast KISS deployment tool
|
84
94
|
test_files: []
|
95
|
+
|