rsyncdiff 0.0.2

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.
Files changed (3) hide show
  1. data/README.textile +15 -0
  2. data/bin/rsyncdiff +162 -0
  3. metadata +56 -0
data/README.textile ADDED
@@ -0,0 +1,15 @@
1
+ This is a simple tool for running diffs against local and remote code. It uses rysnc so it can get all the creations, deletions and updates.
2
+
3
+ Run it like this:
4
+
5
+ <code>rsyncdiff server:/u/apps/myapp/current/app app/</code>
6
+
7
+ !http://dl.getdropbox.com/u/221414/github/rsync_diff.png!
8
+
9
+ It'll use <code>colordiff</code> if it's installed.
10
+
11
+ h3. Installation
12
+
13
+ Install with:
14
+
15
+ <code>gem install alexyoung-rsyncdiff</code>
data/bin/rsyncdiff ADDED
@@ -0,0 +1,162 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # This script uses rsync to compare remote and local files.
4
+ # It will display new files that would have been uploaded
5
+ # and displays a diff for ones that have changes.
6
+
7
+ begin
8
+ remote_path = ARGV[0]
9
+ path = ARGV[1]
10
+ host, remote_path = remote_path.split(':')
11
+ path = path + '/' if path[-1].chr != '/'
12
+ rescue
13
+ puts "Provide two arguments: [remote path] [local path]\n\n"
14
+ puts "For example:"
15
+ puts "\trsyncdiff server:/u/apps/myapp/current/app app/"
16
+ exit 1
17
+ end
18
+
19
+ def colorize(text, color_code)
20
+ "#{color_code}#{text}#{27.chr}[0m"
21
+ end
22
+
23
+ def red(text); colorize(text, "#{27.chr}[31m"); end
24
+ def green(text); colorize(text, "#{27.chr}[32m"); end
25
+
26
+ def use_colordiff?
27
+ not `which colordiff`.empty?
28
+ end
29
+
30
+ class RemoteChange
31
+ attr_reader :file
32
+
33
+ def initialize(string, file)
34
+ @string = string
35
+ @file = file
36
+ end
37
+
38
+ def to_s
39
+ change_type = if new?
40
+ "[#{green 'CREATE'}]"
41
+ elsif include?('new')
42
+ "[#{green 'CREATE'}] #{output.first}"
43
+ elsif change?
44
+ "[#{green 'UPDATE'}] #{output[1]}"
45
+ elsif delete?
46
+ "[#{red 'DELETE'}] #{output[1]}"
47
+ end
48
+
49
+ "#{change_type}\t#{@file}"
50
+ end
51
+
52
+ def new?
53
+ include?('uploaded') and include?('new')
54
+ end
55
+
56
+ def change?
57
+ include?('uploaded') and include?('size')
58
+ end
59
+
60
+ def delete?
61
+ include? 'deleted'
62
+ end
63
+
64
+ def output
65
+ @results ||= parse
66
+ end
67
+
68
+ def include?(item)
69
+ output.include? item
70
+ end
71
+
72
+ def interesting_deletion?
73
+ @string.match /^\*deleting/ and !@string.match /\.svn/
74
+ end
75
+
76
+ def parse
77
+ return @results unless @results.nil?
78
+ @string ||= ''
79
+
80
+ @results = if interesting_deletion?
81
+ ['deleted']
82
+ else
83
+ @string.split('').collect do |c|
84
+ identify c
85
+ end
86
+ end
87
+ @results.compact
88
+ end
89
+
90
+ def identify(c)
91
+ case c
92
+ when '<'
93
+ 'uploaded'
94
+ when '>'
95
+ 'downloaded'
96
+ when 'c'
97
+ 'local change/creation'
98
+ when 'h'
99
+ 'hard link'
100
+ when '*'
101
+ when 'f'
102
+ 'file'
103
+ when 'L'
104
+ 'symlink'
105
+ when '+'
106
+ 'new'
107
+ when '.'
108
+ 'no change'
109
+ when 's'
110
+ 'size'
111
+ end
112
+ end
113
+ end
114
+
115
+ rsync_command = "rsync -rvv --itemize-changes --delete --dry-run #{path} #{host}:#{remote_path}"
116
+ rsync_output = %x(#{rsync_command})
117
+
118
+ items = {}
119
+ items[:creations] = []
120
+ items[:updates] = []
121
+ items[:deletions] = []
122
+
123
+ rsync_output.split("\n").each do |line|
124
+ changes, file = line.gsub(/[ ]+/, ' ').split(' ')
125
+
126
+ # ignore dot files
127
+ next if file.nil? or file[0].chr == '.' or file.match('/\.')
128
+
129
+ item = RemoteChange.new changes, file
130
+
131
+ if item.change?
132
+ items[:updates] << item
133
+ elsif item.new?
134
+ items[:creations] << item
135
+ elsif item.delete?
136
+ items[:deletions] << item
137
+ end
138
+ end
139
+
140
+ items[:deletions].each do |item|
141
+ puts item
142
+ end
143
+
144
+ puts
145
+
146
+ items[:creations].each do |item|
147
+ puts item
148
+ end
149
+
150
+ puts
151
+
152
+ items[:updates].each do |item|
153
+ puts item
154
+ ssh_diff_command = "ssh #{host} cat \"#{File.join(remote_path, item.file)}\" | diff \"#{path}#{item.file}\" -"
155
+
156
+ if use_colordiff?
157
+ ssh_diff_command += ' | colordiff'
158
+ end
159
+
160
+ system(ssh_diff_command)
161
+ puts
162
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rsyncdiff
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Alex R. Young
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-09-16 00:00:00 +01:00
13
+ default_executable: bin/rsyncdiff
14
+ dependencies: []
15
+
16
+ description: rsyncdiff is a tool for comparing local and remote code. It displays changes, deletions and diffs.
17
+ email: alex@alexyoung.org
18
+ executables:
19
+ - rsyncdiff
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - README.textile
26
+ - bin/rsyncdiff
27
+ has_rdoc: false
28
+ homepage: http://github.com/alexyoung/rsyncdiff
29
+ licenses: []
30
+
31
+ post_install_message:
32
+ rdoc_options: []
33
+
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: "0"
41
+ version:
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: "0"
47
+ version:
48
+ requirements: []
49
+
50
+ rubyforge_project:
51
+ rubygems_version: 1.3.4
52
+ signing_key:
53
+ specification_version: 3
54
+ summary: rsyncdiff is a tool for comparing local and remote code.
55
+ test_files: []
56
+