mirrorworks 0.0.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 222eb5938e2c9cd60556a8a9ed479001102bcbda
4
+ data.tar.gz: a6f9bbf43a1ff4d23dceaff53347ea1d01cfb5cc
5
+ SHA512:
6
+ metadata.gz: e31c0d4d8e6b628276fd9ebead81596f3717b102c9dc8109990209f841dfb272852690d2a2b58b695524ad7c9c45857011ac48c7aed6d9654d2b4651cad758ae
7
+ data.tar.gz: 21c0cb44184b11b7af6c8d2327f683376e68718cd67b3b15adf35854b8e8a7e364df9058b78418d647f39a397adae99367f6bf70c151f149a5f423ed1e19513d
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ Mirrorworks
2
+ ===========
3
+
4
+ A handy rsync wrapper cli tool.
5
+
6
+ This is a dead-simple script that lets you easily set up pairs of files or
7
+ directories (called 'reflections') and sync them locally or over the network
8
+ with commands like
9
+ `$ mirrorworks push`
10
+ and
11
+ `$ mirrorworks pull`
12
+
13
+
14
+ Installation and Configuration
15
+ ------------------------------
16
+ Make sure you have rsync and ruby installed on your system.
17
+
18
+ Install the gem with
19
+ `$ gem install mirrorworks`
20
+
21
+ Mirrorworks reads a configuration file at ~/.mirrorworksrc.json.
22
+ To create an example config file run:
23
+ `$ mirrorworks install`
24
+
25
+ This file contains some underlying rsync runtime options as well as a set of
26
+ 'reflections'. Reflections are pairs files or directories that you want to have
27
+ synchronized. Each consists of a name, a local file/dir, and a remote file/dir.
28
+ There are a few things to remember when setting up your reflections:
29
+
30
+ * The name of each reflection should be unique.
31
+ * Directory paths should end in a slash /.
32
+ * You can use '$HOME' or '~' to refer to your home directory.
33
+ * Currently, paths including a space can't be used.
34
+
35
+ Using Mirrorworks
36
+ -----------------
37
+ The script is very straightforward. For usage, run
38
+ `$ mirrorworks --help`
data/bin/mirrorworks ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'mirrorworks'
4
+
5
+ Mirrorworks.new.run ARGV
@@ -0,0 +1,16 @@
1
+ {
2
+ "rsync_opts": ["-irtupEl"],
3
+
4
+ "reflections": [
5
+ {
6
+ "name": "first_example",
7
+ "local": "/dirs/end/with/slash/",
8
+ "remote": "me@example.com:~/dest/"
9
+ },
10
+ {
11
+ "name": "second_example",
12
+ "local": "$HOME/.mirrorworksrc.json",
13
+ "remote": "/public/mirrorworksrc.json"
14
+ }
15
+ ]
16
+ }
@@ -0,0 +1,167 @@
1
+ require 'optparse'
2
+ require 'fileutils'
3
+ require 'rsync'
4
+ require 'json'
5
+
6
+ CONF_AT = File.join(Dir.home, '.mirrorworksrc.json')
7
+
8
+ class Mirrorworks
9
+
10
+ def initialize
11
+ @help_opts = ''
12
+ @conf = nil
13
+ end
14
+
15
+
16
+ def parse_config
17
+ unless File.readable? CONF_AT
18
+ raise "Can't read #{CONF_AT}. Use 'install' command to make example conf."
19
+ end
20
+ File.open(CONF_AT, 'r') {|f| @conf = JSON.parse(f.read)}
21
+ end
22
+
23
+
24
+ def each_reflection(args)
25
+ if args.empty?
26
+ # use all reflections if none are given
27
+ @conf['reflections'].each {|r| yield r}
28
+ else
29
+ args.each do |a|
30
+ ref = nil
31
+ @conf['reflections'].each do |r|
32
+ if args.include? r['name']
33
+ ref = r
34
+ break
35
+ end
36
+ end
37
+ if ref.nil?
38
+ raise "No reflection '#{a}'"
39
+ else
40
+ yield ref
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+
47
+ def install
48
+ src = File.join(File.dirname(__FILE__), '..', 'example.mirrorworksrc.json')
49
+ raise "#{CONF_AT} already exists. Nothing to do." if File.exists? CONF_AT
50
+ FileUtils.cp(src, CONF_AT)
51
+ puts "Created example config at #{CONF_AT}"
52
+ end
53
+
54
+
55
+ def push(args)
56
+ each_reflection(args) do |ref|
57
+ puts ">>>> Pushing #{ref['name']} >>>>"
58
+ result = Rsync.run(ref['local'], ref['remote'], @conf['rsync_opts'])
59
+ raise result.error unless result.success?
60
+
61
+ result.changes.each {|c| puts c.filename}
62
+ puts
63
+ end
64
+ end
65
+
66
+ def pull(args)
67
+ each_reflection(args) do |ref|
68
+ puts "<<<< Pulling #{ref['name']} <<<<"
69
+ result = Rsync.run(ref['remote'], ref['local'], @conf['rsync_opts'])
70
+ raise result.error unless result.success?
71
+
72
+ result.changes.each {|c| puts c.filename}
73
+ puts
74
+ end
75
+ end
76
+
77
+
78
+ def status(args)
79
+ each_reflection(args) do |ref|
80
+ @conf['rsync_opts'] << '-n'
81
+ push(args)
82
+ pull(args)
83
+ end
84
+ end
85
+
86
+
87
+ def list
88
+ @conf['reflections'].each do |r|
89
+ puts "Name: #{r['name']}",
90
+ " Local: #{r['local']}",
91
+ " Remote: #{r['remote']}",
92
+ ''
93
+ end
94
+ end
95
+
96
+
97
+ def version
98
+ path = File.join(File.dirname(__FILE__), '..', 'mirrorworks.gemspec')
99
+ spec = Gem::Specification::load(path)
100
+ puts spec.version
101
+ exit
102
+ end
103
+
104
+
105
+ def help
106
+ puts @help_opts
107
+ puts '',
108
+ ' Commands:',
109
+ ' install create example conf in home directory',
110
+ ' push push from local to remote',
111
+ ' pull pull from remote to local',
112
+ ' status get status of reflections',
113
+ ' list list reflections',
114
+ '',
115
+ "Reads json configuration file from #{CONF_AT}.",
116
+ 'All reflections will be used when none are specified.',
117
+ 'See the README.md for more information.'
118
+ exit
119
+ end
120
+
121
+
122
+ private :parse_config,
123
+ :each_reflection,
124
+ :install,
125
+ :push,
126
+ :pull,
127
+ :status,
128
+ :list,
129
+ :version,
130
+ :help
131
+
132
+
133
+ def run(args)
134
+ begin
135
+ OptionParser.new do |opts|
136
+ opts.banner = 'Usage: mirrorworks [options...] <command> [reflections...]'
137
+ opts.on('-V', '--version', 'print version and exit') {version}
138
+ opts.on('-h', '--help', 'print help and exit') {help}
139
+ opts.on('-x', '--hard', 'delete extra files on transfer') do |x|
140
+ @conf['rsync_opts'] << '--delete' if x
141
+ end
142
+ @help_opts = opts.to_s
143
+ end.parse! args
144
+
145
+ help if args.empty?
146
+
147
+ command = args.shift
148
+ parse_config unless command == 'install'
149
+ case command
150
+ when 'push'
151
+ push args
152
+ when 'pull'
153
+ pull args
154
+ when 'status'
155
+ status args
156
+ when 'list'
157
+ list
158
+ when 'install'
159
+ install
160
+ else
161
+ raise "No command '#{command}'"
162
+ end
163
+ rescue Exception => e
164
+ puts e.message
165
+ end
166
+ end
167
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mirrorworks
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Tyler Brazier
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rsync
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ description: A file and directory synchronizer tool that wraps rsync
28
+ email: tyler@tylerbrazier.com
29
+ executables:
30
+ - mirrorworks
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - LICENSE
35
+ - README.md
36
+ - bin/mirrorworks
37
+ - example.mirrorworksrc.json
38
+ - lib/mirrorworks.rb
39
+ homepage: http://github.com/tylerbrazier/mirrorworks
40
+ licenses:
41
+ - MIT
42
+ metadata: {}
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubyforge_project:
59
+ rubygems_version: 2.2.2
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: A handy rsync wrapper cli tool
63
+ test_files: []