itamae 1.3.3 → 1.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/itamae.gemspec +1 -1
- data/lib/itamae/backend.rb +71 -42
- data/lib/itamae/version.txt +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c3734924aed2c2ab9472e781e7c512c31599b46
|
4
|
+
data.tar.gz: fe29b7a53a36075a3886be1d89e17355edf528cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c7a9d8d4400cc1b46276c7e5115e4c5bd653fb9d2cb63c3edcd548d36207b021947b8925aaaab9b693bf8e4a26db4c9324275c0b80a4e2ea9ac5e4cb382f97a2
|
7
|
+
data.tar.gz: abd0f092cfa89168efe723b0210a58ba3a4ec82993818be5cda8a7787d5827148744fd6dda2355e2482146b79d7414f084bc7e4d3b568a2d695385abc4721379
|
data/CHANGELOG.md
CHANGED
data/itamae.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
|
20
20
|
spec.add_runtime_dependency "thor"
|
21
|
-
spec.add_runtime_dependency "specinfra", [">= 2.
|
21
|
+
spec.add_runtime_dependency "specinfra", [">= 2.37.0", "< 3.0.0"]
|
22
22
|
spec.add_runtime_dependency "hashie"
|
23
23
|
spec.add_runtime_dependency "ansi"
|
24
24
|
spec.add_runtime_dependency "schash", "~> 0.1.0"
|
data/lib/itamae/backend.rb
CHANGED
@@ -43,61 +43,37 @@ module Itamae
|
|
43
43
|
def run_command(commands, options = {})
|
44
44
|
options = {error: true}.merge(options)
|
45
45
|
|
46
|
-
|
47
|
-
command = commands.map do |cmd|
|
48
|
-
Shellwords.escape(cmd)
|
49
|
-
end.join(' ')
|
50
|
-
else
|
51
|
-
command = commands
|
52
|
-
end
|
53
|
-
|
54
|
-
cwd = options[:cwd]
|
55
|
-
if cwd
|
56
|
-
command = "cd #{Shellwords.escape(cwd)} && #{command}"
|
57
|
-
end
|
58
|
-
|
59
|
-
user = options[:user]
|
60
|
-
if user
|
61
|
-
command = "sudo -H -u #{Shellwords.escape(user)} -- /bin/sh -c #{Shellwords.escape(command)}"
|
62
|
-
end
|
63
|
-
|
46
|
+
command = build_command(commands, options)
|
64
47
|
Logger.debug "Executing `#{command}`..."
|
65
48
|
|
66
|
-
result =
|
67
|
-
exit_status = result.exit_status
|
49
|
+
result = nil
|
68
50
|
|
69
51
|
Logger.formatter.with_indent do
|
70
|
-
|
52
|
+
reset_output_handler
|
53
|
+
result = @backend.run_command(command)
|
54
|
+
flush_output_handler_buffer
|
55
|
+
|
56
|
+
if result.exit_status == 0 || !options[:error]
|
71
57
|
method = :debug
|
72
|
-
message = "exited with #{exit_status}"
|
58
|
+
message = "exited with #{result.exit_status}"
|
73
59
|
else
|
74
60
|
method = :error
|
75
|
-
message = "Command `#{command}` failed. (exit status: #{exit_status})"
|
76
|
-
end
|
77
|
-
|
78
|
-
Logger.public_send(method, message)
|
79
|
-
|
80
|
-
{"stdout" => result.stdout, "stderr" => result.stderr}.each_pair do |name, value|
|
81
|
-
next unless value && value != ''
|
61
|
+
message = "Command `#{command}` failed. (exit status: #{result.exit_status})"
|
82
62
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
# remove control chars
|
90
|
-
case line.encoding
|
91
|
-
when Encoding::UTF_8
|
92
|
-
line = line.tr("\u0000-\u001f\u007f\u2028",'')
|
63
|
+
unless Logger.logger.level == ::Logger::DEBUG
|
64
|
+
result.stdout.each_line do |l|
|
65
|
+
log_output_line("stdout", l, :error)
|
66
|
+
end
|
67
|
+
result.stderr.each_line do |l|
|
68
|
+
log_output_line("stderr", l, :error)
|
93
69
|
end
|
94
|
-
|
95
|
-
Logger.public_send(method, "#{name} | #{line}")
|
96
70
|
end
|
97
71
|
end
|
72
|
+
|
73
|
+
Logger.public_send(method, message)
|
98
74
|
end
|
99
75
|
|
100
|
-
if options[:error] && exit_status != 0
|
76
|
+
if options[:error] && result.exit_status != 0
|
101
77
|
raise CommandExecutionError
|
102
78
|
end
|
103
79
|
|
@@ -152,6 +128,59 @@ module Itamae
|
|
152
128
|
def create_specinfra_backend
|
153
129
|
raise NotImplementedError
|
154
130
|
end
|
131
|
+
|
132
|
+
def reset_output_handler
|
133
|
+
@buf = {}
|
134
|
+
%w!stdout stderr!.each do |output_name|
|
135
|
+
@buf[output_name] = ""
|
136
|
+
handler = lambda do |str|
|
137
|
+
lines = str.split(/\r?\n/, -1)
|
138
|
+
@buf[output_name] += lines.pop
|
139
|
+
unless lines.empty?
|
140
|
+
lines[0] = @buf[output_name] + lines[0]
|
141
|
+
@buf[output_name] = ""
|
142
|
+
lines.each do |l|
|
143
|
+
log_output_line(output_name, l)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
@backend.public_send("#{output_name}_handler=", handler)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
def flush_output_handler_buffer
|
152
|
+
@buf.each do |output_name, line|
|
153
|
+
next if line.empty?
|
154
|
+
log_output_line(output_name, line)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
def log_output_line(output_name, line, severity = :debug)
|
159
|
+
line = line.gsub(/[[:cntrl:]]/, '')
|
160
|
+
Logger.public_send(severity, "#{output_name} | #{line}")
|
161
|
+
end
|
162
|
+
|
163
|
+
def build_command(commands, options)
|
164
|
+
if commands.is_a?(Array)
|
165
|
+
command = commands.map do |cmd|
|
166
|
+
Shellwords.escape(cmd)
|
167
|
+
end.join(' ')
|
168
|
+
else
|
169
|
+
command = commands
|
170
|
+
end
|
171
|
+
|
172
|
+
cwd = options[:cwd]
|
173
|
+
if cwd
|
174
|
+
command = "cd #{Shellwords.escape(cwd)} && #{command}"
|
175
|
+
end
|
176
|
+
|
177
|
+
user = options[:user]
|
178
|
+
if user
|
179
|
+
command = "sudo -H -u #{Shellwords.escape(user)} -- /bin/sh -c #{Shellwords.escape(command)}"
|
180
|
+
end
|
181
|
+
|
182
|
+
command
|
183
|
+
end
|
155
184
|
end
|
156
185
|
|
157
186
|
# TODO: Make Specinfra's backends instanciatable
|
data/lib/itamae/version.txt
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.3.
|
1
|
+
1.3.4
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: itamae
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryota Arai
|
@@ -30,7 +30,7 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 2.
|
33
|
+
version: 2.37.0
|
34
34
|
- - "<"
|
35
35
|
- !ruby/object:Gem::Version
|
36
36
|
version: 3.0.0
|
@@ -40,7 +40,7 @@ dependencies:
|
|
40
40
|
requirements:
|
41
41
|
- - ">="
|
42
42
|
- !ruby/object:Gem::Version
|
43
|
-
version: 2.
|
43
|
+
version: 2.37.0
|
44
44
|
- - "<"
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: 3.0.0
|