sshkit 0.0.23 → 0.0.24

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/CHANGELOG.md CHANGED
@@ -3,6 +3,28 @@
3
3
  This file is written in reverse chronological order, newer releases will
4
4
  appear at the top.
5
5
 
6
+ ## 0.0.24
7
+
8
+ * Pretty output now streams stdout and stderr. Previous versions would
9
+ append (`+=`) chunks of data written by the remote host to the `Command`
10
+ instance, and the `Pretty` formatter would only print stdout/stderr if the
11
+ command was `#complete?`. Historically this lead to issues where the
12
+ remote process was blocking for input, had written the prompt to stdout,
13
+ but it was not visible on the client side.
14
+
15
+ Now each time the command is passed to the output stream, the
16
+ stdout/stderr are replaced with the lines returned from the remote server
17
+ in this chunk. (i.e were yielded to the callback block). Commands now have
18
+ attribute accessors for `#full_stdout` and `#full_stderr` which are appended
19
+ in the way that `#stdout` and `#stderr` were previously.
20
+
21
+ This should be considered a private API, and one should beware of relying
22
+ on `#full_stdout` or `#full_stderr`, they will likely be replaced with a
23
+ cleaner soltion eventually.
24
+
25
+ * `upload!` and `download!` now print progress reports at the `Logger::INFO`
26
+ verbosity level.
27
+
6
28
  ## 0.0.23
7
29
 
8
30
  * Explicitly rely on `net-scp` gem.
data/EXAMPLES.md CHANGED
@@ -42,14 +42,14 @@
42
42
  end
43
43
  end
44
44
 
