capistrano-sync 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -12,4 +12,8 @@ Defined three task:
12
12
 
13
13
  Add to you Gmefile:
14
14
 
15
- gem "capistrano-sync", :git => "git://github.com/dima-exe/capistrano-sync.git"
15
+ gem "capistrano-sync"
16
+
17
+ and to you Capfile:
18
+
19
+ require 'capistrano-sync'
data/Rakefile CHANGED
@@ -7,6 +7,7 @@ begin
7
7
  gemspec.email = "dima.exe@gmail.com"
8
8
  gemspec.homepage = "http://github.com/dima-exe/capistrano-sync"
9
9
  gemspec.authors = ["Dmitry Galinsky"]
10
+ gemspec.files = Dir.glob('lib/**/*.rb')
10
11
  end
11
12
  rescue LoadError
12
13
  puts "Jeweler not available. Install it with: gem install jeweler"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.1.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{capistrano-sync}
8
- s.version = "0.0.1"
8
+ s.version = "0.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Dmitry Galinsky"]
12
- s.date = %q{2011-10-06}
12
+ s.date = %q{2011-10-07}
13
13
  s.description = %q{Sync db or directories recipes for Capistrano}
14
14
  s.email = %q{dima.exe@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -25,11 +25,10 @@ Gem::Specification.new do |s|
25
25
  ]
26
26
  s.homepage = %q{http://github.com/dima-exe/capistrano-sync}
27
27
  s.require_paths = ["lib"]
28
- s.rubygems_version = %q{1.3.7}
28
+ s.rubygems_version = %q{1.6.2}
29
29
  s.summary = %q{Sync db or directories recipes for Capistrano}
30
30
 
31
31
  if s.respond_to? :specification_version then
32
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
33
32
  s.specification_version = 3
34
33
 
35
34
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
@@ -15,7 +15,7 @@ module CapistranoSyncTask
15
15
  cap.logger.info *args
16
16
  end
17
17
 
18
- # missing capture task
18
+ # missing capture
19
19
  def _capture(command, options={})
20
20
  output = ""
21
21
  cap.invoke_command(command, options.merge(:once => true)) do |ch, stream, data|
@@ -26,6 +26,14 @@ module CapistranoSyncTask
26
26
  end
27
27
  output
28
28
  end
29
+
30
+ def check_deps
31
+ system "which pv 2> /dev/null"
32
+ unless ($?.to_i == 0)
33
+ puts "FATAL: pv (Pipe Viewer) command not found, please install 'port install pv' or 'brew install pv'"
34
+ exit(1)
35
+ end
36
+ end
29
37
  end
30
38
 
31
39
  class Db
@@ -40,6 +48,7 @@ module CapistranoSyncTask
40
48
  end
41
49
 
42
50
  def sync
51
+ check_deps
43
52
  remote_config = remote_database_config
44
53
  local_config = local_database_config
45
54
 
@@ -58,9 +67,9 @@ module CapistranoSyncTask
58
67
  load_command = __send__(load_method, local_config)
59
68
  ssh_cmd, server = get_ssh_command
60
69
 
61
- log "Drop and create local database"
70
+ log "drop and create local database"
62
71
  drop_and_create_local_db
63
- log "Dump from #{server} and load to local #{local_rails_env} db (see progress)"
72
+ log "dump from #{server} and load to local #{local_rails_env} db (see progress)"
64
73
 
65
74
  cmd = "#{ssh_cmd} #{dump_command} | pv | #{load_command}"
66
75
  system cmd
@@ -152,22 +161,39 @@ module CapistranoSyncTask
152
161
  def sync
153
162
  check_deps
154
163
  ssh_cmd, server = get_ssh_command
155
- log "Download and extract #{server}:#{from} -> local:#{to} (see progress)"
164
+ log "rsync #{server}:#{from} -> local:#{to} (see progress)"
156
165
  cmd = "#{ssh_cmd} \"tar -cC #{from} .\" |pv -s #{total} | tar -x -C #{to}"
166
+ cmd = [rsync_command, cat_files_command, pv_command, trash_output_command].join(" | ")
157
167
  system cmd
158
168
  end
159
169
 
160
170
  private
161
- def check_deps
162
- system "which pv > /dev/null"
163
- unless ($?.to_i == 0)
164
- puts "FATAL: pv (Pipe Viewer) command not found, please install 'port install pv' or 'brew install pv'"
165
- exit(1)
166
- end
171
+
172
+ def rsync_command
173
+ server = cap.find_servers.first
174
+ rsh = "ssh"
175
+ rsh = "#{rsh} -p #{server.port}" if server.port
176
+ cmd = "rsync --verbose --archive --compress --copy-links --delete --rsh='#{rsh}'"
177
+ cmd << " #{cap[:user]}@#{server.host}:#{from}/"
178
+ cmd << " #{to}/ 2> /dev/null"
179
+ end
180
+
181
+ def cat_files_command
182
+ t = to.strip.to_s.gsub(/\/$/, '')
183
+ %{ruby -e "p=l='_' ; begin ; l.strip! ; puts File.read('#{t}/'+p) if File.file?('#{t}/'+p) ; p=l ; end while l=gets"}
184
+ end
185
+
186
+ def pv_command
187
+ "pv -s #{total}"
188
+ end
189
+
190
+ def trash_output_command
191
+ "cat > /dev/null"
167
192
  end
193
+
168
194
  def total
169
195
  unless @total
170
- log "Calculate files size"
196
+ log "calculate files size"
171
197
  @total = _capture("du -sb #{from} | awk '{print $1}'", :once => true).to_i
172
198
  log "TOTAL: #{proxy.number_to_human_size @total}"
173
199
  end
@@ -194,12 +220,12 @@ module CapistranoSyncTask
194
220
  namespace :dir do
195
221
  desc "sync directory"
196
222
  task :default, :roles => :app do
197
- from_path = deploy_to + "/" + ENV["FROM"]
198
- to_path = ENV["TO"]
199
- if !from_path || !to_path
223
+ if (ENV["FROM"].blank? || ENV["TO"].blank?)
200
224
  puts "Usage cap sync:dir FROM=<..> TO=<..>"
201
225
  exit(1)
202
226
  end
227
+ from_path = deploy_to + "/" + ENV["FROM"]
228
+ to_path = ENV["TO"]
203
229
  s = CapistranoSyncTask::Dir.new(self, from_path, to_path)
204
230
  s.sync
205
231
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-sync
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
5
- prerelease: false
4
+ hash: 27
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
- - 0
9
8
  - 1
10
- version: 0.0.1
9
+ - 0
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Dmitry Galinsky
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-10-06 00:00:00 +04:00
18
+ date: 2011-10-07 00:00:00 +04:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -64,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
64
64
  requirements: []
65
65
 
66
66
  rubyforge_project:
67
- rubygems_version: 1.3.7
67
+ rubygems_version: 1.6.2
68
68
  signing_key:
69
69
  specification_version: 3
70
70
  summary: Sync db or directories recipes for Capistrano