diff options
| author | elijah <elijah@riseup.net> | 2016-06-27 14:09:11 -0700 | 
|---|---|---|
| committer | elijah <elijah@riseup.net> | 2016-06-27 16:58:04 -0700 | 
| commit | e8de57c6309daeb5e25e1b0973adb8214255077f (patch) | |
| tree | 101edba8252037bb5fc2ebbe197ec734a132495c /vendor | |
| parent | e46c4c64128621c2e84233e27b63040c027be88f (diff) | |
remove capistrano, switch to sshkit
Diffstat (limited to 'vendor')
| -rw-r--r-- | vendor/rsync_command/README.md | 12 | ||||
| -rw-r--r-- | vendor/rsync_command/lib/rsync_command.rb | 61 | 
2 files changed, 56 insertions, 17 deletions
| diff --git a/vendor/rsync_command/README.md b/vendor/rsync_command/README.md index 4b53a5c..5e44845 100644 --- a/vendor/rsync_command/README.md +++ b/vendor/rsync_command/README.md @@ -11,13 +11,15 @@ Installation  Usage  ------------------------------------ -    rsync   = RsyncCommand.new(:logger => logger, :ssh => {:auth_methods => 'publickey'}, :flags => '-a') -    source  = '/source/path' +    rsync   = RsyncCommand.new(:ssh => {:auth_methods => 'publickey'}, :flags => '-a')      servers = ['red', 'green', 'blue'] -    rsync.asynchronously(servers) do |server| -      dest = {:user => 'root', :host => server, :path => '/dest/path'} -      rsync.exec(source, dest) +    rsync.asynchronously(servers) do |sync, server| +      sync.user = 'root' +      sync.host = server +      sync.source = '/from' +      sync.dest = '/to' +      sync.exec      end      if rsync.failed? diff --git a/vendor/rsync_command/lib/rsync_command.rb b/vendor/rsync_command/lib/rsync_command.rb index 39e5945..bdcafe0 100644 --- a/vendor/rsync_command/lib/rsync_command.rb +++ b/vendor/rsync_command/lib/rsync_command.rb @@ -4,6 +4,44 @@ require "rsync_command/thread_pool"  require 'monitor' +class RsyncRunner +  attr_accessor :logger +  attr_accessor :source, :dest, :flags, :includes, :excludes +  attr_accessor :user, :host +  attr_accessor :chdir, :ssh +  def initialize(rsync_command) +    @logger = nil +    @source = "" +    @dest   = "" +    @flags  = "" +    @includes = [] +    @excludes = [] +    @rsync_command = rsync_command +  end +  def log(*args) +    @logger.log(*args) +  end +  def valid? +    !@source.empty? || !@dest.empty? +  end +  def to_hash +    fields = [:flags, :includes, :excludes, :logger, :ssh, :chdir] +    fields.inject({}){|hsh, i| +      hsh[i] = self.send(i); hsh +    } +  end +  def exec +    return unless valid? +    dest = { +      :user => self.user, +      :host => self.host, +      :path => self.dest +    } +    src = self.source +    @rsync_command.exec_rsync(src, dest, self.to_hash) +  end +end +  class RsyncCommand    attr_accessor :failures, :logger @@ -21,15 +59,23 @@ class RsyncCommand    def asynchronously(array, &block)      pool = ThreadPool.new      array.each do |item| -      pool.schedule(item, &block) +      pool.schedule(RsyncRunner.new(self), item, &block)      end      pool.shutdown    end    # +  # returns true if last exec returned a failure +  # +  def failed? +    @failures && @failures.any? +  end + +  #    # runs rsync, recording failures    # -  def exec(src, dest, options={}) +  def exec_rsync(src, dest, options={}) +    logger = options[:logger] || @logger      @failures.synchronize do        @failures.clear      end @@ -37,7 +83,7 @@ class RsyncCommand      if options[:chdir]        rsync_cmd = "cd '#{options[:chdir]}'; #{rsync_cmd}"      end -    @logger.debug rsync_cmd if @logger +    logger.debug rsync_cmd if logger      ok = system(rsync_cmd)      unless ok        @failures.synchronize do @@ -47,13 +93,6 @@ class RsyncCommand    end    # -  # returns true if last exec returned a failure -  # -  def failed? -    @failures && @failures.any? -  end - -  #    # build rsync command    #    def command(src, dest, options={}) @@ -70,8 +109,6 @@ class RsyncCommand      "rsync #{flags.compact.join(' ')} #{src} #{dest}"    end -  private -    #    # Creates an rsync location if the +address+ is a hash with keys :user, :host, and :path    # (each component is optional). If +address+ is a string, we just pass it through. | 