45
- The `debug()``, `info()`, `warn()`, `error()` and `fatal()` honor the current
45
+ The `debug()`, `info()`, `warn()`, `error()` and `fatal()` honor the current
46
46
  log level of `SSHKit.config.output_verbosity`
47
47
 
48
48
  ## Run a command in a different directory as a different user
49
49
 
50
50
  on hosts do |host|
51
51
  as 'www-data' do
52
- in '/var/log' do
52
+ within '/var/log' do
53
53
  puts capture(:whoami)
54
54
  puts capture(:pwd)
55
55
  end
@@ -70,7 +70,7 @@ have a shell defined, one cannot switch to that user.
70
70
  upload! '/config/database.yml', '/opt/my_project/shared/databse.yml'
71
71
  end
72
72
 
73
- **Note:** The `upload!()` method doesn't honor the values of `in()`, `as()`
73
+ **Note:** The `upload!()` method doesn't honor the values of `within()`, `as()`
74
74
  etc, this will be improved as the library matures, but we're not there yet.
75
75
 
76
76
  ## Upload a file from a stream
@@ -93,14 +93,23 @@ for example
93
93
  This spares one from having to figure out the correct escaping sequences for
94
94
  something like "echo(:cat, '...?...', '> /etc/sudoers.d/yolo')".
95
95
 
96
- **Note:** The `upload!()` method doesn't honor the values of `in()`, `as()`
96
+ **Note:** The `upload!()` method doesn't honor the values of `within()`, `as()`
97
97
  etc, this will be improved as the library matures, but we're not there yet.
98
98
 
99
+ ## Upload a directory of files
100
+
101
+ on hosts do |host|
102
+ upload! '.', '/tmp/mypwd', recursive: true
103
+ end
104
+
105
+ In this case the `recursive: true` option mirrors the same options which are
106
+ available to `Net::{SCP,SFTP}`.
107
+
99
108
  ## Run a command with a different effective group ID
100
109
 
101
110
  on hosts do |host|
102
111
  as user: 'www-data', group: 'project-group' do
103
- in '/var/log' do
112
+ within '/var/log' do
104
113
  execute :touch, 'somefile'
105
114
  execute :ls, '-l'
106
115
  end
@@ -116,9 +125,9 @@ scripts for deployment between team members without sharing logins.
116
125
  ## Stack directory nestings
117
126
 
118
127
  on hosts do
119
- in "/var" do
128
+ within "/var" do
120
129
  puts capture(:pwd)
121
- in :log do
130
+ within :log do
122
131
  puts capture(:pwd)
123
132
  end
124
133
  end
@@ -138,7 +147,7 @@ joined according to the expectations of the machine receiving the commands.
138
147
  ## Running a task in the background
139
148
 
140
149
  on hosts do
141
- in '/opt/sites/example.com' do
150
+ within '/opt/sites/example.com' do
142
151
  background :rails, :server
143
152
  end
144
153
  end
@@ -1,4 +1,5 @@
1
1
  require 'net/ssh'
2
+ require 'net/scp'
2
3
 
3
4
  module SSHKit
4
5
  module Backend
@@ -34,18 +35,18 @@ module SSHKit
34
35
 
35
36
  def capture(*args)
36
37
  options = args.extract_options!.merge(verbosity: Logger::DEBUG)
37
- _execute(*[*args, options]).stdout.strip
38
+ _execute(*[*args, options]).full_stdout.strip
38
39
  end
39
40
 
40
41
  def upload!(local, remote, options = {})
41
- ssh.scp.upload!(local, remote, options) do
42
- warn "Progress"
42
+ ssh.scp.upload!(local, remote, options) do |ch, name, sent, total|
43
+ info "Uploading #{name} #{(sent.to_f * 100 / total.to_f).to_i}%"
43
44
  end
44
45
  end
45
46
 
46
47
  def download!(remote, local=nil, options = {})
47
- ssh.scp.download!(remote, local, options) do
48
- warn "Progress"
48
+ ssh.scp.download!(remote, local, options) do |ch, name, received, total|
49
+ info "Downloading #{name} #{(received.to_f * 100 / total.to_f).to_i}%"
49
50
  end
50
51
  end
51
52
 
@@ -69,11 +70,13 @@ module SSHKit
69
70
  chan.request_pty if Netssh.config.pty
70
71
  chan.exec cmd.to_command do |ch, success|
71
72
  chan.on_data do |ch, data|
72
- cmd.stdout += data
73
+ cmd.stdout = data
74
+ cmd.full_stdout += data
73
75
  output << cmd
74
76
  end
75
77
  chan.on_extended_data do |ch, type, data|
76
- cmd.stderr += data
78
+ cmd.stderr = data
79
+ cmd.full_stderr += data
77
80
  output << cmd
78
81
  end
79
82
  chan.on_request("exit-status") do |ch, data|
@@ -36,6 +36,7 @@ module SSHKit
36
36
  attr_reader :command, :args, :options, :started_at, :started, :exit_status
37
37
 
38
38
  attr_accessor :stdout, :stderr
39
+ attr_accessor :full_stdout, :full_stderr
39
40
 
40
41
  # Initialize a new Command object
41
42
  #
@@ -52,6 +53,7 @@ module SSHKit
52
53
  @options.symbolize_keys!
53
54
  sanitize_command!
54
55
  @stdout, @stderr = String.new, String.new
56
+ @full_stdout, @full_stderr = String.new, String.new
55
57
  end
56
58
 
57
59
  def complete?
@@ -28,13 +28,13 @@ module SSHKit
28
28
  end
29
29
 
30
30
  if SSHKit.config.output_verbosity == Logger::DEBUG
31
- if command.complete? && !command.stdout.empty?
31
+ unless command.stdout.empty?
32
32
  command.stdout.lines.each do |line|
33
33
  original_output << level(Logger::DEBUG) + uuid(command) + c.green("\t" + line)
34
34
  end
35
35
  end
36
36
 
37
- if command.complete? && !command.stderr.empty?
37
+ unless command.stderr.empty?
38
38
  command.stderr.lines.each do |line|
39
39
  original_output << level(Logger::DEBUG) + uuid(command) + c.red("\t" + line)
40
40
  end
@@ -1,3 +1,3 @@
1
1
  module SSHKit
2
- VERSION = "0.0.23"
2
+ VERSION = "0.0.24"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sshkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.23
4
+ version: 0.0.24
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-03-29 00:00:00.000000000 Z
13
+ date: 2013-04-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: net-ssh