ztk 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -64,14 +64,14 @@ module ZTK
64
64
  # puts cmd.exec("hostname -f").inspect
65
65
  #
66
66
  def exec(command, options={})
67
- options = OpenStruct.new({ :exit_code => 0, :silence => false }.merge(options))
67
+ options = OpenStruct.new({ :exit_code => 0, :silence => false }.merge(config.send(:table)).merge(options))
68
68
 
69
- config.ui.logger.debug { "config=#{config.send(:table).inspect}" }
70
- config.ui.logger.debug { "options=#{options.send(:table).inspect}" }
71
- config.ui.logger.info { "command(#{command.inspect})" }
69
+ options.ui.logger.debug { "config=#{options.send(:table).inspect}" }
70
+ options.ui.logger.debug { "options=#{options.send(:table).inspect}" }
71
+ options.ui.logger.info { "command(#{command.inspect})" }
72
72
 
73
- if config.replace_current_process
74
- config.ui.logger.fatal { "REPLACING CURRENT PROCESS - GOODBYE!" }
73
+ if options.replace_current_process
74
+ options.ui.logger.fatal { "REPLACING CURRENT PROCESS - GOODBYE!" }
75
75
  Kernel.exec(command)
76
76
  end
77
77
 
@@ -102,14 +102,14 @@ module ZTK
102
102
  child_stderr_writer.close
103
103
 
104
104
  reader_writer_key = {parent_stdout_reader => :stdout, parent_stderr_reader => :stderr}
105
- reader_writer_map = {parent_stdout_reader => @config.ui.stdout, parent_stderr_reader => @config.ui.stderr}
105
+ reader_writer_map = {parent_stdout_reader => options.ui.stdout, parent_stderr_reader => options.ui.stderr}
106
106
 
107
107
  direct_log(:debug) { log_header("COMMAND") }
108
108
  direct_log(:debug) { "#{command}\n" }
109
109
  direct_log(:debug) { log_header("STARTED") }
110
110
 
111
111
  begin
112
- Timeout.timeout(config.timeout) do
112
+ Timeout.timeout(options.timeout) do
113
113
  loop do
114
114
  pipes = IO.select(reader_writer_map.keys, [], reader_writer_map.keys).first
115
115
  pipes.each do |pipe|
@@ -143,7 +143,7 @@ module ZTK
143
143
  end
144
144
  rescue Timeout::Error => e
145
145
  direct_log(:debug) { log_header("TIMEOUT") }
146
- log_and_raise(CommandError, "Process timed out after #{config.timeout} seconds!")
146
+ log_and_raise(CommandError, "Process timed out after #{options.timeout} seconds!")
147
147
  end
148
148
 
149
149
  Process.waitpid(pid)
@@ -153,9 +153,9 @@ module ZTK
153
153
  parent_stdout_reader.close
154
154
  parent_stderr_reader.close
155
155
 
156
- config.ui.logger.debug { "exit_code(#{exit_code})" }
156
+ options.ui.logger.debug { "exit_code(#{exit_code})" }
157
157
 
158
- if !config.ignore_exit_status && (exit_code != options.exit_code)
158
+ if !options.ignore_exit_status && (exit_code != options.exit_code)
159
159
  log_and_raise(CommandError, "exec(#{command.inspect}, #{options.inspect}) failed! [#{exit_code}]")
160
160
  end
161
161
  OpenStruct.new(:output => output, :exit_code => exit_code)
@@ -203,11 +203,11 @@ module ZTK
203
203
  # end
204
204
  # puts ssh.exec("hostname -f").inspect
205
205
  def exec(command, options={})
206
- options = OpenStruct.new({ :exit_code => 0, :silence => false }.merge(options))
206
+ options = OpenStruct.new({ :exit_code => 0, :silence => false }.merge(config.send(:table)).merge(options))
207
207
 
208
- config.ui.logger.debug { "config=#{config.send(:table).inspect}" }
209
- config.ui.logger.debug { "options=#{options.send(:table).inspect}" }
210
- config.ui.logger.info { "exec(#{command.inspect})" }
208
+ options.ui.logger.debug { "config=#{options.send(:table).inspect}" }
209
+ options.ui.logger.debug { "options=#{options.send(:table).inspect}" }
210
+ options.ui.logger.info { "exec(#{command.inspect})" }
211
211
 
212
212
  output = ""
213
213
  exit_code = -1
@@ -216,12 +216,12 @@ module ZTK
216
216
  stderr_header = false
217
217
 
218
218
  begin
