quicksync 0.0.7 → 0.0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/config/.quicksync_config +10 -15
- data/config/quicksync.yaml +25 -0
- data/lib/core_ext.rb +9 -2
- data/lib/quicksync.rb +22 -10
- data/lib/quicksync/rsync.rb +94 -112
- data/lib/quicksync/version.rb +1 -1
- data/test/test_quicksync.rb +35 -11
- metadata +4 -3
data/config/.quicksync_config
CHANGED
@@ -1,25 +1,20 @@
|
|
1
1
|
$default_options =
|
2
2
|
{
|
3
|
-
|
3
|
+
:run_method => :generate,
|
4
|
+
:src => "/users/shaun/Dropbox/dtg/development/mgm-sugarcrm/custom",
|
5
|
+
:dest => "/inetpub/wwwroot/SugarCRM-main/dev/current/custom",
|
6
|
+
:host => "dev.crm.mgmwireless.com",
|
7
|
+
:user => "sugarcrm",
|
8
|
+
:exclude => %w(.DS_Store .log),
|
9
|
+
:include => %w(),
|
10
|
+
:copy_options => %w(recursive stats compress),
|
4
11
|
:settings => {
|
5
12
|
:ssh_app => "rsh",
|
6
13
|
:rsync_app => "rsync",
|
7
14
|
:log_file => "",
|
8
|
-
:verbose =>
|
15
|
+
:verbose => false,
|
9
16
|
:silent => false,
|
10
17
|
},
|
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
18
|
}
|
25
19
|
|
20
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
:run_method: :generate
|
2
|
+
:src: /users/shaun/Dropbox/dtg/development/mgm-sugarcrm/custom
|
3
|
+
:dest: /inetpub/wwwroot/SugarCRM-main/dev/current/custom
|
4
|
+
:host: dev.crm.mgmwireless.com
|
5
|
+
:user: sugarcrm
|
6
|
+
:exclude:
|
7
|
+
- DS_Store
|
8
|
+
- .log
|
9
|
+
:include:
|
10
|
+
:copy_options:
|
11
|
+
- recursive
|
12
|
+
- stat
|
13
|
+
- compress
|
14
|
+
:settings:
|
15
|
+
:ssh_app: rsh
|
16
|
+
:rsync_app: rsync
|
17
|
+
:log_file: ~
|
18
|
+
:verbose: false
|
19
|
+
:silent: false
|
20
|
+
:sync_types:
|
21
|
+
:pull_from: :local
|
22
|
+
:push_to: :local
|
23
|
+
:copy_local: :local
|
24
|
+
:copy_remote: :remote
|
25
|
+
|
data/lib/core_ext.rb
CHANGED
@@ -10,8 +10,15 @@ String.class_eval do
|
|
10
10
|
return false if self == false || self.blank? || self =~ (/\A(false|f|no|n|0)\Z/i)
|
11
11
|
raise ArgumentError.new("invalid value for Boolean: \"#{self}\"")
|
12
12
|
end
|
13
|
-
|
14
|
-
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
Hash.class_eval do
|
17
|
+
def symbolize_keys
|
18
|
+
self.keys.each do |key|
|
19
|
+
self[(key.to_sym rescue key) || key] = self.delete(key)
|
20
|
+
end
|
21
|
+
end
|
15
22
|
end
|
16
23
|
|
17
24
|
def blank?(var)
|
data/lib/quicksync.rb
CHANGED
@@ -5,15 +5,27 @@ require 'quicksync/rsync'
|
|
5
5
|
require 'quicksync/cli'
|
6
6
|
require 'etc'
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
if File.exists?("#{p}/#{file_name}")
|
13
|
-
config_file = "#{p}/#{file_name}"
|
14
|
-
break
|
8
|
+
module QuickSync
|
9
|
+
|
10
|
+
def self.Config
|
11
|
+
@config ||= QuickSync.LoadConfig
|
15
12
|
end
|
16
|
-
|
17
|
-
|
13
|
+
|
14
|
+
def self.LoadConfig
|
15
|
+
|
16
|
+
home_path = Etc.getpwuid.dir
|
17
|
+
gem_path = File.join(Pathname.new(File.dirname(__FILE__)).parent,"config")
|
18
|
+
search_paths = [home_path, gem_path]
|
19
|
+
yaml_filename = "quicksync.yaml"
|
20
|
+
yaml_file= "#{gem_path}/#{yaml_filename}"
|
21
|
+
search_paths.each { |p|
|
22
|
+
file = "#{p}/#{yaml_filename}"
|
23
|
+
if File.exists?(file)
|
24
|
+
yaml_file = file
|
25
|
+
break
|
26
|
+
end
|
27
|
+
}
|
28
|
+
return YAML::load( File.open( yaml_file ) )
|
29
|
+
end
|
30
|
+
end
|
18
31
|
|
19
|
-
load "#{config_file}"
|
data/lib/quicksync/rsync.rb
CHANGED
@@ -1,159 +1,141 @@
|
|
1
|
-
|
2
|
-
|
3
1
|
module QuickSync
|
4
2
|
class RSync
|
5
3
|
|
6
|
-
attr_accessor :
|
7
|
-
attr_reader :default_options, :logger
|
8
|
-
|
4
|
+
attr_accessor :src, :dest, :user, :host, :exclude, :include, :copy_options, :settings, :run_method, :run_on, :sync_types
|
5
|
+
attr_reader :default_options, :logger, :sync_type, :config
|
9
6
|
def initialize
|
10
7
|
@logger = QuickSync.Logger
|
11
8
|
@logger.level = QuickSync::Logger::INFO
|
12
|
-
@default_options =
|
13
|
-
|
9
|
+
@default_options = QuickSync.Config
|
10
|
+
@sync_types = @default_options[:sync_types]
|
11
|
+
|
14
12
|
end
|
15
13
|
|
16
|
-
def
|
17
|
-
|
14
|
+
def set_sync_type(sync_type)
|
15
|
+
puts "sync_type value set to #{sync_type.to_sym}"
|
16
|
+
@sync_type = sync_type.to_sym
|
18
17
|
end
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
19
|
+
|
20
|
+
def src_fully_qualified
|
21
|
+
return src
|
24
22
|
end
|
25
|
-
|
26
|
-
def
|
27
|
-
if
|
28
|
-
return
|
23
|
+
|
24
|
+
def dest_fully_qualified
|
25
|
+
if sync_type == :pull_from || sync_type == :push_to
|
26
|
+
return "#{user}@#{host}:#{dest}"
|
27
|
+
else
|
28
|
+
return "#{dest}"
|
29
29
|
end
|
30
30
|
end
|
31
|
-
|
32
|
-
def
|
33
|
-
|
31
|
+
|
32
|
+
def run_on
|
33
|
+
# logger.debug "run_on function called, :sync_type=#{sync_type}, sync_types[sync_type]=#{sync_types[sync_type]}"
|
34
|
+
return sync_types[sync_type]
|
34
35
|
end
|
35
36
|
|
36
|
-
def
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
end
|
37
|
+
def pull_from(src,dest,options={})
|
38
|
+
set_sync_type(__method__)
|
39
|
+
return sync(src,dest,options)
|
40
|
+
end
|
41
41
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
logger.debug "QuickSync.parse_options: from class=#{from_v.class}"
|
42
|
+
def push_to(src,dest,options={})
|
43
|
+
set_sync_type(__method__)
|
44
|
+
return sync(src,dest,options)
|
45
|
+
end
|
47
46
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
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}"
|
47
|
+
def copy_local(src,dest,options={})
|
48
|
+
set_sync_type(__method__)
|
49
|
+
return sync(src,dest,options)
|
50
|
+
end
|
63
51
|
|
52
|
+
def copy_remote(src,dest,options={})
|
53
|
+
set_sync_type(__method__)
|
54
|
+
return sync(src,dest,options)
|
64
55
|
end
|
65
|
-
|
66
|
-
def
|
67
|
-
parse_options(
|
68
|
-
# if from[:dir] does not exist then abort as there is nothing to do
|
56
|
+
|
57
|
+
def sync(src,dest,options={})
|
58
|
+
parse_options(src,dest,options)
|
69
59
|
cmd = generate_cmd
|
70
|
-
logger.info "
|
60
|
+
logger.info "quicksync command:\n #{cmd}"
|
71
61
|
if run_method == :execute
|
72
|
-
# run the actual command before returning it
|
73
62
|
logger.info "RSync.pull_from: about to execute command"
|
74
|
-
|
75
|
-
|
63
|
+
# system(cmd)
|
76
64
|
end
|
77
|
-
|
65
|
+
|
78
66
|
return cmd
|
79
67
|
end
|
80
|
-
|
81
|
-
def
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
68
|
+
|
69
|
+
def to_str
|
70
|
+
out = "QuickSync.to_str:\n"
|
71
|
+
out += " :src=#{src}\n"
|
72
|
+
out += " :dest=#{dest}\n"
|
73
|
+
out += " :dest_fully_qualified=#{dest_fully_qualified}\n"
|
74
|
+
out += " :host=#{host}\n"
|
75
|
+
out += " :user=#{user}\n"
|
76
|
+
out += " :exclude=#{exclude.join(',')}\n" if ! exclude.nil?
|
77
|
+
out += " :include=#{include.join(',')}\n" if ! include.nil?
|
78
|
+
out += " :copy_options=#{copy_options.join(" --")}\n"
|
79
|
+
out += " :settings=#{settings}\n"
|
80
|
+
out += " :sync_type=#{sync_type}\n"
|
81
|
+
out += " :sync_types=#{sync_types}\n"
|
82
|
+
out += " :run_on=#{run_on}\n"
|
83
|
+
out += " :run_method=#{run_method}\n"
|
84
|
+
return out
|
94
85
|
end
|
95
|
-
|
96
|
-
def
|
97
|
-
|
98
|
-
|
99
|
-
|
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
|
86
|
+
|
87
|
+
def parse_options(src,dest,options)
|
88
|
+
|
89
|
+
if src.nil? || src.empty?
|
90
|
+
raise ArgumentError, ":src can not be empty"
|
107
91
|
end
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
if ! the_host.nil? && ! the_host.empty? && the_host.include?("local")
|
112
|
-
return true
|
113
|
-
else
|
114
|
-
return false
|
92
|
+
|
93
|
+
if dest.nil? || dest.empty?
|
94
|
+
raise ArgumentError, ":dest can not be empty"
|
115
95
|
end
|
96
|
+
|
97
|
+
@src = ( ! src.nil? && ! src.empty? ) ? src: default_options[:src]
|
98
|
+
@dest = ( ! dest.nil? && ! dest.empty? ) ? dest: default_options[:dest]
|
99
|
+
@host = ( ! host.nil? && ! host.empty? ) ? host: default_options[:host]
|
100
|
+
@user = ( ! user.nil? && ! user.empty? ) ? user: default_options[:user]
|
101
|
+
@exclude = options.length > 0 && ! options[:exclude].nil? ? options[:exclude]: default_options[:exclude]
|
102
|
+
@include = options.length > 0 && ! options[:include].nil? ? options[:include]: default_options[:include]
|
103
|
+
@copy_options = options.length > 0 && ! options[:copy_options].nil? ? options[:copy_options]: default_options[:copy_options]
|
104
|
+
@settings = options.length > 0 && ! options[:settings].nil? ? default_options[:settings].merge(options[:settings]): default_options[:settings]
|
105
|
+
@run_method = options.length > 0 && ! options[:run_method].nil? ? options[:run_method]: default_options[:run_method]
|
106
|
+
|
107
|
+
logger.important " parse_options: #{self.to_str}"
|
108
|
+
|
116
109
|
end
|
117
110
|
|
118
|
-
def
|
119
|
-
|
120
|
-
return true
|
121
|
-
else
|
122
|
-
return false
|
123
|
-
end
|
111
|
+
def copy_options_to_s
|
112
|
+
return copy_options.map{ |o| "--#{o}"}.join(' ')
|
124
113
|
end
|
125
|
-
|
126
|
-
def
|
127
|
-
|
128
|
-
|
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]
|
114
|
+
|
115
|
+
def include_to_s
|
116
|
+
if include.any?
|
117
|
+
return include.map { |i| "--include=\"#{i}\"" }.join(' ')
|
133
118
|
end
|
134
119
|
end
|
135
|
-
|
136
|
-
def
|
137
|
-
|
138
|
-
|
139
|
-
val = to[:user]+"@"+to[:host] + ":" + to[:dir]
|
140
|
-
else
|
141
|
-
return to[:dir]
|
120
|
+
|
121
|
+
def exclude_to_s
|
122
|
+
if exclude.any?
|
123
|
+
return exclude.map { |e| "--exclude=\"#{e}\"" }.join(' ')
|
142
124
|
end
|
143
125
|
end
|
144
126
|
|
145
|
-
|
146
127
|
def generate_cmd
|
147
128
|
logger.debug "QuickSync.generated_cmd: method called"
|
148
|
-
|
149
129
|
cmd = "#{settings[:rsync_app]} #{copy_options_to_s}"
|
150
130
|
cmd << " #{include_to_s}" if !include.nil? && include.any?
|
151
131
|
cmd << " #{exclude_to_s}" if !exclude.nil? && exclude.any?
|
152
|
-
cmd << " #{
|
153
|
-
|
132
|
+
cmd << " #{src_fully_qualified}/ #{dest_fully_qualified}"
|
133
|
+
|
154
134
|
return cmd
|
155
135
|
end
|
156
136
|
|
137
|
+
|
138
|
+
|
157
139
|
end
|
158
140
|
|
159
141
|
end
|
data/lib/quicksync/version.rb
CHANGED
data/test/test_quicksync.rb
CHANGED
@@ -2,31 +2,55 @@ require 'helper'
|
|
2
2
|
require 'quicksync'
|
3
3
|
|
4
4
|
class TestQuickSync < Test::Unit::TestCase
|
5
|
+
|
6
|
+
attr_accessor :src, :dest, :user, :host, :exclude, :include, :copy_options, :settings, :run_method, :copy_method, :run_on
|
7
|
+
|
5
8
|
def setup
|
6
|
-
|
7
|
-
|
9
|
+
@logger = QuickSync.Logger
|
10
|
+
@logger.level = QuickSync::Logger::INFO
|
11
|
+
@config = QuickSync.Config
|
12
|
+
@quicksync = QuickSync::RSync.new
|
13
|
+
@src = @config[:src]
|
14
|
+
@dest = @config[:dest]
|
15
|
+
@host = @config[:host]
|
16
|
+
@user = @config[:user]
|
17
|
+
@options = @config
|
8
18
|
|
9
19
|
end
|
10
20
|
|
11
21
|
def teardown
|
12
22
|
|
13
23
|
end
|
14
|
-
|
15
|
-
|
24
|
+
|
25
|
+
|
26
|
+
def test_config
|
16
27
|
|
17
28
|
assert_nothing_raised do
|
18
|
-
|
19
|
-
|
20
|
-
|
29
|
+
@config = QuickSync.Config
|
30
|
+
end
|
31
|
+
end
|
21
32
|
|
22
|
-
|
23
|
-
to = options[:to]
|
24
|
-
cmd = qs.pull_from(from,to,options)
|
33
|
+
def test_rsync
|
25
34
|
|
35
|
+
puts "test_rsync: testing pull_from"
|
36
|
+
assert_nothing_raised do
|
37
|
+
cmd = @quicksync.pull_from(@src,@dest,@options)
|
38
|
+
end
|
39
|
+
puts "test_rsync: testing push_to"
|
40
|
+
assert_nothing_raised do
|
41
|
+
cmd = @quicksync.push_to(@src,@dest,@options)
|
42
|
+
end
|
43
|
+
puts "test_rsync: testing copy_local"
|
44
|
+
assert_nothing_raised do
|
45
|
+
cmd = @quicksync.copy_local(@src,@dest,@options)
|
46
|
+
end
|
47
|
+
puts "test_rsync: testing copy_remote"
|
48
|
+
assert_nothing_raised do
|
49
|
+
cmd = @quicksync.copy_remote(@src,@dest,@options)
|
26
50
|
end
|
27
51
|
|
28
|
-
|
29
52
|
|
53
|
+
|
30
54
|
end
|
31
55
|
|
32
56
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quicksync
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.7
|
4
|
+
version: 0.0.7.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -205,6 +205,7 @@ files:
|
|
205
205
|
- Rakefile
|
206
206
|
- bin/quicksync
|
207
207
|
- config/.quicksync_config
|
208
|
+
- config/quicksync.yaml
|
208
209
|
- lib/core_ext.rb
|
209
210
|
- lib/quicksync.rb
|
210
211
|
- lib/quicksync/cli.rb
|
@@ -228,7 +229,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
228
229
|
version: '0'
|
229
230
|
segments:
|
230
231
|
- 0
|
231
|
-
hash: -
|
232
|
+
hash: -2741976033233478250
|
232
233
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
233
234
|
none: false
|
234
235
|
requirements:
|
@@ -237,7 +238,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
237
238
|
version: '0'
|
238
239
|
segments:
|
239
240
|
- 0
|
240
|
-
hash: -
|
241
|
+
hash: -2741976033233478250
|
241
242
|
requirements: []
|
242
243
|
rubyforge_project:
|
243
244
|
rubygems_version: 1.8.24
|