class Disloku::Tasks::NetSftpTask

Public Class Methods

new(input) click to toggle source
Calls superclass method Disloku::BaseTask::new
# File lib/disloku/tasks/NetSftpTask.rb, line 30
def initialize(input)
        super()
        @repository = getInputParam(input, :repository, Disloku::Repository)
        @options = getInputParam(input, :options, Config::Options)
        @directory = getInputParam(input, :directory, String)
        @files = getInputParam(input, :files, Array)
        @target = getInputParam(input, :target, Config::Target)
        @dirty = getInputParam(input, :dirty, Object)
end

Public Instance Methods

afterExecute() click to toggle source
# File lib/disloku/tasks/NetSftpTask.rb, line 108
def afterExecute()
end
beforeExecute() click to toggle source
# File lib/disloku/tasks/NetSftpTask.rb, line 40
def beforeExecute()
        if (@files.count == 0)
                CliAdapter.puts("Nothing to deploy for target [#{@target.name}]")
                return false
        end

        if (!@target.branchLock.nil?)
                branch = @repository.getBranchName()
                if (branch != @target.branchLock)
                        raise DislokuError.new("Target [#{@target.name}] is locked to branch #{@target.branchLock} but current branch is #{branch}", true)
                end
        end

        if (@dirty && !@target.allowDirty.nil? && !@target.allowDirty)
                raise DislokuError.new("Target does not allow deployments from dirty repositories", true)
        end

        CliAdapter.puts()
        CliAdapter.puts("Target [#{@target.name}]: #{@target.user}@#{@target.host}:#{@target.targetDir}")
        @files.each() do |file|
                puts(file)
        end

        return CliAdapter.queryYesNo("Continue with deployment?")
end
executeTask() click to toggle source
# File lib/disloku/tasks/NetSftpTask.rb, line 66
def executeTask()
        CliAdapter.puts("Doploying target [#{@target.name}]")

        Log.instance.scope([:default, :logfile]) do

                SessionManager.instance.get(@target.connection) do |sftp|
                        Log.instance.info("connection with [#{@target.name}] established")

                        sftp.upload!(@directory, @target.targetDir, { :ignoreMkdirError => true }) do |event, uploader, *args|
                                case event
                                        when :open then
                                                # args[0] : file metadata
                                                # "starting upload: #{args[0].local} -> #{args[0].remote} (#{args[0].size} bytes}"
                                                CliAdapter.print(".")
                                                Log.instance.info("#{args[0].local} -> #{args[0].remote} (#{args[0].size} bytes)")
                                end
                        end
                        CliAdapter.puts()

                        @files.each() do |file|
                                if (file.change.changeType == :deleted)
                                        path = file.getAbsoluteDstPath()
                                        Log.instance.info("deleting file #{path}")
                                        begin
                                                sftp.remove!(path)
                                                CliAdapter.print("x")
                                        rescue
                                                if (!@options.ignoreDeleteErrors)
                                                        Log.instance.fatal("unable to delete file #{path} - failing")
                                                        raise
                                                else
                                                        Log.instance.warn("unable to delete file #{path} (it probably doesn't exist)")
                                                end
                                        end
                                end
                        end
                end

        end

end