Module: LSync

Defined in:
lib/lsync/error.rb,
lib/lsync.rb,
lib/lsync/shell.rb,
lib/lsync/method.rb,
lib/lsync/script.rb,
lib/lsync/server.rb,
lib/lsync/version.rb,
lib/lsync/directory.rb,
lib/lsync/controller.rb,
lib/lsync/shells/ssh.rb,
lib/lsync/tee_logger.rb,
lib/lsync/event_timer.rb,
lib/lsync/event_handler.rb,
lib/lsync/methods/rsync.rb

Overview

Copyright © 2007, 2011 Samuel G. D. Williams. <www.oriontransfer.co.nz>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Defined Under Namespace

Modules: EventHandler, Methods, Shells, TeeHelper, VERSION Classes: AbsolutePathError, BackupMethodError, BasicController, CommandFailure, ConnectionError, CopyController, Directory, DirectoryController, Error, EventTimer, Method, MinimalLogFormat, Script, ScriptError, Server, ServerController, Shell, TeeLogger, Timeout

Constant Summary collapse

CLIENT_CODE =
(Pathname.new(__FILE__).dirname + "client.rb").read

Class Method Summary collapse

Class Method Details

.log_error(error, logger) ⇒ Object



46
47
48
49
50
51
# File 'lib/lsync/controller.rb', line 46

def self.log_error(error, logger)
  logger.error "Error #{error.class.name}: #{error}"
  error.backtrace.each do |where|
    logger.error "\t#{where}"
  end
end

.log_task(task, logger) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/lsync/controller.rb', line 25

def self.log_task(task, logger)
  pipes = [task.output, task.error]

  while pipes.size > 0
    result = IO.select(pipes)

    result[0].each do |pipe|
      if pipe.closed? || pipe.eof?
        pipes.delete(pipe)
        next
      end

      if pipe == task.output
        logger.info pipe.readline.chomp
      elsif pipe == task.error
        logger.error pipe.readline.chomp
      end
    end
  end
end

.run_script(options = {}, &block) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/lsync.rb', line 39

def self.run_script(options = {}, &block)
  script = LSync::Script.new(options, &block)
  
  script.on(:failure) do |error|
    LSync::log_error(error, logger)
  end
  
  script.run!
end