hash-that-tree 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,19 +1,19 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- coverage
6
- InstalledFiles
7
- lib/bundler/man
8
- pkg
9
- rdoc
10
- spec/reports
11
- test/tmp
12
- test/version_tmp
13
- tmp
14
- doc
15
- # YARD artifacts
16
- .yardoc
17
- _yardoc
18
- .project
19
- *~
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+ doc
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ .project
19
+ *~
data/Gemfile.lock CHANGED
@@ -1,17 +1,17 @@
1
- PATH
2
- remote: .
3
- specs:
4
- hash-that-tree (0.0.9)
5
- thor
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- thor (0.16.0)
11
-
12
- PLATFORMS
13
- ruby
14
- x86-mingw32
15
-
16
- DEPENDENCIES
17
- hash-that-tree!
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ hash-that-tree (0.0.9)
5
+ thor
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ thor (0.16.0)
11
+
12
+ PLATFORMS
13
+ ruby
14
+ x86-mingw32
15
+
16
+ DEPENDENCIES
17
+ hash-that-tree!
data/README.md CHANGED
@@ -1,69 +1,69 @@
1
- #hash-that-tree
2
- A ruby command line app that compares the MD5 hashes of the files in different folders
3
-
4
- It allows the user to enter folder locations, then iterats through the files, creating and comparing the MD5 hashes of the files with the same name
5
-
6
- ## Installation
7
-
8
- Add this line to your application's Gemfile:
9
-
10
- gem 'hash-that-tree'
11
-
12
- And then execute:
13
-
14
- $ bundle
15
-
16
- Or install it yourself as:
17
-
18
- $ gem install hash-that-tree
19
-
20
- ## Usage
21
- # to view help
22
- hashthattree help
23
-
24
- # run the app on the test files
25
- hashthattree compare ./spec/testfiles/1 ./spec/testfiles/2
26
- hashthattree compare ./spec/testfiles/1 ./spec/testfiles/2 csv
27
- hashthattree compare ./spec/testfiles/1 ./spec/testfiles/2 html
28
- hashthattree compare ./spec/testfiles/1 ./spec/testfiles/2 json
29
-
30
-
31
- ## Creating Documentation
32
- Run the following command to generate the documantation
33
-
34
- rdoc --exclude spec/testfiles
35
-
36
- ## Create a gem
37
-
38
- Build and Test Locally
39
- -gem build hash-that-tree.gemspec
40
- -gem install hash-that-tree-X.X.X # where X.X.X is the version of the compiled gemspec
41
- -hashthattree
42
-
43
- Build and deploy to rubygems.org
44
- -gem update --system
45
- -gem build hash-that-tree.gemspec
46
- -gem push hash-that-tree-0.0.1.gem # where X.X.X is the version of the compiled gemspec
47
-
48
- ## Contributing
49
-
50
- 1. Fork it
51
- 2. Create your feature branch (`git checkout -b my-new-feature`)
52
- 3. Commit your changes (`git commit -am 'Add some feature'`)
53
- 4. Push to the branch (`git push origin my-new-feature`)
54
- 5. Create new Pull Request
55
-
56
- ##References
57
-
58
- Looking into bundling with https://github.com/radar/guides/blob/master/gem-development.md
59
- http://whatisthor.com/
60
-
61
- ## TODO
62
-
63
- I have a few items to do in upcoming releases
64
- * Add Unit Tests
65
- * Allow to be used as an API as well as a Command Line Tool
66
- * Allow multiple folders to be specified
67
- * Add folder recursion option
68
- * Add SHA1
69
-
1
+ #hash-that-tree
2
+ A ruby command line app that compares the MD5 hashes of the files in different folders
3
+
4
+ It allows the user to enter folder locations, then iterats through the files, creating and comparing the MD5 hashes of the files with the same name
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'hash-that-tree'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install hash-that-tree
19
+
20
+ ## Usage
21
+ # to view help
22
+ hashthattree help
23
+
24
+ # run the app on the test files
25
+ hashthattree compare ./spec/testfiles/1 ./spec/testfiles/2
26
+ hashthattree compare ./spec/testfiles/1 ./spec/testfiles/2 csv
27
+ hashthattree compare ./spec/testfiles/1 ./spec/testfiles/2 html
28
+ hashthattree compare ./spec/testfiles/1 ./spec/testfiles/2 json
29
+
30
+
31
+ ## Creating Documentation
32
+ Run the following command to generate the documantation
33
+
34
+ rdoc --exclude spec/testfiles
35
+
36
+ ## Create a gem
37
+
38
+ Build and Test Locally
39
+ -gem build hash-that-tree.gemspec
40
+ -gem install hash-that-tree-X.X.X # where X.X.X is the version of the compiled gemspec
41
+ -hashthattree
42
+
43
+ Build and deploy to rubygems.org
44
+ -gem update --system
45
+ -gem build hash-that-tree.gemspec
46
+ -gem push hash-that-tree-0.0.1.gem # where X.X.X is the version of the compiled gemspec
47
+
48
+ ## Contributing
49
+
50
+ 1. Fork it
51
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
52
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
53
+ 4. Push to the branch (`git push origin my-new-feature`)
54
+ 5. Create new Pull Request
55
+
56
+ ##References
57
+
58
+ Looking into bundling with https://github.com/radar/guides/blob/master/gem-development.md
59
+ http://whatisthor.com/
60
+
61
+ ## TODO
62
+
63
+ I have a few items to do in upcoming releases
64
+ * Add Unit Tests
65
+ * Allow to be used as an API as well as a Command Line Tool
66
+ * Allow multiple folders to be specified
67
+ * Add folder recursion option
68
+ * Add SHA1
69
+
data/bin/hashthattree CHANGED
@@ -1 +1 @@
1
- require_relative '../lib/cli'
1
+ require_relative '../lib/cli'
@@ -1,22 +1,24 @@
1
- # -*- encoding: utf-8 -*-
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
-
5
- Gem::Specification.new do |gem|
6
- gem.name = "hash-that-tree"
7
- gem.version = "0.1.0"
8
- gem.authors = ["John Ryan"]
9
- gem.email = ["555john@gmail.com"]
10
- gem.description = "Command line app that compares the MD5 hashes of the files in different folders"
11
- gem.summary = "Allows the user to enter folder locations iterating through the files, creating and comparing the MD5 hashes of the files with the same name"
12
- gem.homepage = "http://github.com/jnyryan/hash-that-tree"
13
- gem.extra_rdoc_files = [ "LICENSE.txt", "README.md" ]
14
- gem.files = `git ls-files`.split($/)
15
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
- gem.executable = 'hashthattree'
17
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
- gem.require_paths = ["lib"]
19
- gem.rdoc_options << '--title' << 'Rake -- Ruby Make' << '--main' << 'README' << '--line-numbers'
20
-
21
- gem.add_dependency "thor"
22
- end
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = %q{hash-that-tree}
7
+ gem.version = "0.1.1"
8
+ gem.authors = ["John Ryan"]
9
+ gem.email = ["555john@gmail.com"]
10
+ gem.description = %q{Command line app that compares the MD5 hashes of the files in different folders}
11
+ gem.summary = %q{Allows the user to enter folder locations iterating through the files, creating and comparing the MD5 hashes of the files with the same name}
12
+ gem.homepage = %q{http://github.com/jnyryan/hash-that-tree}
13
+
14
+ gem.extra_rdoc_files = ["LICENSE.txt","README.md" ]
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.executable = 'hashthattree'
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+
21
+ gem.rdoc_options << '--exclude spec/testfiles'
22
+
23
+ gem.add_dependency "thor"
24
+ end
data/lib/cli.rb CHANGED
@@ -1,19 +1,19 @@
1
- require 'thor'
2
- require_relative 'compare'
3
-
4
- # Command Line Program that takes two directories and creates a MD5 hash for every file contained within.<br/>
5
- # It then builds a result set that compares files with the same name and allows for them to be outputted
6
- # as a csv string
7
- module HashThatTree
8
- #This class controls the Command Line Interface
9
- class CLI < Thor
10
- #Create a hash of all files in the folders, compare them and output the results in CSV format
11
- desc "compare FOLDER1 FOLDER2", "Create a hash of all files in the folders, compare them and output the results in the specified format"
12
- def compare(folder1, folder2, output=:csv)
13
- htt = CompareMD5.new(folder1, folder2, output)
14
- htt.compare
15
- htt.display_results
16
- end
17
- end
18
- CLI.start(ARGV)
1
+ require 'thor'
2
+ require_relative 'compare'
3
+
4
+ # Command Line Program that takes two directories and creates a MD5 hash for every file contained within.<br/>
5
+ # It then builds a result set that compares files with the same name and allows for them to be outputted
6
+ # as a csv string
7
+ module HashThatTree
8
+ #This class controls the Command Line Interface
9
+ class CLI < Thor
10
+ #Create a hash of all files in the folders, compare them and output the results in CSV format
11
+ desc "compare FOLDER1 FOLDER2", "Create a hash of all files in the folders, compare them and output the results in the specified format"
12
+ def compare(folder1, folder2, output=:csv)
13
+ htt = CompareMD5.new(folder1, folder2, output)
14
+ htt.compare
15
+ htt.display_results
16
+ end
17
+ end
18
+ CLI.start(ARGV)
19
19
  end
data/lib/compare.rb CHANGED
@@ -1,120 +1,120 @@
1
- require 'digest/md5'
2
-
3
- # Author:: John Ryan (mailto:555john@gmail.com)
4
- # Copyright:: Copyright (c) 2012 John Ryan
5
- # License:: Distributes under the same terms as Ruby
6
-
7
- module HashThatTree
8
-
9
- # This class accepts two folders and provides methods to iterate
10
- # through them creating a hash of each file within and can display
11
- # the results for analysis
12
- class CompareMD5
13
- attr_accessor :folder1 #path to folder containing files to hash
14
- attr_accessor :folder2 #path to folder containing files to hash to be compared to folder1
15
- attr_accessor :format #the format to output the results to. csv, html or json
16
-
17
- #initialize the class with the folders to be compared
18
- def initialize(folder1, folder2, format)
19
- @folder1 = folder1
20
- @folder2 = folder2
21
- @format = format
22
- @filehash = Hash.new
23
- validate
24
- end
25
-
26
-
27
- # Validates the input ensuring the arguments are both valid folders
28
- def validate
29
- if(folder1==nil) || (folder1=="") || !Dir.exists?(folder1)
30
- puts "a valid folder path is required as argument 1"
31
- exit
32
- end
33
-
34
- if(folder2==nil) || (folder2=="") || !Dir.exists?(folder2)
35
- puts "a valid folder path is required as argument 2"
36
- exit
37
- end
38
-
39
- end
40
-
41
- # Iterates through the folders and creates a FileHashResults object containing the
42
- # results of the comparisson
43
- def compare
44
-
45
- Dir.foreach(@folder1) do |item|
46
- begin
47
- next if item == '.' or item == '..'
48
- fullfilename = File.expand_path(@folder1, item)
49
- the_hash = Digest::MD5.hexdigest(File.read(File.join(File.expand_path(@folder1), item)))
50
- item = item.downcase
51
- filedata = FileHashResults.new(item, the_hash, nil)
52
- @filehash[item] = filedata
53
- rescue
54
- #puts "Skipped:#{item.inspect}"
55
- end
56
- end
57
-
58
- Dir.foreach(@folder2) do |item|
59
- begin
60
- next if item == '.' or item == '..'
61
- the_hash = Digest::MD5.hexdigest(File.read(File.join(@folder2, item)))
62
- item = item.downcase
63
- if(@filehash[item]==nil)
64
- filedata = FileHashResults.new(item, nil, the_hash)
65
- @filehash[item] = filedata
66
- next
67
- end
68
- @filehash[item.downcase].file_hash2 = the_hash
69
- rescue
70
- #puts "Skipped:#{item.inspect}"
71
- end
72
- end
73
- end
74
-
75
- #print the contents of the FileHashResults object standard out in the format specified. Default is csv
76
- def display_results()
77
- case @format
78
- when "csv"
79
- display_results_csv
80
- when "html"
81
- display_results_html
82
- when "json"
83
- display_results_json
84
- else
85
- display_results_csv
86
- end
87
- end
88
-
89
- #Prints the results to standard out in the csv format specified.
90
- def display_results_csv
91
- puts "FileName,#{@folder1},#{@folder2},Are Equal"
92
- @filehash.each{ |key, value| puts "#{value.file_name},#{value.file_hash1},#{value.file_hash2}, #{value.file_hash1==value.file_hash2}" }
93
- end
94
-
95
- #Prints the results to standard out in the csv format specified.
96
- def display_results_html
97
- output ="<!DOCTYPE html><html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title></title></head><body>"
98
- output.concat("<table><thead><tr><td>FileName</td></tr><tr><td>#{@folder1}</td></tr><tr><td>#{@folder2}</td></tr><tr><td>Equal</td></tr></thead>")
99
- @filehash.each{ |key, value| output.concat("<tbody><tr><td>#{value.file_name}</td></tr><tr><td>#{value.file_hash1}</td></tr><tr><td>#{value.file_hash2}</td></tr><tr><td>#{value.file_hash1==value.file_hash2}</td></tr>")}
100
- output.concat("</tbody></table></body></html>")
101
- puts output
102
- end
103
-
104
- #Prints the results to standard out in the csv format specified.
105
- def display_results_json
106
- puts @filehash
107
- end
108
-
109
- end
110
-
111
- #Container for the results of the file comparisson
112
- class FileHashResults
113
- attr_accessor :file_name, :file_hash1, :file_hash2
114
- def initialize(file_name, file_hash1, file_hash2)
115
- @file_name = file_name
116
- @file_hash1 = file_hash1
117
- @file_hash2 = file_hash2
118
- end
119
- end
120
- end
1
+ require 'digest/md5'
2
+
3
+ # Author:: John Ryan (mailto:555john@gmail.com)
4
+ # Copyright:: Copyright (c) 2012 John Ryan
5
+ # License:: Distributes under the same terms as Ruby
6
+
7
+ module HashThatTree
8
+
9
+ # This class accepts two folders and provides methods to iterate
10
+ # through them creating a hash of each file within and can display
11
+ # the results for analysis
12
+ class CompareMD5
13
+ attr_accessor :folder1 #path to folder containing files to hash
14
+ attr_accessor :folder2 #path to folder containing files to hash to be compared to folder1
15
+ attr_accessor :format #the format to output the results to. csv, html or json
16
+
17
+ #initialize the class with the folders to be compared
18
+ def initialize(folder1, folder2, format)
19
+ @folder1 = folder1
20
+ @folder2 = folder2
21
+ @format = format
22
+ @filehash = Hash.new
23
+ validate
24
+ end
25
+
26
+
27
+ # Validates the input ensuring the arguments are both valid folders
28
+ def validate
29
+ if(folder1==nil) || (folder1=="") || !Dir.exists?(folder1)
30
+ puts "a valid folder path is required as argument 1"
31
+ exit
32
+ end
33
+
34
+ if(folder2==nil) || (folder2=="") || !Dir.exists?(folder2)
35
+ puts "a valid folder path is required as argument 2"
36
+ exit
37
+ end
38
+
39
+ end
40
+
41
+ # Iterates through the folders and creates a FileHashResults object containing the
42
+ # results of the comparisson
43
+ def compare
44
+
45
+ Dir.foreach(@folder1) do |item|
46
+ begin
47
+ next if item == '.' or item == '..'
48
+ fullfilename = File.expand_path(@folder1, item)
49
+ the_hash = Digest::MD5.hexdigest(File.read(File.join(File.expand_path(@folder1), item)))
50
+ item = item.downcase
51
+ filedata = FileHashResults.new(item, the_hash, nil)
52
+ @filehash[item] = filedata
53
+ rescue
54
+ #puts "Skipped:#{item.inspect}"
55
+ end
56
+ end
57
+
58
+ Dir.foreach(@folder2) do |item|
59
+ begin
60
+ next if item == '.' or item == '..'
61
+ the_hash = Digest::MD5.hexdigest(File.read(File.join(@folder2, item)))
62
+ item = item.downcase
63
+ if(@filehash[item]==nil)
64
+ filedata = FileHashResults.new(item, nil, the_hash)
65
+ @filehash[item] = filedata
66
+ next
67
+ end
68
+ @filehash[item.downcase].file_hash2 = the_hash
69
+ rescue
70
+ #puts "Skipped:#{item.inspect}"
71
+ end
72
+ end
73
+ end
74
+
75
+ #print the contents of the FileHashResults object standard out in the format specified. Default is csv
76
+ def display_results()
77
+ case @format
78
+ when "csv"
79
+ display_results_csv
80
+ when "html"
81
+ display_results_html
82
+ when "json"
83
+ display_results_json
84
+ else
85
+ display_results_csv
86
+ end
87
+ end
88
+
89
+ #Prints the results to standard out in the csv format specified.
90
+ def display_results_csv
91
+ puts "FileName,#{@folder1},#{@folder2},Are Equal"
92
+ @filehash.each{ |key, value| puts "#{value.file_name},#{value.file_hash1},#{value.file_hash2}, #{value.file_hash1==value.file_hash2}" }
93
+ end
94
+
95
+ #Prints the results to standard out in the csv format specified.
96
+ def display_results_html
97
+ output ="<!DOCTYPE html><html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title></title></head><body>"
98
+ output.concat("<table><thead><tr><td>FileName</td></tr><tr><td>#{@folder1}</td></tr><tr><td>#{@folder2}</td></tr><tr><td>Equal</td></tr></thead>")
99
+ @filehash.each{ |key, value| output.concat("<tbody><tr><td>#{value.file_name}</td></tr><tr><td>#{value.file_hash1}</td></tr><tr><td>#{value.file_hash2}</td></tr><tr><td>#{value.file_hash1==value.file_hash2}</td></tr>")}
100
+ output.concat("</tbody></table></body></html>")
101
+ puts output
102
+ end
103
+
104
+ #Prints the results to standard out in the csv format specified.
105
+ def display_results_json
106
+ puts @filehash
107
+ end
108
+
109
+ end
110
+
111
+ #Container for the results of the file comparisson
112
+ class FileHashResults
113
+ attr_accessor :file_name, :file_hash1, :file_hash2
114
+ def initialize(file_name, file_hash1, file_hash2)
115
+ @file_name = file_name
116
+ @file_hash1 = file_hash1
117
+ @file_hash2 = file_hash2
118
+ end
119
+ end
120
+ end
@@ -1 +1 @@
1
- hello
1
+ hello
@@ -1 +1 @@
1
- hello
1
+ hello
@@ -1,2 +1,2 @@
1
- hello
2
- Hello
1
+ hello
2
+ Hello
@@ -1,2 +1,2 @@
1
- hello
2
- goodbye
1
+ hello
2
+ goodbye
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hash-that-tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -62,11 +62,7 @@ homepage: http://github.com/jnyryan/hash-that-tree
62
62
  licenses: []
63
63
  post_install_message:
64
64
  rdoc_options:
65
- - --title
66
- - Rake -- Ruby Make
67
- - --main
68
- - README
69
- - --line-numbers
65
+ - --exclude spec/testfiles
70
66
  require_paths:
71
67
  - lib
72
68
  required_ruby_version: !ruby/object:Gem::Requirement