kommando 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 90cd16476bfc79190a5707fa07bd7c6d235f5a04
4
- data.tar.gz: 947a4d5c54f2837e2f969bb1ca7ef1de0487a06b
3
+ metadata.gz: e48c9ee88deb15984338770bcb3f88df16233c55
4
+ data.tar.gz: 1734e1fbce11cb305053d2a75c193a92ce71889d
5
5
  SHA512:
6
- metadata.gz: f1bf07fac67f79fa57574c243cfee2e1da16168d4c9a4ce8b7a8ba65f55f09bf491355af063c64a7a1fbce5dc456b05cce877bbdcc3d4223c2cf6002411bac31
7
- data.tar.gz: 069f925a8b7b8c13a2f317a6c9b6ea557b1a21c5aad2b82b3d03d2fe86d0023c33280c78827756a02f8acd102aab2bc6b657346ab93a1d616fa027103fc69168
6
+ metadata.gz: 1fdc4301a64924c7bd60e2555a40c27a83849c47b674deb717017cb9c873aa2693cc790332545cf39a3e818af913190b59a4de903ee2869902ea1a6470bede89
7
+ data.tar.gz: b05437941a9ec740fe09a8aac78fa8b67ee3ed05f150b88e1ddb941e0308662c96fec308195146f33bac1f85fade218faad6ad3ac702eb21be9645fdc8061123
@@ -1,5 +1,11 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.0.5
4
+ Fixes.
5
+
6
+ - FIX: File output is flushed in sync.
7
+ - FIX: Linux compatibility attempt.
8
+
3
9
  ## 0.0.4
4
10
  Writes standard out to file and timeouts.
5
11
 
data/README.md CHANGED
@@ -28,7 +28,7 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
28
28
 
29
29
  `bin/e2e` runs all Kommando files in `examples/` with `kommando`.
30
30
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bin/release`, which will run all tests, create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
32
 
33
33
  ## Contributing
34
34
 
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env sh
2
2
 
3
- VERSION=$(ruby -r "./lib/kommando/version" -e "puts Kommando::VERSION")
3
+ VERSION=$(bin/version)
4
4
 
5
5
  gem uninstall kommando
6
6
  gem build kommando.gemspec
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env bash
2
+ git diff-index --quiet --cached HEAD
3
+ if [[ $? != 0 ]]; then
4
+ echo "git dirty."
5
+ exit 1
6
+ fi
7
+
8
+ set -e
9
+
10
+ rake
11
+ bin/e2e
12
+ bin/stress 2 10
13
+
14
+ echo
15
+ head CHANGELOG.md
16
+ echo
17
+ echo "Changelog ok?"
18
+ read
19
+
20
+ bin/version
21
+ echo "Version ok?"
22
+ read
23
+
24
+ echo "Release to rubygems?"
25
+ read
26
+ echo "Sure?"
27
+ read
28
+ echo "Double sure?"
29
+ bundle exec rake release
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env bash
2
+
3
+ ruby -r "./lib/kommando/version" -e "puts Kommando::VERSION"
@@ -7,6 +7,23 @@ 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
+
10
27
  def initialize(cmd, opts={})
11
28
  @cmd = cmd
12
29
  @stdout = Buffer.new
@@ -21,8 +38,12 @@ class Kommando
21
38
  elsif opts[:timeout].class == Fixnum
22
39
  opts[:timeout].to_f
23
40
  end
41
+ @thread_did_timeout = nil
24
42
 
43
+ @code = nil
25
44
  @executed = false
45
+
46
+ @retry = opts[:retry] == true
26
47
  end
27
48
 
28
49
  def run
@@ -31,22 +52,37 @@ class Kommando
31
52
 
32
53
  command, *args = @cmd.split " "
33
54
  begin
34
- PTY.spawn(command, *args) do |stdout, stdin, pid|
35
- stdout_file = File.open @output_file, 'w' if @output_file
55
+ exitstatus = SafePTY.spawn(command, *args) do |stdout, stdin, pid|
56
+ if @retry && stdout.eof?
57
+ @executed = false
58
+ return run
59
+ end
60
+
61
+ if @output_file
62
+ stdout_file = File.open @output_file, 'w'
63
+ stdout_file.sync = true
64
+ end
36
65
 
37
66
  Thread.abort_on_exception = true
38
67
  thread_stdout = Thread.new do
39
68
  while true do
40
69
  break if stdout.eof?
41
70
 
42
- c = stdout.getc
71
+ c = nil
72
+ begin
73
+ Timeout.timeout(0.1) do
74
+ c = stdout.getc
75
+ end
76
+ rescue Timeout::Error
77
+ # sometimes it just hangs.
78
+ end
79
+
43
80
  @stdout.append c if c
44
81
  print c if @output_stdout
45
82
  stdout_file.write c if @output_file
46
83
  end
47
84
  end
48
85
 
49
- thread_did_timeout = nil
50
86
  if @timeout
51
87
  begin
52
88
  Timeout.timeout(@timeout) do
@@ -54,23 +90,19 @@ class Kommando
54
90
  end
55
91
  rescue Timeout::Error
56
92
  Process.kill('KILL', pid)
57
- thread_did_timeout = true
93
+ @thread_did_timeout = true
58
94
  end
59
95
  else
60
96
  thread_stdout.join
61
97
  end
62
98
 
63
99
  stdout_file.close if @output_file
100
+ end
64
101
 
65
- # http://stackoverflow.com/a/7263243
66
- Process.wait(pid)
67
-
68
- @code = if thread_did_timeout
69
- 1
70
- else
71
- $?.exitstatus
72
- end
73
-
102
+ @code = if @thread_did_timeout
103
+ 1
104
+ else
105
+ exitstatus
74
106
  end
75
107
  rescue RuntimeError => ex
76
108
  if ex.message == "can't get Master/Slave device"
@@ -1,3 +1,3 @@
1
1
  class Kommando
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -0,0 +1,12 @@
1
+ require "./lib/kommando"
2
+
3
+ puts "Running forever..."
4
+ while true do
5
+ k = Kommando.new "/usr/bin/true"
6
+ k.run
7
+ unless k.code == 0
8
+ raise "true failed..."
9
+ end
10
+
11
+ print "."
12
+ end
@@ -0,0 +1,21 @@
1
+ require "./lib/kommando"
2
+
3
+ puts "Running forever..."
4
+
5
+ iterations = 0
6
+ while true do
7
+ k = Kommando.new "uptime", {
8
+ retry: true # TODO: make this pass without true
9
+ }
10
+ k.run
11
+
12
+ unless k.out.size > 60
13
+ puts k.out
14
+ raise "uptime output doesn't have enough content"
15
+ end
16
+
17
+ iterations += 1
18
+ if iterations % 100 == 0
19
+ print "."
20
+ end
21
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kommando
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matti Paksula
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-05-05 00:00:00.000000000 Z
11
+ date: 2016-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -100,8 +100,10 @@ files:
100
100
  - bin/console
101
101
  - bin/e2e
102
102
  - bin/reinstall
103
+ - bin/release
103
104
  - bin/setup
104
105
  - bin/stress
106
+ - bin/version
105
107
  - examples/exit.rb
106
108
  - examples/live_output.rb
107
109
  - examples/ping.rb
@@ -113,6 +115,8 @@ files:
113
115
  - lib/kommando/buffer.rb
114
116
  - lib/kommando/error.rb
115
117
  - lib/kommando/version.rb
118
+ - tests/forever_true.rb
119
+ - tests/forever_uptime.rb
116
120
  homepage: http://github.com/matti/kommando
117
121
  licenses:
118
122
  - MIT