219
- Timeout.timeout(config.timeout) do
219
+ Timeout.timeout(options.timeout) do
220
220
  ZTK::RescueRetry.try(:tries => 3, :on => EOFError) do
221
- @ssh = Net::SSH.start(config.host_name, config.user, ssh_options)
221
+ @ssh = Net::SSH.start(options.host_name, options.user, ssh_options)
222
222
 
223
223
  channel = ssh.open_channel do |chan|
224
- config.ui.logger.debug { "Channel opened." }
224
+ options.ui.logger.debug { "Channel opened." }
225
225
 
226
226
  direct_log(:debug) { log_header("COMMAND") }
227
227
  direct_log(:debug) { "#{command}\n" }
@@ -238,7 +238,7 @@ module ZTK
238
238
  end
239
239
  direct_log(:debug) { data }
240
240
 
241
- config.ui.stdout.print(data) unless options.silence
241
+ options.ui.stdout.print(data) unless options.silence
242
242
  output += data
243
243
  end
244
244
 
@@ -250,7 +250,7 @@ module ZTK
250
250
  end
251
251
  direct_log(:warn) { data }
252
252
 
253
- config.ui.stderr.print(data) unless options.silence
253
+ options.ui.stderr.print(data) unless options.silence
254
254
  output += data
255
255
  end
256
256
 
@@ -263,7 +263,7 @@ module ZTK
263
263
  end
264
264
 
265
265
  ch.on_open_failed do |c, code, desc|
266
- config.ui.logger.fatal { "Open failed! (#{code.inspect} - #{desc.inspect})" }
266
+ options.ui.logger.fatal { "Open failed! (#{code.inspect} - #{desc.inspect})" }
267
267
  end
268
268
 
269
269
  end
@@ -271,13 +271,13 @@ module ZTK
271
271
  channel.wait
272
272
 
273
273
  direct_log(:debug) { log_header("CLOSED") }
274
- config.ui.logger.debug { "Channel closed." }
274
+ options.ui.logger.debug { "Channel closed." }
275
275
  end
276
276
  end
277
277
 
278
278
  rescue Timeout::Error => e
279
279
  direct_log(:debug) { log_header("TIMEOUT") }
280
- log_and_raise(SSHError, "Session timed out after #{config.timeout} seconds!")
280
+ log_and_raise(SSHError, "Session timed out after #{options.timeout} seconds!")
281
281
  end
282
282
 
283
283
  message = [
@@ -285,9 +285,9 @@ module ZTK
285
285
  (exit_signal.nil? ? nil : "exit_signal=#{exit_signal} (#{EXIT_SIGNALS[exit_signal]})")
286
286
  ].compact.join(", ")
287
287
 
288
- config.ui.logger.debug { message }
288
+ options.ui.logger.debug { message }
289
289
 
290
- if !config.ignore_exit_status && (exit_code != options.exit_code)
290
+ if !options.ignore_exit_status && (exit_code != options.exit_code)
291
291
  log_and_raise(SSHError, message)
292
292
  end
293
293
  OpenStruct.new(:output => output, :exit_code => exit_code, :exit_signal => exit_signal)
@@ -27,7 +27,10 @@ module ZTK
27
27
  # @author Zachary Patten <zachary@jovelabs.net>
28
28
  class UIError < Error; end
29
29
 
30
- # ZTK UI Wrapper Class
30
+ # ZTK UI Class
31
+ #
32
+ # This class encapsulates a STDOUT, STDERR, STDIN
33
+ # and logging device.
31
34
  #
32
35
  # @author Zachary Patten <zachary@jovelabs.net>
33
36
  class UI < ZTK::Base
@@ -21,6 +21,6 @@
21
21
  module ZTK
22
22
 
23
23
  # ZTK Version String
24
- VERSION = "1.0.0"
24
+ VERSION = "1.0.1"
25
25
 
26
26
  end
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.0
4
+ version: 1.0.1
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-02-03 00:00:00.000000000 Z
12
+ date: 2013-02-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: erubis
@@ -250,7 +250,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
250
250
  version: '0'
251
251
  segments:
252
252
  - 0
253
- hash: 3551649041852268044
253
+ hash: 4264063468850380802
254
254
  required_rubygems_version: !ruby/object:Gem::Requirement
255
255
  none: false
256
256
  requirements:
@@ -259,7 +259,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
259
259
  version: '0'
260
260
  segments:
261
261
  - 0
262
- hash: 3551649041852268044
262
+ hash: 4264063468850380802
263
263
  requirements: []
264
264
  rubyforge_project:
265
265
  rubygems_version: 1.8.24