/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

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