ztk 1.0.9 → 1.0.10

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/.travis.yml CHANGED
@@ -3,13 +3,14 @@ language: ruby
3
3
  rvm:
4
4
  - 1.9.2
5
5
  - 1.9.3
6
+ - 2.0.0
6
7
 
7
8
  before_install:
8
- - sudo apt-get -qq update
9
+ - sudo apt-get -qq --force-yes update
9
10
 
10
11
  bundler_args: --binstubs
11
12
 
12
- script: "rake spec"
13
+ script: "rake test"
13
14
 
14
15
  notifications:
15
16
  irc: "irc.freenode.net#jovelabs"
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  [![Build Status](https://secure.travis-ci.org/zpatten/ztk.png)](http://travis-ci.org/zpatten/ztk)
2
- [![Dependency Status](https://gemnasium.com/zpatten/ztk.png)](https://gemnasium.com/zpatten/ztk)
3
2
  [![Code Climate](https://codeclimate.com/github/zpatten/ztk.png)](https://codeclimate.com/github/zpatten/ztk)
3
+ [![Dependency Status](https://gemnasium.com/zpatten/ztk.png)](https://gemnasium.com/zpatten/ztk)
4
4
 
5
5
  # ZTK
6
6
 
data/lib/ztk.rb CHANGED
@@ -43,6 +43,7 @@ module ZTK
43
43
  autoload :Config, "ztk/config"
44
44
  autoload :Logger, "ztk/logger"
45
45
  autoload :Parallel, "ztk/parallel"
46
+ autoload :PTY, "ztk/pty"
46
47
  autoload :Report, "ztk/report"
47
48
  autoload :RescueRetry, "ztk/rescue_retry"
48
49
  autoload :Spinner, "ztk/spinner"
data/lib/ztk/command.rb CHANGED
@@ -61,7 +61,7 @@ module ZTK
61
61
  # @example Execute a command:
62
62
  #
63
63
  # cmd = ZTK::Command.new
64
- # puts cmd.exec("hostname -f").inspect
64
+ # puts cmd.exec("hostname").inspect
65
65
  #
66
66
  def exec(command, options={})
67
67
  options = OpenStruct.new({ :exit_code => 0, :silence => false }.merge(config.send(:table)).merge(options))
data/lib/ztk/pty.rb ADDED
@@ -0,0 +1,61 @@
1
+ ################################################################################
2
+ #
3
+ # Author: Zachary Patten <zachary@jovelabs.net>
4
+ # Copyright: Copyright (c) Zachary Patten
5
+ # License: Apache License, Version 2.0
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+ ################################################################################
20
+ require 'pty'
21
+
22
+ module ZTK
23
+
24
+ # ZTK::PTY Error Class
25
+ # @author Zachary Patten <zachary@jovelabs.net>
26
+ class PTYError < Error; end
27
+
28
+ # Ruby PTY Class Wrapper
29
+ # @author Zachary Patten <zachary@jovelabs.net>
30
+ class PTY
31
+
32
+ class << self
33
+
34
+ # Wraps the Ruby PTY class, providing better functionality.
35
+ #
36
+ # @param [Array] args An argument splat to be passed to PTY::spawn
37
+ #
38
+ # @return [Object] Returns the $? object.
39
+ def spawn(*args, &block)
40
+
41
+ if block_given?
42
+ ::PTY.spawn(*args) do |reader, writer, pid|
43
+ begin
44
+ yield(reader, writer, pid)
45
+ rescue Errno::EIO
46
+ ensure
47
+ ::Process.wait(pid)
48
+ end
49
+ end
50
+ else
51
+ reader, writer, pid = ::PTY.spawn(*args)
52
+ end
53
+
54
+ [reader, writer, pid]
55
+ end
56
+
57
+ end
58
+
59
+ end
60
+
61
+ end
data/lib/ztk/ssh.rb CHANGED
@@ -205,7 +205,7 @@ module ZTK
205
205
  # config.user = ENV["USER"]
206
206
  # config.host_name = "127.0.0.1"
207
207
  # end
208
- # puts ssh.exec("hostname -f").inspect
208
+ # puts ssh.exec("hostname").inspect
209
209
  def exec(command, options={})
210
210
  options = OpenStruct.new({ :exit_code => 0, :silence => false }.merge(config.send(:table)).merge(options))
211
211
 
data/lib/ztk/version.rb CHANGED
@@ -21,6 +21,6 @@
21
21
  module ZTK
22
22
 
23
23
  # ZTK Version String
24
- VERSION = "1.0.9"
24
+ VERSION = "1.0.10"
25
25
 
26
26
  end
data/spec/spec_helper.rb CHANGED
@@ -31,6 +31,7 @@ end if ENV["COVERAGE"]
31
31
  ENV['LOG_LEVEL'] = "DEBUG"
32
32
 
33
33
  WAIT_SMALL = 3
34
+ READ_PARTIAL_CHUNK = 2048
34
35
 
35
36
  RSpec.configure do |config|
36
37
 
@@ -36,12 +36,12 @@ describe ZTK::Command do
36
36
 
37
37
  describe "execute" do
38
38
 
39
- it "should be able to execute the command \"hostname -f\"" do
39
+ it "should be able to execute the command \"hostname\"" do
40
40
  subject.config do |config|
41
41
  config.ui = $ui
42
42
  end
43
- hostname = %x(hostname -f).chomp
44
- status = subject.exec("hostname -f")
43
+ hostname = %x(hostname).chomp
44
+ status = subject.exec("hostname")
45
45
  status.exit_code.should == 0
46
46
  $ui.stdout.rewind
47
47
  $ui.stdout.read.chomp.should == hostname
@@ -52,8 +52,8 @@ describe ZTK::Command do
52
52
  config.ui = $ui
53
53
  config.timeout = WAIT_SMALL
54
54
  end
55
- hostname = %x(hostname -f).chomp
56
- lambda { subject.exec("hostname -f ; sleep 10") }.should raise_error ZTK::CommandError
55
+ hostname = %x(hostname).chomp
56
+ lambda { subject.exec("hostname ; sleep 10") }.should raise_error ZTK::CommandError
57
57
  end
58
58
 
59
59
  it "should throw an exception if the exit status is not as expected" do
@@ -107,7 +107,7 @@ describe ZTK::Command do
107
107
  end
108
108
  data = "Hello World @ #{Time.now.utc}"
109
109
 
110
- subject.exec(%Q{echo "#{data}" -f >&1})
110
+ subject.exec(%Q{echo "#{data}" >&1})
111
111
 
112
112
  $ui.stdout.rewind
113
113
  $ui.stdout.read.match(data).should_not be nil
@@ -129,7 +129,7 @@ describe ZTK::Command do
129
129
  end
130
130
  data = "Hello World @ #{Time.now.utc}"
131
131
 
132
- subject.exec(%Q{echo "#{data}" -f >&2})
132
+ subject.exec(%Q{echo "#{data}" >&2})
133
133
 
134
134
  $ui.stdout.rewind
135
135
  $ui.stdout.read.match(data).should be nil
@@ -0,0 +1,100 @@
1
+ ################################################################################
2
+ #
3
+ # Author: Zachary Patten <zachary@jovelabs.net>
4
+ # Copyright: Copyright (c) Zachary Patten
5
+ # License: Apache License, Version 2.0
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+ ################################################################################
20
+
21
+ require "spec_helper"
22
+
23
+ describe ZTK::PTY do
24
+
25
+ subject { ZTK::PTY }
26
+
27
+ describe "class" do
28
+
29
+ it "should be ZTK::PTY" do
30
+ subject.should be ZTK::PTY
31
+ end
32
+
33
+ end
34
+
35
+ describe "behaviour" do
36
+
37
+ it "should spawn a command with a block" do
38
+ lambda do
39
+ subject.spawn("hostname") do |r, w, p|
40
+ end
41
+ end.should_not raise_error
42
+ end
43
+
44
+ it "should spawn a command without a block" do
45
+ lambda do
46
+ r, w, p = subject.spawn("hostname")
47
+ end.should_not raise_error
48
+ end
49
+
50
+ describe "spawn" do
51
+
52
+ it "should be able to spawn the command \"hostname\"" do
53
+ data = %x(hostname).chomp
54
+
55
+ reader, writer, pid = subject.spawn("hostname")
56
+ output = reader.readpartial(READ_PARTIAL_CHUNK).chomp
57
+
58
+ output.should == data
59
+ end
60
+
61
+ it "should return the output of spawned commands" do
62
+ data = "Hello World @ #{Time.now.utc}"
63
+
64
+ reader, writer, pid = subject.spawn(%(echo "#{data}"))
65
+ output = reader.readpartial(READ_PARTIAL_CHUNK).chomp
66
+
67
+ output.should == data
68
+ end
69
+
70
+ describe "stdout" do
71
+
72
+ it "should capture stdout and send it to the reader" do
73
+ data = "Hello World @ #{Time.now.utc}"
74
+
75
+ reader, writer, pid = subject.spawn(%(echo "#{data}" >&1))
76
+ output = reader.readpartial(READ_PARTIAL_CHUNK).chomp
77
+
78
+ output.should == data
79
+ end
80
+
81
+ end
82
+
83
+ describe "stderr" do
84
+
85
+ it "should capture stderr and send it to the reader" do
86
+ data = "Hello World @ #{Time.now.utc}"
87
+
88
+ reader, writer, pid = subject.spawn(%(echo "#{data}" >&2))
89
+ output = reader.readpartial(READ_PARTIAL_CHUNK).chomp
90
+
91
+ output.should == data
92
+ end
93
+
94
+ end
95
+
96
+ end
97
+
98
+ end
99
+
100
+ end
data/spec/ztk/ssh_spec.rb CHANGED
@@ -45,9 +45,9 @@ describe ZTK::SSH do
45
45
  config.host_name = "127.0.0.1"
46
46
  end
47
47
 
48
- data = %x(hostname -f).chomp
48
+ data = %x(hostname).chomp
49
49
 
50
- status = subject.exec("hostname -f")
50
+ status = subject.exec("hostname")
51
51
  status.exit_code.should == 0
52
52
  $ui.stdout.rewind
53
53
  $ui.stdout.read.chomp.should == data
@@ -61,8 +61,8 @@ describe ZTK::SSH do
61
61
  config.host_name = "127.0.0.1"
62
62
  config.timeout = WAIT_SMALL
63
63
  end
64
- hostname = %x(hostname -f).chomp
65
- lambda { subject.exec("hostname -f ; sleep 10") }.should raise_error ZTK::SSHError
64
+ hostname = %x(hostname).chomp
65
+ lambda { subject.exec("hostname ; sleep 10") }.should raise_error ZTK::SSHError
66
66
  end
67
67
 
68
68
  it "should throw an exception if the exit status is not as expected" do
@@ -293,9 +293,9 @@ describe ZTK::SSH do
293
293
  config.proxy_host_name = "127.0.0.1"
294
294
  end
295
295
 
296
- data = %x( hostname -f ).chomp
296
+ data = %x( hostname ).chomp
297
297
 
298
- status = subject.exec("hostname -f")
298
+ status = subject.exec("hostname")
299
299
  status.exit_code.should == 0
300
300
  $ui.stdout.rewind
301
301
  $ui.stdout.read.chomp.should == data
@@ -311,8 +311,8 @@ describe ZTK::SSH do
311
311
  config.proxy_host_name = "127.0.0.1"
312
312
  config.timeout = WAIT_SMALL
313
313
  end
314
- hostname = %x(hostname -f).chomp
315
- lambda { subject.exec("hostname -f ; sleep 10") }.should raise_error ZTK::SSHError
314
+ hostname = %x(hostname).chomp
315
+ lambda { subject.exec("hostname ; sleep 10") }.should raise_error ZTK::SSHError
316
316
  end
317
317
 
318
318
  it "should throw an exception if the exit status is not as expected" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ztk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.9
4
+ version: 1.0.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-07 00:00:00.000000000 Z
12
+ date: 2013-04-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: erubis
@@ -209,6 +209,7 @@ files:
209
209
  - lib/ztk/dsl/core/relations/has_many.rb
210
210
  - lib/ztk/logger.rb
211
211
  - lib/ztk/parallel.rb
212
+ - lib/ztk/pty.rb
212
213
  - lib/ztk/report.rb
213
214
  - lib/ztk/rescue_retry.rb
214
215
  - lib/ztk/spinner.rb
@@ -228,6 +229,7 @@ files:
228
229
  - spec/ztk/dsl_spec.rb
229
230
  - spec/ztk/logger_spec.rb
230
231
  - spec/ztk/parallel_spec.rb
232
+ - spec/ztk/pty_spec.rb
231
233
  - spec/ztk/rescue_retry_spec.rb
232
234
  - spec/ztk/spinner_spec.rb
233
235
  - spec/ztk/ssh_spec.rb
@@ -250,7 +252,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
250
252
  version: '0'
251
253
  segments:
252
254
  - 0
253
- hash: -955411107059050686
255
+ hash: 4473587828937144611
254
256
  required_rubygems_version: !ruby/object:Gem::Requirement
255
257
  none: false
256
258
  requirements:
@@ -259,10 +261,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
259
261
  version: '0'
260
262
  segments:
261
263
  - 0
262
- hash: -955411107059050686
264
+ hash: 4473587828937144611
263
265
  requirements: []
264
266
  rubyforge_project:
265
- rubygems_version: 1.8.24
267
+ rubygems_version: 1.8.25
266
268
  signing_key:
267
269
  specification_version: 3
268
270
  summary: Contains various classes and utilities I find I regularly need.
@@ -278,6 +280,7 @@ test_files:
278
280
  - spec/ztk/dsl_spec.rb
279
281
  - spec/ztk/logger_spec.rb
280
282
  - spec/ztk/parallel_spec.rb
283
+ - spec/ztk/pty_spec.rb
281
284
  - spec/ztk/rescue_retry_spec.rb
282
285
  - spec/ztk/spinner_spec.rb
283
286
  - spec/ztk/ssh_spec.rb