kommando 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/kommando.rb +11 -23
- data/lib/kommando/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a4b7759e3a3f6c9980f7dc19353cdece83fafdca
|
4
|
+
data.tar.gz: 5c4ac9619d762838a4146a03fee7c5b314b7c920
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 378367b00a5cf6febd212d611eb35622fe37a1b530d233757e25b54d11af818778145a1f0cab1c5722049dc26cd3e8f765d72a0a1d19e52013247edf9081b8dd
|
7
|
+
data.tar.gz: 1e2c26f31ade6e75cc68dd7a965566769f54cf46346c915d2863614d9185d52ff8c36f6cdfa944344e6ba7a33bc7dd5c3f31b007d38d190972179363adf6e193
|
data/CHANGELOG.md
CHANGED
data/lib/kommando.rb
CHANGED
@@ -7,23 +7,6 @@ require_relative "kommando/buffer"
|
|
7
7
|
|
8
8
|
class Kommando
|
9
9
|
|
10
|
-
# http://stackoverflow.com/a/7263243
|
11
|
-
module SafePTY
|
12
|
-
def self.spawn command, *args, &block
|
13
|
-
|
14
|
-
PTY.spawn(command, *args) do |r,w,p|
|
15
|
-
begin
|
16
|
-
yield r,w,p
|
17
|
-
rescue Errno::EIO
|
18
|
-
ensure
|
19
|
-
Process.wait p
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
$?.exitstatus
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
10
|
def initialize(cmd, opts={})
|
28
11
|
@cmd = cmd
|
29
12
|
@stdout = Buffer.new
|
@@ -38,7 +21,7 @@ class Kommando
|
|
38
21
|
elsif opts[:timeout].class == Fixnum
|
39
22
|
opts[:timeout].to_f
|
40
23
|
end
|
41
|
-
@
|
24
|
+
@timeout_happened = false
|
42
25
|
|
43
26
|
@code = nil
|
44
27
|
@executed = false
|
@@ -52,7 +35,7 @@ class Kommando
|
|
52
35
|
|
53
36
|
command, *args = @cmd.split " "
|
54
37
|
begin
|
55
|
-
|
38
|
+
PTY.spawn(command, *args) do |stdout, stdin, pid|
|
56
39
|
if @retry && stdout.eof?
|
57
40
|
@executed = false
|
58
41
|
return run
|
@@ -66,7 +49,12 @@ class Kommando
|
|
66
49
|
Thread.abort_on_exception = true
|
67
50
|
thread_stdout = Thread.new do
|
68
51
|
while true do
|
69
|
-
|
52
|
+
begin
|
53
|
+
break if stdout.eof?
|
54
|
+
rescue Errno::EIO
|
55
|
+
# Linux http://stackoverflow.com/a/7263243
|
56
|
+
break
|
57
|
+
end
|
70
58
|
|
71
59
|
c = nil
|
72
60
|
begin
|
@@ -90,7 +78,7 @@ class Kommando
|
|
90
78
|
end
|
91
79
|
rescue Timeout::Error
|
92
80
|
Process.kill('KILL', pid)
|
93
|
-
@
|
81
|
+
@timeout_happened = true
|
94
82
|
end
|
95
83
|
else
|
96
84
|
thread_stdout.join
|
@@ -99,10 +87,10 @@ class Kommando
|
|
99
87
|
stdout_file.close if @output_file
|
100
88
|
end
|
101
89
|
|
102
|
-
@code = if @
|
90
|
+
@code = if @timeout_happened
|
103
91
|
1
|
104
92
|
else
|
105
|
-
exitstatus
|
93
|
+
$?.exitstatus
|
106
94
|
end
|
107
95
|
rescue RuntimeError => ex
|
108
96
|
if ex.message == "can't get Master/Slave device"
|
data/lib/kommando/version.rb
CHANGED