PageRenderTime 22ms CodeModel.GetById 17ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/tools/Ruby/lib/ruby/gems/1.8/gems/rake-0.9.2/lib/rake/contrib/sshpublisher.rb

http://github.com/agross/netopenspace
Ruby | 45 lines | 33 code | 6 blank | 6 comment | 0 complexity | 1dd2ece2323b033f020a1ef031a36fc3 MD5 | raw file
 1require 'rake/contrib/compositepublisher'
 2
 3module Rake
 4
 5  # Publish an entire directory to an existing remote directory using
 6  # SSH.
 7  class SshDirPublisher
 8    def initialize(host, remote_dir, local_dir)
 9      @host = host
10      @remote_dir = remote_dir
11      @local_dir = local_dir
12    end
13
14    def upload
15      sh %{scp -rq #{@local_dir}/* #{@host}:#{@remote_dir}}
16    end
17  end
18
19  # Publish an entire directory to a fresh remote directory using SSH.
20  class SshFreshDirPublisher < SshDirPublisher
21    def upload
22      sh %{ssh #{@host} rm -rf #{@remote_dir}} rescue nil
23      sh %{ssh #{@host} mkdir #{@remote_dir}}
24      super
25    end
26  end
27
28  # Publish a list of files to an existing remote directory.
29  class SshFilePublisher
30    # Create a publisher using the give host information.
31    def initialize(host, remote_dir, local_dir, *files)
32      @host = host
33      @remote_dir = remote_dir
34      @local_dir = local_dir
35      @files = files
36    end
37
38    # Upload the local directory to the remote directory.
39    def upload
40      @files.each do |fn|
41        sh %{scp -q #{@local_dir}/#{fn} #{@host}:#{@remote_dir}}
42      end
43    end
44  end
45end