checksummer 0.2.1 → 0.2.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.
- data/VERSION +1 -1
- data/checksummer.gemspec +2 -2
- data/features/checksum.feature +9 -1
- data/features/step_definitions/checksum_steps.rb +9 -0
- data/lib/checksummer.rb +31 -18
- data/spec/checksummer_spec.rb +5 -7
- metadata +4 -4
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.2.
|
|
1
|
+
0.2.2
|
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.2.
|
|
8
|
+
s.version = "0.2.2"
|
|
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-04-
|
|
12
|
+
s.date = %q{2011-04-06}
|
|
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/features/checksum.feature
CHANGED
|
@@ -92,4 +92,12 @@ Feature: Checksum
|
|
|
92
92
|
Then I should see 1 files in "tmp/dst"
|
|
93
93
|
Then I should see the following files
|
|
94
94
|
| symlink | path | content |
|
|
95
|
-
| src/file11.txt | dst/7/1/5/0/715081268e5e053a7e89daf6c155244a | file 11 |
|
|
95
|
+
| src/file11.txt | dst/7/1/5/0/715081268e5e053a7e89daf6c155244a | file 11 |
|
|
96
|
+
|
|
97
|
+
Scenario: Checksum not existing file
|
|
98
|
+
Given I clear tmp
|
|
99
|
+
And the directory "dst" exists
|
|
100
|
+
When I call "checksummer tmp/src/file11.txt tmp/dst"
|
|
101
|
+
Then I should get the following response
|
|
102
|
+
| status | not_found |
|
|
103
|
+
| original_line | tmp/src/file11.txt |
|
|
@@ -67,4 +67,13 @@ end
|
|
|
67
67
|
|
|
68
68
|
Given /^I freeze time to "([^"]*)"$/ do |time|
|
|
69
69
|
Timecop.freeze(Time.parse(time))
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
Then /^I should get the following response$/ do |table|
|
|
73
|
+
json = JSON.parse(@out.to_s)
|
|
74
|
+
headers = ([table.headers] + table.rows).map(&:first)
|
|
75
|
+
result = headers.map do |header|
|
|
76
|
+
[header, json[header]]
|
|
77
|
+
end
|
|
78
|
+
table.diff!(result)
|
|
70
79
|
end
|
data/lib/checksummer.rb
CHANGED
|
@@ -3,6 +3,8 @@ $:<< File.expand_path(File.dirname(__FILE__))
|
|
|
3
3
|
require "checksummer_file"
|
|
4
4
|
require "json"
|
|
5
5
|
class Checksummer
|
|
6
|
+
DEFAULT_SLEEP = 0.1
|
|
7
|
+
|
|
6
8
|
def self.find(directory, options = nil)
|
|
7
9
|
Kernel.send(:`, %(find #{directory} #{options ? "#{options} " : ""}-type f -printf "%p\t%T+\t%s\t%Y\t%l\n")).split("\n")
|
|
8
10
|
end
|
|
@@ -12,31 +14,42 @@ class Checksummer
|
|
|
12
14
|
puts File.read(File.expand_path("../VERSION", File.dirname(__FILE__)))
|
|
13
15
|
return
|
|
14
16
|
end
|
|
15
|
-
|
|
16
|
-
sleep =
|
|
17
|
-
if
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if File.file?(directory)
|
|
23
|
-
puts ChecksummerFile.from_line(directory).checksum_to!(checksum_to).to_json
|
|
17
|
+
directory_or_file, checksum_to = args[0,2]
|
|
18
|
+
sleep = sleep_from_args(args)
|
|
19
|
+
if directory_or_file && checksum_to && File.directory?(checksum_to)
|
|
20
|
+
lines = if directory_or_file == "--stdin"
|
|
21
|
+
$stdin.readlines
|
|
22
|
+
elsif File.directory?(directory_or_file)
|
|
23
|
+
find(directory_or_file, args[2..-1].join(" "))
|
|
24
24
|
else
|
|
25
|
-
|
|
26
|
-
lines = directory == "--stdin" ? $stdin.readlines : find(directory, args[2..-1].join(" "))
|
|
27
|
-
total = lines.count
|
|
28
|
-
lines.each_with_index do |line, index|
|
|
29
|
-
extra = { :index => index + 1, :total => lines.count, :started_at => started_at.iso8601 }
|
|
30
|
-
puts ChecksummerFile.from_line(line).checksum_to!(checksum_to).merge(extra).to_json
|
|
31
|
-
$stdout.flush
|
|
32
|
-
sleep sleep if !Range.new(0,7).include?(Time.now.hour)
|
|
33
|
-
end
|
|
25
|
+
[directory_or_file]
|
|
34
26
|
end
|
|
27
|
+
checksum_many(lines, checksum_to, sleep)
|
|
35
28
|
return true
|
|
36
29
|
end
|
|
37
30
|
puts usage
|
|
38
31
|
end
|
|
39
32
|
|
|
33
|
+
def self.sleep_from_args(args)
|
|
34
|
+
if idx = args.index("--sleep")
|
|
35
|
+
args.delete_at(idx)
|
|
36
|
+
args.delete_at(idx).to_i / 1000.0
|
|
37
|
+
else
|
|
38
|
+
DEFAULT_SLEEP
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def self.checksum_many(lines, checksum_to, sleep = DEFAULT_SLEEP)
|
|
43
|
+
started_at = Time.now
|
|
44
|
+
total = lines.count
|
|
45
|
+
lines.each_with_index do |line, index|
|
|
46
|
+
extra = { :index => index + 1, :total => lines.count, :started_at => started_at.iso8601 }
|
|
47
|
+
puts ChecksummerFile.from_line(line).checksum_to!(checksum_to).merge(extra).to_json
|
|
48
|
+
$stdout.flush
|
|
49
|
+
sleep sleep if !Range.new(0,7).include?(Time.now.hour)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
40
53
|
def self.usage
|
|
41
54
|
out = ["checksummer <directory_to_checksum> <directory_to_store_checksummed_files> [options]"]
|
|
42
55
|
out << ["OPTIONS", "--sleep <sleep in ms>", "<any find option>"]
|
data/spec/checksummer_spec.rb
CHANGED
|
@@ -140,18 +140,13 @@ describe "Checksummer" do
|
|
|
140
140
|
end
|
|
141
141
|
|
|
142
142
|
describe "with a direct file given" do
|
|
143
|
-
let(:checksum_file) { double("checksummer_file", :checksum_to! =>
|
|
143
|
+
let(:checksum_file) { double("checksummer_file", :checksum_to! => {})}
|
|
144
144
|
|
|
145
145
|
before(:each) do
|
|
146
146
|
File.stub!(:file?).and_return true
|
|
147
147
|
ChecksummerFile.stub!(:from_line).and_return(checksum_file)
|
|
148
148
|
end
|
|
149
149
|
|
|
150
|
-
it "calls File.file? on src" do
|
|
151
|
-
File.should_receive(:file?).with("/some/path").and_return true
|
|
152
|
-
Checksummer.run_for_args(["/some/path", "/tmp"])
|
|
153
|
-
end
|
|
154
|
-
|
|
155
150
|
it "calls ChecksummerFile.from_line with file" do
|
|
156
151
|
ChecksummerFile.should_receive(:from_line).with("/some/path").and_return(checksum_file)
|
|
157
152
|
Checksummer.run_for_args(["/some/path", "/tmp"])
|
|
@@ -163,8 +158,11 @@ describe "Checksummer" do
|
|
|
163
158
|
end
|
|
164
159
|
|
|
165
160
|
it "puts result of checksum_to!" do
|
|
161
|
+
Time.stub(:now).and_return Time.local(2011, 2, 3, 4, 5, 6)
|
|
166
162
|
checksum_file.stub!(:checksum_to!).and_return(:some => "result")
|
|
167
|
-
Checksummer.should_receive(:puts).with(
|
|
163
|
+
Checksummer.should_receive(:puts).with(
|
|
164
|
+
"{\"some\":\"result\",\"index\":1,\"total\":1,\"started_at\":\"2011-02-03T04:05:06+01:00\"}"
|
|
165
|
+
)
|
|
168
166
|
Checksummer.run_for_args(["/some/path", "/tmp"])
|
|
169
167
|
end
|
|
170
168
|
end
|
metadata
CHANGED
|
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
|
5
5
|
segments:
|
|
6
6
|
- 0
|
|
7
7
|
- 2
|
|
8
|
-
-
|
|
9
|
-
version: 0.2.
|
|
8
|
+
- 2
|
|
9
|
+
version: 0.2.2
|
|
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-04-
|
|
17
|
+
date: 2011-04-06 00:00:00 +02:00
|
|
18
18
|
default_executable: checksummer
|
|
19
19
|
dependencies:
|
|
20
20
|
- !ruby/object:Gem::Dependency
|
|
@@ -184,7 +184,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
184
184
|
requirements:
|
|
185
185
|
- - ">="
|
|
186
186
|
- !ruby/object:Gem::Version
|
|
187
|
-
hash:
|
|
187
|
+
hash: -691865504154105386
|
|
188
188
|
segments:
|
|
189
189
|
- 0
|
|
190
190
|
version: "0"
|