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

http://github.com/agross/netopenspace · Ruby · 69 lines · 42 code · 9 blank · 18 comment · 0 complexity · 843a61ae0160c4e3eaae9a83e940d9a3 MD5 · raw file

  1. # Copyright 2003-2010 by Jim Weirich (jim.weirich@gmail.com)
  2. # All rights reserved.
  3. # Configuration information about an upload host system.
  4. # * name :: Name of host system.
  5. # * webdir :: Base directory for the web information for the
  6. # application. The application name (APP) is appended to
  7. # this directory before using.
  8. # * pkgdir :: Directory on the host system where packages can be
  9. # placed.
  10. HostInfo = Struct.new(:name, :webdir, :pkgdir)
  11. # Manage several publishers as a single entity.
  12. class CompositePublisher
  13. def initialize
  14. @publishers = []
  15. end
  16. # Add a publisher to the composite.
  17. def add(pub)
  18. @publishers << pub
  19. end
  20. # Upload all the individual publishers.
  21. def upload
  22. @publishers.each { |p| p.upload }
  23. end
  24. end
  25. # Publish an entire directory to an existing remote directory using
  26. # SSH.
  27. class SshDirPublisher
  28. def initialize(host, remote_dir, local_dir)
  29. @host = host
  30. @remote_dir = remote_dir
  31. @local_dir = local_dir
  32. end
  33. def upload
  34. run %{scp -rq #{@local_dir}/* #{@host}:#{@remote_dir}}
  35. end
  36. end
  37. # Publish an entire directory to a fresh remote directory using SSH.
  38. class SshFreshDirPublisher < SshDirPublisher
  39. def upload
  40. run %{ssh #{@host} rm -rf #{@remote_dir}} rescue nil
  41. run %{ssh #{@host} mkdir #{@remote_dir}}
  42. super
  43. end
  44. end
  45. # Publish a list of files to an existing remote directory.
  46. class SshFilePublisher
  47. # Create a publisher using the give host information.
  48. def initialize(host, remote_dir, local_dir, *files)
  49. @host = host
  50. @remote_dir = remote_dir
  51. @local_dir = local_dir
  52. @files = files
  53. end
  54. # Upload the local directory to the remote directory.
  55. def upload
  56. @files.each do |fn|
  57. run %{scp -q #{@local_dir}/#{fn} #{@host}:#{@remote_dir}}
  58. end
  59. end
  60. end