capistrano-transfer_progress 0.0.1
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/.gitignore +17 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/capistrano-transfer_progress.gemspec +22 -0
- data/lib/capistrano-transfer_progress.rb +97 -0
- data/lib/capistrano-transfer_progress/version.rb +5 -0
- metadata +89 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm --create use @transferp
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Nikos Dimitrakopoulos
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Capistrano::TransferProgress
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'capistrano-transfer_progress'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install capistrano-transfer_progress
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'capistrano-transfer_progress/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "capistrano-transfer_progress"
|
8
|
+
gem.version = Capistrano::TransferProgress::VERSION
|
9
|
+
gem.authors = ["Eric Cohen", "Nikos Dimitrakopoulos"]
|
10
|
+
gem.email = ["eirc.eirc@gmail.com", "nospam@nikosd.com"]
|
11
|
+
gem.description = %q{Progress bars for capistrano transfers}
|
12
|
+
gem.summary = %q{Hooks on capistrano transfers and provides a callback that displays a progressbar with current transfer progress}
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_runtime_dependency 'capistrano', '~> 2.0'
|
21
|
+
gem.add_runtime_dependency 'progressbar'
|
22
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require "capistrano-transfer_progress/version"
|
2
|
+
|
3
|
+
require 'progressbar'
|
4
|
+
|
5
|
+
module Capistrano
|
6
|
+
# Hooks on capistrano transfers and provides a callback that displays a progressbar with current transfer progress
|
7
|
+
#
|
8
|
+
# Can handle:
|
9
|
+
# * Simultaneous transfers
|
10
|
+
# * SCP and SFTP
|
11
|
+
# * Multiple files (recursive)
|
12
|
+
# * Uploads & Downloads
|
13
|
+
#
|
14
|
+
# Cannot handle:
|
15
|
+
# * SFTP Downloads as they do not report the total file size
|
16
|
+
module TransferProgress
|
17
|
+
def transfer(*args)
|
18
|
+
if block_given?
|
19
|
+
super(*args)
|
20
|
+
else
|
21
|
+
# Here we hook the tracking on our own by default if no progress block given to the transfer method
|
22
|
+
super(*args) { |*a| track(*a) }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Tracks SCP or SFTP tranfer progress
|
27
|
+
def track(*args)
|
28
|
+
if args[0].is_a?(Symbol) && args[1].is_a?(Net::SFTP::Operations::Upload)
|
29
|
+
track_sftp_transfer(*args)
|
30
|
+
elsif args[0].is_a?(Net::SSH::Connection::Channel)
|
31
|
+
track_scp_transfer(*args)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
#######
|
36
|
+
private
|
37
|
+
#######
|
38
|
+
|
39
|
+
def track_sftp_transfer(event, options, *others)
|
40
|
+
key = "#{options.class}-#{options.sftp.object_id}:#{others[0].local}:#{others[0].remote}" if [:open, :put, :close].include? event
|
41
|
+
|
42
|
+
case event
|
43
|
+
when :open
|
44
|
+
update_session key, 0, others[0].size
|
45
|
+
when :put
|
46
|
+
update_session key, others[1]
|
47
|
+
when :close
|
48
|
+
end_session key
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def track_scp_transfer(channel, name, sent, total)
|
53
|
+
update_session("#{channel.class}-#{channel.object_id}:#{name}", sent, total)
|
54
|
+
end
|
55
|
+
|
56
|
+
def update_session(key, sent, total = nil)
|
57
|
+
@bar ||= ProgressBar.new("Transfering", 1)
|
58
|
+
|
59
|
+
@active_sessions ||= {}
|
60
|
+
@active_sessions[key] ||= {}
|
61
|
+
@active_sessions[key].merge!(:sent => sent)
|
62
|
+
|
63
|
+
unless total.nil?
|
64
|
+
@active_sessions[key].merge!(:total => total)
|
65
|
+
update_bar_total
|
66
|
+
end
|
67
|
+
|
68
|
+
update_bar_progress
|
69
|
+
|
70
|
+
end_session(key) if sent == total
|
71
|
+
end
|
72
|
+
|
73
|
+
def end_session(key)
|
74
|
+
@active_sessions.delete key
|
75
|
+
update_bar_total
|
76
|
+
update_bar_progress
|
77
|
+
if @active_sessions.empty?
|
78
|
+
@bar.finish
|
79
|
+
@bar = nil
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def update_bar_total
|
84
|
+
new_total = @active_sessions.inject(0) { |sum, (k, v)| sum + v[:total] }
|
85
|
+
@bar.instance_eval { @total = new_total }
|
86
|
+
end
|
87
|
+
|
88
|
+
def update_bar_progress
|
89
|
+
@bar.set @active_sessions.inject(0) { |sum, (k, v)| sum + v[:sent] }
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
# Inject transfer progress tracking in current capistrano configuration instance
|
95
|
+
class Capistrano::Configuration
|
96
|
+
include Capistrano::TransferProgress
|
97
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capistrano-transfer_progress
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Eric Cohen
|
9
|
+
- Nikos Dimitrakopoulos
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2012-12-06 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: capistrano
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ~>
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '2.0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ~>
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '2.0'
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: progressbar
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
type: :runtime
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
description: Progress bars for capistrano transfers
|
48
|
+
email:
|
49
|
+
- eirc.eirc@gmail.com
|
50
|
+
- nospam@nikosd.com
|
51
|
+
executables: []
|
52
|
+
extensions: []
|
53
|
+
extra_rdoc_files: []
|
54
|
+
files:
|
55
|
+
- .gitignore
|
56
|
+
- .rvmrc
|
57
|
+
- Gemfile
|
58
|
+
- LICENSE.txt
|
59
|
+
- README.md
|
60
|
+
- Rakefile
|
61
|
+
- capistrano-transfer_progress.gemspec
|
62
|
+
- lib/capistrano-transfer_progress.rb
|
63
|
+
- lib/capistrano-transfer_progress/version.rb
|
64
|
+
homepage: ''
|
65
|
+
licenses: []
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ! '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 1.8.24
|
85
|
+
signing_key:
|
86
|
+
specification_version: 3
|
87
|
+
summary: Hooks on capistrano transfers and provides a callback that displays a progressbar
|
88
|
+
with current transfer progress
|
89
|
+
test_files: []
|