checksummer 0.1.4 → 0.1.5
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/VERSION +1 -1
- data/checksummer.gemspec +2 -2
- data/lib/checksummer.rb +10 -7
- data/spec/checksummer_spec.rb +26 -6
- metadata +4 -4
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.1.
|
|
1
|
+
0.1.5
|
data/checksummer.gemspec
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |s|
|
|
7
7
|
s.name = %q{checksummer}
|
|
8
|
-
s.version = "0.1.
|
|
8
|
+
s.version = "0.1.5"
|
|
9
9
|
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
11
|
s.authors = ["Tobias Schwab"]
|
|
12
|
-
s.date = %q{2011-
|
|
12
|
+
s.date = %q{2011-02-12}
|
|
13
13
|
s.default_executable = %q{checksummer}
|
|
14
14
|
s.description = %q{Replace files with links to md5 files}
|
|
15
15
|
s.email = %q{tobias.schwab@dynport.de}
|
data/lib/checksummer.rb
CHANGED
|
@@ -8,8 +8,8 @@ class Checksummer
|
|
|
8
8
|
self.checksum_to = File.expand_path(checksum_to)
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
-
def checksum_directory(directory)
|
|
12
|
-
files = find(directory)
|
|
11
|
+
def checksum_directory(directory, find_options = nil)
|
|
12
|
+
files = find(directory, find_options)
|
|
13
13
|
total = files.length
|
|
14
14
|
files.each_with_index do |file, i|
|
|
15
15
|
status = file.checksum_to!(checksum_to)
|
|
@@ -17,19 +17,19 @@ class Checksummer
|
|
|
17
17
|
end
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
-
def find(directory)
|
|
21
|
-
Kernel.send(:`, %(find #{directory} -type f -printf "%T+\t%s\t%Y\t%p\t%l\n")).split("\n").map do |line|
|
|
20
|
+
def find(directory, options = nil)
|
|
21
|
+
Kernel.send(:`, %(find #{directory} #{options ? "#{options} " : ""}-type f -printf "%T+\t%s\t%Y\t%p\t%l\n")).split("\n").map do |line|
|
|
22
22
|
ChecksummerFile.from_line(line)
|
|
23
23
|
end
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
def self.run_for_args(args)
|
|
27
|
-
directory, checksum_to = args
|
|
27
|
+
directory, checksum_to = args[0,2]
|
|
28
28
|
sleep = args.index("--sleep") ? args[args.index("--sleep") + 1].to_i / 1000.0 : 0.1
|
|
29
29
|
if !directory || !File.directory?(directory) || !checksum_to || !File.directory?(checksum_to)
|
|
30
30
|
puts usage
|
|
31
31
|
else
|
|
32
|
-
self.new(checksum_to).checksum_directory(directory) do |status, file, index, total|
|
|
32
|
+
self.new(checksum_to).checksum_directory(directory, args[2..-1].join(" ")) do |status, file, index, total|
|
|
33
33
|
puts "%s\t%0#{total.to_s.length}d/%d\t%s\t%s" % [Time.now.strftime("%Y-%m-%d %H:%M:%S"), index, total, status, file.path]
|
|
34
34
|
$stdout.flush
|
|
35
35
|
sleep sleep if !Range.new(0,7).include?(Time.now.hour)
|
|
@@ -38,6 +38,9 @@ class Checksummer
|
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
def self.usage
|
|
41
|
-
"checksummer <directory_to_checksum> <directory_to_store_checksummed_files>"
|
|
41
|
+
out = ["checksummer <directory_to_checksum> <directory_to_store_checksummed_files> [options]"]
|
|
42
|
+
out << ["OPTIONS", "--sleep <sleep in ms>"]
|
|
43
|
+
out << ["OPTIONS", "<any find option>"]
|
|
44
|
+
out.join("\n")
|
|
42
45
|
end
|
|
43
46
|
end
|
data/spec/checksummer_spec.rb
CHANGED
|
@@ -25,8 +25,8 @@ describe "Checksummer" do
|
|
|
25
25
|
let(:file2) { double("checksummer file 2", :checksum_to! => :symlinked, :path => "/path2") }
|
|
26
26
|
|
|
27
27
|
it "it calls find with correct parameters" do
|
|
28
|
-
cs.should_receive(:find).with("path1").and_return []
|
|
29
|
-
cs.checksum_directory("path1")
|
|
28
|
+
cs.should_receive(:find).with("path1", "-mtime +1").and_return []
|
|
29
|
+
cs.checksum_directory("path1", "-mtime +1")
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
it "calls checksum on all ChecksummerFiles" do
|
|
@@ -68,6 +68,11 @@ describe "Checksummer" do
|
|
|
68
68
|
cs.find("path1")
|
|
69
69
|
end
|
|
70
70
|
|
|
71
|
+
it "uses find options" do
|
|
72
|
+
Kernel.should_receive(:`).with(%(find path1 -mtime +1 -type f -printf "%T+\t%s\t%Y\t%p\t%l\n"))
|
|
73
|
+
cs.find("path1", "-mtime +1")
|
|
74
|
+
end
|
|
75
|
+
|
|
71
76
|
it "returns the correct amount of files" do
|
|
72
77
|
cs.find("path1").length.should == 6
|
|
73
78
|
end
|
|
@@ -106,11 +111,18 @@ describe "Checksummer" do
|
|
|
106
111
|
Checksummer.run_for_args(["/tmp", "/tmp"])
|
|
107
112
|
end
|
|
108
113
|
|
|
114
|
+
it "calls checksum_directory wirh correct find options" do
|
|
115
|
+
checksummer = double("checksummer")
|
|
116
|
+
Checksummer.stub!(:new).and_return checksummer
|
|
117
|
+
checksummer.should_receive(:checksum_directory).with("/tmp", %(-name "*.mp3"))
|
|
118
|
+
Checksummer.run_for_args(["/tmp", "/tmp", "-name", %("*.mp3")])
|
|
119
|
+
end
|
|
120
|
+
|
|
109
121
|
describe "with a cs double" do
|
|
110
122
|
before(:each) do
|
|
111
123
|
@cs_double = double("cs")
|
|
112
124
|
Checksummer.stub(:new).with("/tmp").and_return @cs_double
|
|
113
|
-
def @cs_double.checksum_directory(path)
|
|
125
|
+
def @cs_double.checksum_directory(path, find_options)
|
|
114
126
|
file1 = ChecksummerFile.new(:path => "/path1.txt")
|
|
115
127
|
file2 = ChecksummerFile.new(:path => "/path2.txt")
|
|
116
128
|
yield(:copied, file1, 0, 20)
|
|
@@ -170,8 +182,8 @@ describe "Checksummer" do
|
|
|
170
182
|
end
|
|
171
183
|
|
|
172
184
|
it "checksums all files" do
|
|
173
|
-
|
|
174
|
-
|
|
185
|
+
Checksummer.stub!(:puts)
|
|
186
|
+
Checksummer.run_for_args(["#{root}/source", "#{root}/data"])
|
|
175
187
|
{ "4/3/4/9/4349cfeff8e2eb74dffc369bb5fd084e" => ["file2.txt", time_for_index(2)],
|
|
176
188
|
"9/c/3/8/9c38e8324dbf031557c89d53a39f0b26" => ["file3.txt", time_for_index(3)],
|
|
177
189
|
"e/2/4/3/e243bb39c844b3543a7726576c869caf" => ["file1.txt", time_for_index(1)],
|
|
@@ -186,6 +198,14 @@ describe "Checksummer" do
|
|
|
186
198
|
File.mtime(original).should == mtime
|
|
187
199
|
end
|
|
188
200
|
end
|
|
201
|
+
|
|
202
|
+
it "only runs on specific files when option given" do
|
|
203
|
+
File.open("#{root}/source/test.mp3", "w") { |f| f.puts "some mp3" }
|
|
204
|
+
Checksummer.stub!(:puts)
|
|
205
|
+
Checksummer.run_for_args(["#{root}/source", "#{root}/data", "-name", %("*.mp3")])
|
|
206
|
+
File.should be_a_symlink("#{root}/source/test.mp3")
|
|
207
|
+
File.should be_exists("#{root}/source/file1.txt")
|
|
208
|
+
File.should_not be_a_symlink("#{root}/source/file1.txt")
|
|
209
|
+
end
|
|
189
210
|
end
|
|
190
|
-
|
|
191
211
|
end
|
metadata
CHANGED
|
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
|
5
5
|
segments:
|
|
6
6
|
- 0
|
|
7
7
|
- 1
|
|
8
|
-
-
|
|
9
|
-
version: 0.1.
|
|
8
|
+
- 5
|
|
9
|
+
version: 0.1.5
|
|
10
10
|
platform: ruby
|
|
11
11
|
authors:
|
|
12
12
|
- Tobias Schwab
|
|
@@ -14,7 +14,7 @@ autorequire:
|
|
|
14
14
|
bindir: bin
|
|
15
15
|
cert_chain: []
|
|
16
16
|
|
|
17
|
-
date: 2011-
|
|
17
|
+
date: 2011-02-12 00:00:00 +01:00
|
|
18
18
|
default_executable: checksummer
|
|
19
19
|
dependencies:
|
|
20
20
|
- !ruby/object:Gem::Dependency
|
|
@@ -155,7 +155,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
155
155
|
requirements:
|
|
156
156
|
- - ">="
|
|
157
157
|
- !ruby/object:Gem::Version
|
|
158
|
-
hash:
|
|
158
|
+
hash: 4188489209554996846
|
|
159
159
|
segments:
|
|
160
160
|
- 0
|
|
161
161
|
version: "0"
|