Sha256: 8904bcfb02feab2bc2fd78ee8a151d7fae7b4536a341a6987451f15f37157c97

Contents?: true

Size: 1.9 KB

Versions: 8

Compression:

Stored size: 1.9 KB

Contents

require 'awestruct/deploy/base_deploy'
require 'shellwords'
require 'open3'

module Awestruct
  module Deploy
    class RSyncDeploy < Base

      def initialize(site_config, deploy_config)
        @site_path = File.join( site_config.output_dir, '/' ).gsub(/^\w:\//, '/')
        @host      = deploy_config['host']
        @path      = File.join( deploy_config['path'], '/' )
        @exclude   = deploy_config['exclude']
      end

      def publish_site
        exclude_option = (!@exclude.nil? and !@exclude.empty?) ? "--exclude=" + Shellwords.escape(@exclude) : nil
        site_path = Shellwords.escape(@site_path)
        host = Shellwords.escape(@host)
        path = Shellwords.escape(@path)

        cmd = "rsync -r -l -i --no-p --no-g --chmod=Dg+sx,ug+rw --delete #{exclude_option} #{site_path} #{host}:#{path}"

        Open3.popen3( cmd ) do |stdin, stdout, stderr|
          stdin.close
          threads = []
          threads << Thread.new(stdout) do |i|
            while ( ! i.eof? )
              line = i.readline
              case line[0,9]
              when '<f.sT....'
                $LOG.info " updating #{line[10..-1]}" if $LOG.info?
              when 'cd+++++++'
                $LOG.info " creating #{line[10..-1]}" if $LOG.info?
              when '<f+++++++'
                $LOG.info " adding #{line[10..-1]}" if $LOG.info?
              when '<f..T....'
                # ignoring unchanged files
                $LOG.debug " no change to #{line[10..-1]}" if $LOG.debug?
              else
                $LOG.info line if $LOG.info
              end
            end
          end
          threads << Thread.new(stderr) do |i|
            while ( ! i.eof? )
              line = i.readline
              $LOG.info line if $LOG.info?
            end
          end
          threads.each{|t|t.join}
        end
      end
    end
  end
end

Awestruct::Deployers.instance[ :rsync ] = Awestruct::Deploy::RSyncDeploy

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
awestruct-0.5.4.beta1 lib/awestruct/deploy/rsync_deploy.rb
awestruct-0.5.3 lib/awestruct/deploy/rsync_deploy.rb
awestruct-0.5.2.1 lib/awestruct/deploy/rsync_deploy.rb
awestruct-0.5.2 lib/awestruct/deploy/rsync_deploy.rb
awestruct-0.5.1 lib/awestruct/deploy/rsync_deploy.rb
awestruct-0.5.1a lib/awestruct/deploy/rsync_deploy.rb
awestruct-0.5.0 lib/awestruct/deploy/rsync_deploy.rb
awestruct-0.5.0.cr lib/awestruct/deploy/rsync_deploy.rb