mirrorworks 0.1.0 → 0.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cd0da08208a1d2ea56fec9b382602974852e3ef3
4
- data.tar.gz: 38e022c740f21507f07eec06a628b1c5ef810d6f
3
+ metadata.gz: 58cb6b98f44aff4d8dbc13f4484dff1ade3803d1
4
+ data.tar.gz: afc17f0cc0320aaf5eddc94b0c67d458efc832ab
5
5
  SHA512:
6
- metadata.gz: ceaab3fd63fea590e302e70099e34d3ee363a7e7ab27e67b63b3416dd1a26cc2cb06e619f6ef04a6d641b6bbcadb2a5fe3f58f12d48e6ed21a24b0cb4ca13755
7
- data.tar.gz: 31df3fb01deac0c5ff2235f711f6f412dd6a07a3a138e2278913236f8f67ff3190cd1aae4dc7459f5dac94ac26952498f4dd696005fdf8ff096338a1a896c1cc
6
+ metadata.gz: ba6a4407b7b2f5d2b05e58e57f795dca3f6ee7f9cadaf9c73bef775f0229615884647c9e182c1efead09d34ae11bc19f093e990c0232b48381aeca8ac43ef06e
7
+ data.tar.gz: 995f9b9a4f0fbbf10340ab42aaa98b2cb585ac09a0d3d57ae0c9513dd2fb69b4848fc5e5246cbbd24c296a0b0f361ba393830ba78180b0dd06b4ffb0e06d2d7e
@@ -1,5 +1,11 @@
1
1
  {
2
- "rsync_opts": ["-irtupEl"],
2
+ "rsync_opts": [
3
+ "-rtupEl",
4
+ "--exclude=.git/*",
5
+ "--backup",
6
+ "--backup-dir=$HOME/.backup",
7
+ "--suffix=.$(date +%Y-%m-%d-%H-%M)"
8
+ ],
3
9
 
4
10
  "reflections": [
5
11
  {
data/lib/mirrorworks.rb CHANGED
@@ -3,17 +3,18 @@ require 'fileutils'
3
3
  require 'rsync'
4
4
  require 'json'
5
5
 
6
- VERSION = '0.1.0'
6
+ VERSION = '0.1.1'
7
7
  CONF_AT = File.join(Dir.home, '.mirrorworksrc.json')
8
8
 
9
9
  class Mirrorworks
10
10
 
11
11
  def initialize
12
- @help_opts = ''
12
+ @help_msg = ''
13
13
  @options = {}
14
14
  @conf = {}
15
15
  end
16
16
 
17
+ private
17
18
 
18
19
  def parse_config
19
20
  unless File.readable? CONF_AT
@@ -23,30 +24,28 @@ class Mirrorworks
23
24
  @conf['rsync_opts'] << '--delete' if @options[:x]
24
25
  end
25
26
 
26
-
27
27
  def each_reflection(args)
28
28
  if args.empty?
29
29
  # use all reflections if none are given
30
- @conf['reflections'].each {|r| yield r}
30
+ @conf['reflections'].each {|ref| yield ref}
31
31
  else
32
- args.each do |a|
33
- ref = nil
34
- @conf['reflections'].each do |r|
35
- if args.include? r['name']
36
- ref = r
32
+ args.each do |arg|
33
+ selected = nil
34
+ @conf['reflections'].each do |ref|
35
+ if arg == ref['name']
36
+ selected = ref
37
37
  break
38
38
  end
39
39
  end
40
- if ref.nil?
41
- raise "No reflection '#{a}'"
40
+ if selected.nil?
41
+ raise "No reflection '#{arg}'"
42
42
  else
43
- yield ref
43
+ yield selected
44
44
  end
45
45
  end
46
46
  end
47
47
  end
48
48
 
49
-
50
49
  def install
51
50
  src = File.join(File.dirname(__FILE__), '..', 'example.mirrorworksrc.json')
52
51
  raise "#{CONF_AT} already exists. Nothing to do." if File.exists? CONF_AT
@@ -54,59 +53,62 @@ class Mirrorworks
54
53
  puts "Created example config at #{CONF_AT}"
55
54
  end
56
55
 
56
+ def transfer(src, dest)
57
+ src.gsub! ' ', '\ '
58
+ dest.gsub! ' ', '\ '
59
+ result = Rsync.run(src, dest, @conf['rsync_opts'])
60
+ raise result.error unless result.success?
61
+ result.changes.each do |c|
62
+ unless c.update_type == :no_update
63
+ summary = c.summary.empty? ? "\t" : c.summary
64
+ puts summary << "\t" << c.filename
65
+ end
66
+ end
67
+ puts
68
+ end
57
69
 
58
70
  def push(args)
59
71
  each_reflection(args) do |ref|
60
72
  puts ">>>> Pushing #{ref['name']} >>>>"
61
- src = ref['local'].sub(' ', '\ ')
62
- dest = ref['remote'].sub(' ', '\ ')
63
- result = Rsync.run(src, dest, @conf['rsync_opts'])
64
- raise result.error unless result.success?
65
- result.changes.each {|c| puts c.filename}
66
- puts
73
+ src = ref['local']
74
+ dest = ref['remote']
75
+ transfer(src, dest)
67
76
  end
68
77
  end
69
78
 
70
79
  def pull(args)
71
80
  each_reflection(args) do |ref|
72
81
  puts "<<<< Pulling #{ref['name']} <<<<"
73
- src = ref['remote'].sub(' ', '\ ')
74
- dest = ref['local'].sub(' ', '\ ')
75
- result = Rsync.run(src, dest, @conf['rsync_opts'])
76
- raise result.error unless result.success?
77
- result.changes.each {|c| puts c.filename}
78
- puts
82
+ src = ref['remote']
83
+ dest = ref['local']
84
+ transfer(src, dest)
79
85
  end
80
86
  end
81
87
 
82
-
83
88
  def status(args)
84
- each_reflection(args) do |ref|
85
- @conf['rsync_opts'] << '-n'
86
- push(args)
87
- pull(args)
88
- end
89
+ puts 'Starting dry run. No changes will be made.'
90
+ @conf['rsync_opts'] << '-n'
91
+ push(args)
92
+ pull(args)
93
+ puts 'End of dry run.'
89
94
  end
90
95
 
91
-
92
- def list
93
- @conf['reflections'].each do |r|
94
- puts "Name: #{r['name']}",
95
- " Local: #{r['local']}",
96
- " Remote: #{r['remote']}",
96
+ def list(args)
97
+ each_reflection(args) do |ref|
98
+ puts "Name: #{ref['name']}",
99
+ " Local: #{ref['local']}",
100
+ " Remote: #{ref['remote']}",
97
101
  ''
98
102
  end
99
103
  end
100
104
 
101
-
102
105
  def version
103
106
  puts VERSION
104
107
  exit
105
108
  end
106
109
 
107
-
108
110
  def help
109
- puts @help_opts
111
+ puts @help_msg
110
112
  puts '',
111
113
  ' Commands:',
112
114
  ' install create example conf in home directory',
@@ -121,28 +123,18 @@ class Mirrorworks
121
123
  exit
122
124
  end
123
125
 
124
-
125
- private :parse_config,
126
- :each_reflection,
127
- :install,
128
- :push,
129
- :pull,
130
- :status,
131
- :list,
132
- :version,
133
- :help
134
-
126
+ public
135
127
 
136
128
  def run(args)
137
129
  begin
138
130
  OptionParser.new do |opts|
139
- opts.banner = 'Usage: mirrorworks [options...] <command> [reflections...]'
131
+ opts.banner = 'Usage: mirrorworks [options] <command> [reflections]'
140
132
  opts.on('-V', '--version', 'print version and exit') {version}
141
133
  opts.on('-h', '--help', 'print help and exit') {help}
142
134
  opts.on('-x', '--hard', 'delete extra files on transfer') do |x|
143
135
  @options[:x] = x
144
136
  end
145
- @help_opts = opts.to_s
137
+ @help_msg = opts.to_s
146
138
  end.parse! args
147
139
 
148
140
  help if args.empty?
@@ -157,7 +149,7 @@ class Mirrorworks
157
149
  when 'status'
158
150
  status args
159
151
  when 'list'
160
- list
152
+ list args
161
153
  when 'install'
162
154
  install
163
155
  else
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mirrorworks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Brazier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-13 00:00:00.000000000 Z
11
+ date: 2014-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rsync