lsync 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,84 @@
1
+
2
+ require 'logger'
3
+ require 'fileutils'
4
+
5
+ require "open3"
6
+
7
+ LSYNC_TMP_DIRECTORY = "/tmp/lsync-#{Process.pid}"
8
+ FileUtils.mkdir_p(LSYNC_TMP_DIRECTORY)
9
+ FileUtils.chmod 0700, LSYNC_TMP_DIRECTORY
10
+ $logger = Logger.new "/tmp/remote-client.log"
11
+
12
+ $logger.info "Starting remote shell @ #{Time.now.to_s}"
13
+
14
+ def script_path(named)
15
+ File.join(LSYNC_TMP_DIRECTORY, "#{named}")
16
+ end
17
+
18
+ module RemoteMethods
19
+ def self.run_command(cmd)
20
+ $connection.send_object([:info, "Running #{cmd}..."])
21
+
22
+ cin, cout, cerr = Open3.popen3(cmd)
23
+ cin.close
24
+
25
+ pipes = [cout, cerr]
26
+
27
+ while pipes.size > 0
28
+ ready = IO.select(pipes)
29
+ $logger.info(ready.inspect)
30
+
31
+ ready[0].each do |pipe|
32
+ # Delete the pipe when it has become closed
33
+ if pipe.closed? || pipe.eof?
34
+ pipes.delete(pipe)
35
+ next
36
+ end
37
+
38
+ line = pipe.readline.chomp
39
+ mode = (pipe == cout ? :info : :error)
40
+
41
+ $logger.send(mode, line)
42
+ $connection.send_object([mode, line])
43
+ end
44
+ end
45
+
46
+ $logger.info "Done running command."
47
+ $connection.send_object(:done)
48
+ end
49
+
50
+ def self.run_script(name, code, arguments)
51
+ path = script_path(name)
52
+
53
+ File.open(path, "w") do |f|
54
+ f.write(code)
55
+ end
56
+
57
+ FileUtils.chmod 0755, path
58
+
59
+ run_command(path + " " + arguments)
60
+ end
61
+
62
+ def self.mkdir_p(path)
63
+ FileUtils.mkdir_p(path)
64
+ end
65
+
66
+ def self.set_working_dir(path)
67
+ Dir.chdir(path)
68
+ end
69
+ end
70
+
71
+ begin
72
+ $connection.send_object(:ready)
73
+
74
+ $connection.run do |message|
75
+ method = message.shift
76
+ $logger.info("Calling #{method}...")
77
+ result = RemoteMethods.send(method, *message)
78
+ end
79
+ rescue
80
+ $logger.error("Exception caught: #{$!}")
81
+ exit(1)
82
+ ensure
83
+ FileUtils.rm_rf(LSYNC_TMP_DIRECTORY)
84
+ end
@@ -0,0 +1,37 @@
1
+
2
+ module TeeHelper
3
+ def tee(*loggers)
4
+ return TeeLogger.new(self, *loggers)
5
+ end
6
+ end
7
+
8
+ class TeeLogger
9
+ def initialize(*loggers)
10
+ @loggers = Set.new(loggers.flatten.compact)
11
+ end
12
+
13
+ attr :loggers
14
+
15
+ def self.logger_methods
16
+ Set.new(Logger.instance_methods) - Set.new(Object.instance_methods + %w(tee))
17
+ end
18
+
19
+ logger_methods.each do |method|
20
+ define_method(method) do |*args|
21
+ @loggers.each { |l| l.send(method, *args) }
22
+ end
23
+ end
24
+
25
+ include TeeHelper
26
+ end
27
+
28
+ class Logger
29
+ include TeeHelper
30
+ end
31
+
32
+ class MinimalLogFormat
33
+ def call(severity, time, progname, msg)
34
+ "[#{severity.rjust(8)}] #{msg}\n"
35
+ end
36
+ end
37
+
@@ -0,0 +1,24 @@
1
+ # Copyright (c) 2007 Samuel Williams. Released under the GNU GPLv2.
2
+ #
3
+ # This program is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
15
+
16
+ module LSync
17
+ module VERSION #:nodoc:
18
+ MAJOR = 1
19
+ MINOR = 2
20
+ TINY = 1
21
+
22
+ STRING = [MAJOR, MINOR, TINY].join('.')
23
+ end
24
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lsync
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 2
8
+ - 1
9
+ version: 1.2.1
10
+ platform: ruby
11
+ authors:
12
+ - Samuel Williams
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-03-18 00:00:00 +13:00
18
+ default_executable: lsync
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: termios
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :runtime
31
+ version_requirements: *id001
32
+ - !ruby/object:Gem::Dependency
33
+ name: net-ssh
34
+ prerelease: false
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ segments:
40
+ - 0
41
+ version: "0"
42
+ type: :runtime
43
+ version_requirements: *id002
44
+ - !ruby/object:Gem::Dependency
45
+ name: ruleby
46
+ prerelease: false
47
+ requirement: &id003 !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ segments:
52
+ - 0
53
+ version: "0"
54
+ type: :runtime
55
+ version_requirements: *id003
56
+ - !ruby/object:Gem::Dependency
57
+ name: rexec
58
+ prerelease: false
59
+ requirement: &id004 !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ type: :runtime
67
+ version_requirements: *id004
68
+ description:
69
+ email: samuel.williams@oriontransfer.co.nz
70
+ executables:
71
+ - lsync
72
+ extensions: []
73
+
74
+ extra_rdoc_files: []
75
+
76
+ files:
77
+ - bin/lsync
78
+ - lib/lsync/action.rb
79
+ - lib/lsync/actions/darwin/disk
80
+ - lib/lsync/actions/darwin/terminal
81
+ - lib/lsync/actions/generic/prune
82
+ - lib/lsync/actions/generic/rotate
83
+ - lib/lsync/actions/linux/disk
84
+ - lib/lsync/actions/linux/terminal
85
+ - lib/lsync/backup_error.rb
86
+ - lib/lsync/backup_plan.rb
87
+ - lib/lsync/backup_script.rb
88
+ - lib/lsync/directory.rb
89
+ - lib/lsync/extensions.rb
90
+ - lib/lsync/lb.py
91
+ - lib/lsync/method.rb
92
+ - lib/lsync/password.rb
93
+ - lib/lsync/run.rb
94
+ - lib/lsync/server.rb
95
+ - lib/lsync/shell.rb
96
+ - lib/lsync/shell_client.rb
97
+ - lib/lsync/tee_logger.rb
98
+ - lib/lsync/version.rb
99
+ - lib/lsync.rb
100
+ has_rdoc: true
101
+ homepage: http://wiki.oriontransfer.org/?lsync
102
+ licenses: []
103
+
104
+ post_install_message:
105
+ rdoc_options: []
106
+
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ segments:
114
+ - 0
115
+ version: "0"
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ segments:
121
+ - 0
122
+ version: "0"
123
+ requirements: []
124
+
125
+ rubyforge_project:
126
+ rubygems_version: 1.3.6
127
+ signing_key:
128
+ specification_version: 2
129
+ summary: LSync is a tool for scripted synchronization and backups.
130
+ test_files: []
131
+