class Rbfs::Rsync

Public Class Methods

new(config = {}, host = nil) click to toggle source
# File lib/rbfs/rsync.rb, line 5
def initialize(config = {}, host = nil)
  @config = config
  @host = host
end

Public Instance Methods

command(cmd, options = [], &block) click to toggle source
# File lib/rbfs/rsync.rb, line 60
def command(cmd, options = [], &block)
  cmd_line = "#{cmd} "
  cmd_line += options.join(' ')
  output = run_command(cmd_line, &block)
  exitcode = $?
  {:output => output, :exitcode => exitcode}
end
config() click to toggle source
# File lib/rbfs/rsync.rb, line 10
def config
  @config
end
local_root() click to toggle source
# File lib/rbfs/rsync.rb, line 34
def local_root
  path = sub_root(config[:root])
  path += "/" if File.directory?(path)
  path
end
logger() click to toggle source
# File lib/rbfs/rsync.rb, line 14
def logger
  config[:logger]
end
mkdir() click to toggle source
# File lib/rbfs/rsync.rb, line 40
def mkdir
  args = [@host.ip, "mkdir", "-p", File.dirname(remote_root)]
  command("ssh", args)
end
remote_root() click to toggle source
# File lib/rbfs/rsync.rb, line 30
def remote_root
  sub_root(config[:remote_root])
end
remote_url() click to toggle source
# File lib/rbfs/rsync.rb, line 26
def remote_url
  "#{@host.ip}:#{remote_root}"
end
rsync() click to toggle source
# File lib/rbfs/rsync.rb, line 45
def rsync
  args = ["-a", "--delete"]
  args << "-v" if config[:verbose]
  args << "-n" if config[:dry]
  args << "--timeout=#{config[:timeout]}" if config[:timeout]
  ::Rsync.run(local_root, remote_url, args)
end
run_command(cmd, &block) click to toggle source
# File lib/rbfs/rsync.rb, line 68
def run_command(cmd, &block)
  if block_given?
    IO.popen("#{cmd} 2>&1", &block)
  else
    `#{cmd} 2>&1`
  end
end
sub_root(path) click to toggle source
# File lib/rbfs/rsync.rb, line 18
def sub_root(path)
  if config[:subpath]
    File.join(path, config[:subpath])
  else
    path
  end
end
sync() click to toggle source
# File lib/rbfs/rsync.rb, line 53
def sync
  if config[:subpath]
    mkdir
  end
  rsync
end