Module: LSync

Defined in:
lib/lsync/error.rb,
lib/lsync.rb,
lib/lsync/run.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, ConnectionError, CopyController, Directory, DirectoryController, Error, EventTimer, Method, MinimalLogFormat, Script, ScriptError, Server, ServerController, Shell, ShellScriptError, TeeLogger, Timeout

Constant Summary collapse

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

Class Method Summary collapse

Class Method Details

.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/run.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_command(root, command, logger) ⇒ Object

Run a specific command and output the results to the given logger.



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/lsync/run.rb', line 47

def self.run_command(root, command, logger)
	Dir.chdir(root) do
		logger.info "Running #{command.inspect} in #{Dir.getwd.inspect}"

		process_result = RExec::Task.open(command) do |task|
			log_task(task, logger)
		end

		return process_result
	end
end

.run_remote_command(root, connection_command, command, logger) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/lsync/run.rb', line 59

def self.run_remote_command(root, connection_command, command, logger)
	logger.info "Running remote command #{command.inspect} in #{root}"
	
	process_result = RExec::Task.open(connection_command) do |connection|
		connection.puts(["cd", root].to_cmd)
		connection.puts((["exec"] + command).to_cmd)
		
		LSync::log_task(connection, logger)
	end
	
	return process_result
end

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



39
40
41
42
43
# File 'lib/lsync.rb', line 39

def self.run_script(options = {}, &block)
	script = LSync::Script.new(options, &block)
	
	script.run!
end