quicksync 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +20 -0
- data/.project +15 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +20 -0
- data/README.md +5 -0
- data/README.rdoc +19 -0
- data/Rakefile +10 -0
- data/bin/quicksync +8 -0
- data/config/.quicksync_config +25 -0
- data/lib/core_ext.rb +19 -0
- data/lib/quicksync.rb +19 -0
- data/lib/quicksync/cli.rb +69 -0
- data/lib/quicksync/logger.rb +158 -0
- data/lib/quicksync/rsync.rb +159 -0
- data/lib/quicksync/version.rb +3 -0
- data/quicksync.gemspec +33 -0
- data/test/helper.rb +18 -0
- data/test/test_quicksync.rb +33 -0
- metadata +243 -0
data/.document
ADDED
data/.gitignore
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
/vendor
|
19
|
+
vendor/bundle/ruby/1.9.1/
|
20
|
+
/pkg
|
data/.project
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<projectDescription>
|
3
|
+
<name>quicksync</name>
|
4
|
+
<comment></comment>
|
5
|
+
<projects>
|
6
|
+
</projects>
|
7
|
+
<buildSpec>
|
8
|
+
</buildSpec>
|
9
|
+
<natures>
|
10
|
+
<nature>com.aptana.ruby.core.rubynature</nature>
|
11
|
+
<nature>com.aptana.editor.php.phpNature</nature>
|
12
|
+
<nature>org.radrails.rails.core.railsnature</nature>
|
13
|
+
<nature>com.aptana.projects.webnature</nature>
|
14
|
+
</natures>
|
15
|
+
</projectDescription>
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 ShaunCollopy
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= quicksync
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to quicksync
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
9
|
+
* Fork the project.
|
10
|
+
* Start a feature/bugfix branch.
|
11
|
+
* Commit and push until you are happy with your contribution.
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2012 ShaunCollopy. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
data/bin/quicksync
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
$default_options =
|
2
|
+
{
|
3
|
+
:run_method => :execute,
|
4
|
+
:settings => {
|
5
|
+
:ssh_app => "rsh",
|
6
|
+
:rsync_app => "rsync",
|
7
|
+
:log_file => "",
|
8
|
+
:verbose => true,
|
9
|
+
:silent => false,
|
10
|
+
},
|
11
|
+
:from => {
|
12
|
+
:host => "local",
|
13
|
+
:user => "",
|
14
|
+
:dir => "/users/shaun/Dropbox/dtg/development/mgm-sugarcrm/data",
|
15
|
+
},
|
16
|
+
:to => {
|
17
|
+
:host => "dev.crm.mgmwireless.com",
|
18
|
+
:user => "sugarcrm",
|
19
|
+
:dir => "/inetpub/wwwroot/SugarCRM-main/dev/current/data",
|
20
|
+
},
|
21
|
+
:exclude => %w(.DS_Store .log .csv mytest.txt),
|
22
|
+
:include => %w(),
|
23
|
+
:copy_options => %w(progress stats times perms compress dry-run),
|
24
|
+
}
|
25
|
+
|
data/lib/core_ext.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# extensions to ruby core classes
|
2
|
+
|
3
|
+
String.class_eval do
|
4
|
+
def blank?
|
5
|
+
self.nil? || self.empty?
|
6
|
+
end
|
7
|
+
|
8
|
+
def to_bool
|
9
|
+
return true if self == true || self =~ (/\A(true|t|yes|y|1)\Z/i)
|
10
|
+
return false if self == false || self.blank? || self =~ (/\A(false|f|no|n|0)\Z/i)
|
11
|
+
raise ArgumentError.new("invalid value for Boolean: \"#{self}\"")
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
def blank?(var)
|
18
|
+
var.nil? || var.empty?
|
19
|
+
end
|
data/lib/quicksync.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require "core_ext"
|
2
|
+
require "quicksync/version"
|
3
|
+
require "quicksync/logger"
|
4
|
+
require 'quicksync/rsync'
|
5
|
+
require 'quicksync/cli'
|
6
|
+
require 'etc'
|
7
|
+
|
8
|
+
search_paths = [Etc.getpwuid.dir, File.join(Pathname.new(File.dirname(__FILE__)).parent,"config")]
|
9
|
+
file_name = ".quicksync_config"
|
10
|
+
config_file = ""
|
11
|
+
search_paths.each { |p|
|
12
|
+
if File.exists?("#{p}/#{file_name}")
|
13
|
+
config_file = "#{p}/#{file_name}"
|
14
|
+
break
|
15
|
+
end
|
16
|
+
}
|
17
|
+
|
18
|
+
|
19
|
+
load "#{config_file}"
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module QuickSync
|
2
|
+
class CLI
|
3
|
+
|
4
|
+
require 'highline'
|
5
|
+
|
6
|
+
def self.run
|
7
|
+
|
8
|
+
$logger.debug "CLI.run: function called"
|
9
|
+
qsync = QuickSync::RSync.new
|
10
|
+
config = $default_options
|
11
|
+
|
12
|
+
from = {}
|
13
|
+
to = {}
|
14
|
+
options={}
|
15
|
+
settings = {}
|
16
|
+
copy_strategy = :push_to;
|
17
|
+
|
18
|
+
ui.choose do |menu|
|
19
|
+
menu.prompt = "Copy strategy? "
|
20
|
+
copy_strategy = menu.choices(:pull_from, :push_to)
|
21
|
+
end
|
22
|
+
from[:dir] = ui.ask("from[:dir]? ") { |q| q.default = config[:from][:dir] }
|
23
|
+
from[:host] = ui.ask("from[:host]? ") { |q| q.default = config[:from][:host] }
|
24
|
+
from[:user] = ui.ask("from[:user]? ") { |q| q.default = config[:from][:user] }
|
25
|
+
to[:dir] = ui.ask("to[:dir]? ") { |q| q.default = config[:to][:dir] }
|
26
|
+
to[:host] = ui.ask("to[:host]? ") { |q| q.default = config[:to][:host] }
|
27
|
+
to[:user] = ui.ask("to[:user]? ") { |q| q.default = config[:to][:user] }
|
28
|
+
options[:include] = ui.ask("includes? ", lambda { |str| str.split(/,\s*/) }) { |q| q.default = config[:include].join(',')}
|
29
|
+
options[:exclude] = ui.ask("excludes? ", lambda { |str| str.split(/,\s*/) }) { |q| q.default = config[:exclude].join(',') }
|
30
|
+
options[:copy_options] = ui.ask("copy options? ", lambda { |str| str.split(/,\s*/) }) { |q| q.default = config[:copy_options].join(',') }
|
31
|
+
|
32
|
+
config[:settings].each do |key, value|
|
33
|
+
settings[key.to_sym] = ui.ask("settings[#{key.to_s}]? ") { |q| q.default = "#{value}" }
|
34
|
+
end
|
35
|
+
options[:settings] = settings
|
36
|
+
|
37
|
+
$logger.debug "CLI.run from=#{from}"
|
38
|
+
$logger.debug "CLI.run to=#{to}"
|
39
|
+
$logger.debug "CLI.run copy_options=#{options[:copy_options]}"
|
40
|
+
$logger.debug "CLI.run include=#{options[:include]}"
|
41
|
+
$logger.debug "CLI.run exclude=#{options[:exclude]}"
|
42
|
+
$logger.debug "CLI.run settings=#{options[:settings]}"
|
43
|
+
|
44
|
+
qs = QuickSync::RSync.new
|
45
|
+
cmd = qs.pull_from(from,to,options)
|
46
|
+
$logger.important "CLI.run: pull_from cmd=#{cmd}"
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.ui
|
53
|
+
@ui ||= HighLine.new
|
54
|
+
end
|
55
|
+
|
56
|
+
def env_var(var)
|
57
|
+
if ! ENV[var].nil? && ! ENV[var].empty?
|
58
|
+
return ENV[var]
|
59
|
+
else
|
60
|
+
return ""
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def env_var_bool(var)
|
65
|
+
return to_boolean(ENV[var])
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
@@ -0,0 +1,158 @@
|
|
1
|
+
module QuickSync
|
2
|
+
|
3
|
+
def self.Logger
|
4
|
+
@logger ||= QuickSync::Logger.new(:output => STDOUT)
|
5
|
+
end
|
6
|
+
|
7
|
+
class Logger #:nodoc:
|
8
|
+
attr_accessor :level, :device, :disable_formatters
|
9
|
+
|
10
|
+
IMPORTANT = 0
|
11
|
+
INFO = 1
|
12
|
+
DEBUG = 2
|
13
|
+
TRACE = 3
|
14
|
+
|
15
|
+
MAX_LEVEL = 3
|
16
|
+
|
17
|
+
COLORS = {
|
18
|
+
:none => "0",
|
19
|
+
:black => "30",
|
20
|
+
:red => "31",
|
21
|
+
:green => "32",
|
22
|
+
:yellow => "33",
|
23
|
+
:blue => "34",
|
24
|
+
:magenta => "35",
|
25
|
+
:cyan => "36",
|
26
|
+
:white => "37"
|
27
|
+
}
|
28
|
+
|
29
|
+
STYLES = {
|
30
|
+
:bright => 1,
|
31
|
+
:dim => 2,
|
32
|
+
:underscore => 4,
|
33
|
+
:blink => 5,
|
34
|
+
:reverse => 7,
|
35
|
+
:hidden => 8
|
36
|
+
}
|
37
|
+
|
38
|
+
# Set up default formatters
|
39
|
+
@formatters = [
|
40
|
+
# TRACE
|
41
|
+
{ :match => /command finished/, :color => :white, :style => :dim, :level => 3, :priority => -10 },
|
42
|
+
{ :match => /executing locally/, :color => :yellow, :level => 3, :priority => -20 },
|
43
|
+
|
44
|
+
# DEBUG
|
45
|
+
{ :match => /executing `.*/, :color => :green, :level => 2, :priority => -10, :timestamp => true },
|
46
|
+
{ :match => /.*/, :color => :yellow, :level => 2, :priority => -30 },
|
47
|
+
|
48
|
+
# INFO
|
49
|
+
{ :match => /.*out\] (fatal:|ERROR:).*/, :color => :red, :level => 1, :priority => -10 },
|
50
|
+
{ :match => /Permission denied/, :color => :red, :level => 1, :priority => -20 },
|
51
|
+
{ :match => /sh: .+: command not found/, :color => :magenta, :level => 1, :priority => -30 },
|
52
|
+
|
53
|
+
# IMPORTANT
|
54
|
+
{ :match => /^err ::/, :color => :red, :level => 0, :priority => -10 },
|
55
|
+
{ :match => /.*/, :color => :blue, :level => 0, :priority => -20 }
|
56
|
+
]
|
57
|
+
|
58
|
+
class << self
|
59
|
+
def add_formatter(options) #:nodoc:
|
60
|
+
@formatters.push(options)
|
61
|
+
@sorted_formatters = nil
|
62
|
+
end
|
63
|
+
|
64
|
+
def sorted_formatters
|
65
|
+
# Sort matchers in reverse order so we can break if we found a match.
|
66
|
+
@sorted_formatters ||= @formatters.sort_by { |i| -(i[:priority] || i[:prio] || 0) }
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def initialize(options={})
|
71
|
+
output = options[:output] || $stderr
|
72
|
+
if output.respond_to?(:puts)
|
73
|
+
@device = output
|
74
|
+
else
|
75
|
+
@device = File.open(output.to_str, "a")
|
76
|
+
@needs_close = true
|
77
|
+
end
|
78
|
+
|
79
|
+
@options = options
|
80
|
+
@level = options[:level] || 0
|
81
|
+
@disable_formatters = options[:disable_formatters]
|
82
|
+
end
|
83
|
+
|
84
|
+
def close
|
85
|
+
device.close if @needs_close
|
86
|
+
end
|
87
|
+
|
88
|
+
def log(level, message, line_prefix=nil)
|
89
|
+
if level <= self.level
|
90
|
+
# Only format output if device is a TTY or formatters are not disabled
|
91
|
+
if device.tty? && !@disable_formatters
|
92
|
+
color = :none
|
93
|
+
style = nil
|
94
|
+
|
95
|
+
Logger.sorted_formatters.each do |formatter|
|
96
|
+
if (formatter[:level] == level || formatter[:level].nil?)
|
97
|
+
if message =~ formatter[:match] || line_prefix =~ formatter[:match]
|
98
|
+
color = formatter[:color] if formatter[:color]
|
99
|
+
style = formatter[:style] || formatter[:attribute] # (support original cap colors)
|
100
|
+
message.gsub!(formatter[:match], formatter[:replace]) if formatter[:replace]
|
101
|
+
message = formatter[:prepend] + message unless formatter[:prepend].nil?
|
102
|
+
message = message + formatter[:append] unless formatter[:append].nil?
|
103
|
+
message = Time.now.strftime('%Y-%m-%d %T') + ' ' + message if formatter[:timestamp]
|
104
|
+
break unless formatter[:replace]
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
if color == :hide
|
110
|
+
# Don't do anything if color is set to :hide
|
111
|
+
return false
|
112
|
+
end
|
113
|
+
|
114
|
+
term_color = COLORS[color]
|
115
|
+
term_style = STYLES[style]
|
116
|
+
|
117
|
+
# Don't format message if no color or style
|
118
|
+
unless color == :none and style.nil?
|
119
|
+
unless line_prefix.nil?
|
120
|
+
line_prefix = format(line_prefix, term_color, term_style, nil)
|
121
|
+
end
|
122
|
+
message = format(message, term_color, term_style)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
indent = "%*s" % [MAX_LEVEL, "*" * (MAX_LEVEL - level)]
|
127
|
+
(RUBY_VERSION >= "1.9" ? message.lines : message).each do |line|
|
128
|
+
if line_prefix
|
129
|
+
device.puts "#{indent} [#{line_prefix}] #{line.strip}\n"
|
130
|
+
else
|
131
|
+
device.puts "#{indent} #{line.strip}\n"
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def important(message, line_prefix=nil)
|
138
|
+
log(IMPORTANT, message, line_prefix)
|
139
|
+
end
|
140
|
+
|
141
|
+
def info(message, line_prefix=nil)
|
142
|
+
log(INFO, message, line_prefix)
|
143
|
+
end
|
144
|
+
|
145
|
+
def debug(message, line_prefix=nil)
|
146
|
+
log(DEBUG, message, line_prefix)
|
147
|
+
end
|
148
|
+
|
149
|
+
def trace(message, line_prefix=nil)
|
150
|
+
log(TRACE, message, line_prefix)
|
151
|
+
end
|
152
|
+
|
153
|
+
def format(message, color, style, nl = "\n")
|
154
|
+
style = "#{style};" if style
|
155
|
+
"\e[#{style}#{color}m" + message.to_s.strip + "\e[0m#{nl}"
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
@@ -0,0 +1,159 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
module QuickSync
|
4
|
+
class RSync
|
5
|
+
|
6
|
+
attr_accessor :settings, :from, :to, :exclude, :include, :copy_options, :run_method
|
7
|
+
attr_reader :default_options, :logger
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@logger = QuickSync.Logger
|
11
|
+
@logger.level = QuickSync::Logger::TRACE
|
12
|
+
@default_options = $default_options
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
def copy_options_to_s
|
17
|
+
return copy_options.map{ |o| "--#{o}"}.join(' ')
|
18
|
+
end
|
19
|
+
|
20
|
+
def include_to_s
|
21
|
+
if include.any?
|
22
|
+
return include.map { |i| "--include=\"#{i}\"" }.join(' ')
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def exclude_to_s
|
27
|
+
if exclude.any?
|
28
|
+
return exclude.map { |e| "--exclude=\"#{e}\"" }.join(' ')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def default_options
|
33
|
+
@default_options
|
34
|
+
end
|
35
|
+
|
36
|
+
def parse_options(from_v,to_v,options)
|
37
|
+
|
38
|
+
if from_v.nil? || from_v.empty?
|
39
|
+
raise ArgumentError, ":from can not be empty"
|
40
|
+
end
|
41
|
+
|
42
|
+
if to_v.nil? || to_v.empty?
|
43
|
+
raise ArgumentError, ":to can not be empty"
|
44
|
+
end
|
45
|
+
|
46
|
+
logger.debug "QuickSync.parse_options: from class=#{from_v.class}"
|
47
|
+
|
48
|
+
@from = from_v == String ? default_options[:from].merge({:dir=>from_v}): default_options[:from].merge(from_v)
|
49
|
+
@to = to_v == String ? default_options[:to].merge({:dir=>to_v}): default_options[:to].merge(to_v)
|
50
|
+
@exclude = options.length > 0 && ! options[:exclude].nil? ? options[:exclude]: default_options[:exclude]
|
51
|
+
@include = options.length > 0 && ! options[:include].nil? ? options[:include]: default_options[:include]
|
52
|
+
@copy_options = options.length > 0 && ! options[:copy_options].nil? ? default_options[:copy_options].concat(options[:copy_options]).uniq!: default_options[:copy_options]
|
53
|
+
@settings = options.length > 0 && ! options[:settings].nil? ? default_options[:settings].merge(options[:settings]): default_options[:settings]
|
54
|
+
@run_method = default_options[:run_method]
|
55
|
+
|
56
|
+
logger.debug "QuickSync.parse_options:"
|
57
|
+
logger.debug " from=#{from}"
|
58
|
+
logger.debug " to=#{to}"
|
59
|
+
logger.debug " exclude=#{exclude}"
|
60
|
+
logger.debug " include=#{include}"
|
61
|
+
logger.debug " copy_options=#{copy_options}"
|
62
|
+
logger.debug " settings=#{settings}"
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
def pull_from(from,to,options={})
|
67
|
+
parse_options(from,to,options)
|
68
|
+
# if from[:dir] does not exist then abort as there is nothing to do
|
69
|
+
cmd = generate_cmd
|
70
|
+
logger.info "RSync.pull_from: run_method=#{run_method}"
|
71
|
+
if run_method == :execute
|
72
|
+
# run the actual command before returning it
|
73
|
+
logger.info "RSync.pull_from: about to execute command"
|
74
|
+
system(cmd)
|
75
|
+
|
76
|
+
end
|
77
|
+
logger.info "quicksync command:\n #{cmd}"
|
78
|
+
return cmd
|
79
|
+
end
|
80
|
+
|
81
|
+
def push_to(from,to,options={})
|
82
|
+
parse_options(from,to,options)
|
83
|
+
# if from[:dir] does not exist then abort as there is nothing to do
|
84
|
+
cmd = generate_cmd
|
85
|
+
logger.info "RSync.push_to: run_method=#{run_method}"
|
86
|
+
if run_method == :execute
|
87
|
+
# run the actual command before returning it
|
88
|
+
logger.info "RSync.push_to: about to execute command"
|
89
|
+
system(cmd)
|
90
|
+
|
91
|
+
end
|
92
|
+
logger.info "quicksync command:\n #{cmd}"
|
93
|
+
return cmd
|
94
|
+
end
|
95
|
+
|
96
|
+
def run_on
|
97
|
+
if is_local(from[:host]) && is_local(to[:host])
|
98
|
+
return :local
|
99
|
+
elsif is_local(from[:host]) && is_remote(to[:host])
|
100
|
+
return :local
|
101
|
+
elsif is_remote(from[:host]) && is_remote(to[:host])
|
102
|
+
return :remote
|
103
|
+
elsif is_remote(from[:host]) && is_local(to[:host])
|
104
|
+
return :remote
|
105
|
+
else
|
106
|
+
return :local
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def is_local(the_host)
|
111
|
+
if ! the_host.nil? && ! the_host.empty? && the_host.include?("local")
|
112
|
+
return true
|
113
|
+
else
|
114
|
+
return false
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def is_remote(the_host)
|
119
|
+
if ! the_host.nil? && ! the_host.empty? && ! the_host.include?("local")
|
120
|
+
return true
|
121
|
+
else
|
122
|
+
return false
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def from_to_s
|
127
|
+
|
128
|
+
logger.debug "RSync.from_to_s: from=#{from}"
|
129
|
+
if ! from[:host].nil? && ! from[:host].empty? && ! from[:host].include?("local")
|
130
|
+
return from[:user]+"@"+from[:host] + ":" + from[:dir]
|
131
|
+
else
|
132
|
+
return from[:dir]
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def to_to_s
|
137
|
+
val = to[:dir]
|
138
|
+
if ! to[:host].nil? && ! to[:host].empty? && ! to[:host].include?("local")
|
139
|
+
val = to[:user]+"@"+to[:host] + ":" + to[:dir]
|
140
|
+
else
|
141
|
+
return to[:dir]
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
|
146
|
+
def generate_cmd
|
147
|
+
logger.debug "QuickSync.generated_cmd: method called"
|
148
|
+
|
149
|
+
cmd = "#{settings[:rsync_app]} #{copy_options_to_s}"
|
150
|
+
cmd << " #{include_to_s}" if !include.nil? && include.any?
|
151
|
+
cmd << " #{exclude_to_s}" if !exclude.nil? && exclude.any?
|
152
|
+
cmd << " #{from_to_s}/ #{to_to_s}"
|
153
|
+
|
154
|
+
return cmd
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
158
|
+
|
159
|
+
end
|
data/quicksync.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'quicksync/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "quicksync"
|
8
|
+
gem.version = QuickSync::VERSION
|
9
|
+
gem.authors = ["ShaunCollopy"]
|
10
|
+
gem.email = ["shaun@shauncollopy.com"]
|
11
|
+
gem.description = %q{QuickSync gem description 1}
|
12
|
+
gem.summary = %q{QuickSync gem summary 2}
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
gem.add_development_dependency "rspec", "~> 2.6"
|
20
|
+
gem.add_development_dependency "test", "~> 0.3.1"
|
21
|
+
gem.add_development_dependency "shoulda", "~> 3.3.2"
|
22
|
+
gem.add_development_dependency "shoulda-context", "~> 1.0.1"
|
23
|
+
gem.add_development_dependency "bundler", "~> 1.2.2"
|
24
|
+
gem.add_development_dependency "logger", "~> 1.2.8"
|
25
|
+
gem.add_development_dependency "rake"
|
26
|
+
gem.add_development_dependency "highline"
|
27
|
+
gem.add_development_dependency "etc"
|
28
|
+
|
29
|
+
gem.add_dependency "logger", "~> 1.2.8"
|
30
|
+
gem.add_dependency "highline"
|
31
|
+
|
32
|
+
|
33
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda'
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
require 'quicksync'
|
16
|
+
|
17
|
+
class Test::Unit::TestCase
|
18
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'quicksync'
|
3
|
+
|
4
|
+
class TestQuickSync < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
$logger = QuickSync.Logger
|
7
|
+
$logger.level = QuickSync::Logger::INFO
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
def teardown
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_rsync
|
16
|
+
|
17
|
+
assert_nothing_raised do
|
18
|
+
|
19
|
+
options = $default_options
|
20
|
+
qs = QuickSync::RSync.new
|
21
|
+
|
22
|
+
from = options[:from]
|
23
|
+
to = options[:to]
|
24
|
+
cmd = qs.pull_from(from,to,options)
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
metadata
ADDED
@@ -0,0 +1,243 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: quicksync
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.6
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- ShaunCollopy
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-29 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '2.6'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '2.6'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: test
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 0.3.1
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.3.1
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: shoulda
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 3.3.2
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.3.2
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: shoulda-context
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.0.1
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.0.1
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: bundler
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 1.2.2
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 1.2.2
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: logger
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ~>
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 1.2.8
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 1.2.8
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: rake
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: highline
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
type: :development
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
- !ruby/object:Gem::Dependency
|
143
|
+
name: etc
|
144
|
+
requirement: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ! '>='
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
type: :development
|
151
|
+
prerelease: false
|
152
|
+
version_requirements: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ! '>='
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
- !ruby/object:Gem::Dependency
|
159
|
+
name: logger
|
160
|
+
requirement: !ruby/object:Gem::Requirement
|
161
|
+
none: false
|
162
|
+
requirements:
|
163
|
+
- - ~>
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: 1.2.8
|
166
|
+
type: :runtime
|
167
|
+
prerelease: false
|
168
|
+
version_requirements: !ruby/object:Gem::Requirement
|
169
|
+
none: false
|
170
|
+
requirements:
|
171
|
+
- - ~>
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: 1.2.8
|
174
|
+
- !ruby/object:Gem::Dependency
|
175
|
+
name: highline
|
176
|
+
requirement: !ruby/object:Gem::Requirement
|
177
|
+
none: false
|
178
|
+
requirements:
|
179
|
+
- - ! '>='
|
180
|
+
- !ruby/object:Gem::Version
|
181
|
+
version: '0'
|
182
|
+
type: :runtime
|
183
|
+
prerelease: false
|
184
|
+
version_requirements: !ruby/object:Gem::Requirement
|
185
|
+
none: false
|
186
|
+
requirements:
|
187
|
+
- - ! '>='
|
188
|
+
- !ruby/object:Gem::Version
|
189
|
+
version: '0'
|
190
|
+
description: QuickSync gem description 1
|
191
|
+
email:
|
192
|
+
- shaun@shauncollopy.com
|
193
|
+
executables:
|
194
|
+
- quicksync
|
195
|
+
extensions: []
|
196
|
+
extra_rdoc_files: []
|
197
|
+
files:
|
198
|
+
- .document
|
199
|
+
- .gitignore
|
200
|
+
- .project
|
201
|
+
- Gemfile
|
202
|
+
- LICENSE.txt
|
203
|
+
- README.md
|
204
|
+
- README.rdoc
|
205
|
+
- Rakefile
|
206
|
+
- bin/quicksync
|
207
|
+
- config/.quicksync_config
|
208
|
+
- lib/core_ext.rb
|
209
|
+
- lib/quicksync.rb
|
210
|
+
- lib/quicksync/cli.rb
|
211
|
+
- lib/quicksync/logger.rb
|
212
|
+
- lib/quicksync/rsync.rb
|
213
|
+
- lib/quicksync/version.rb
|
214
|
+
- quicksync.gemspec
|
215
|
+
- test/helper.rb
|
216
|
+
- test/test_quicksync.rb
|
217
|
+
homepage: ''
|
218
|
+
licenses: []
|
219
|
+
post_install_message:
|
220
|
+
rdoc_options: []
|
221
|
+
require_paths:
|
222
|
+
- lib
|
223
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
224
|
+
none: false
|
225
|
+
requirements:
|
226
|
+
- - ! '>='
|
227
|
+
- !ruby/object:Gem::Version
|
228
|
+
version: '0'
|
229
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
230
|
+
none: false
|
231
|
+
requirements:
|
232
|
+
- - ! '>='
|
233
|
+
- !ruby/object:Gem::Version
|
234
|
+
version: '0'
|
235
|
+
requirements: []
|
236
|
+
rubyforge_project:
|
237
|
+
rubygems_version: 1.8.24
|
238
|
+
signing_key:
|
239
|
+
specification_version: 3
|
240
|
+
summary: QuickSync gem summary 2
|
241
|
+
test_files:
|
242
|
+
- test/helper.rb
|
243
|
+
- test/test_quicksync.rb
|