PageRenderTime 109ms CodeModel.GetById 104ms app.highlight 4ms RepoModel.GetById 0ms app.codeStats 1ms

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