hash-that-tree 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,73 +1,73 @@
1
- require 'digest/md5'
2
- require 'mustache'
3
- require 'json'
4
- require_relative '../templates/displaytemplates'
5
-
6
- # Author:: John Ryan (mailto:555john@gmail.com)
7
- # Copyright:: Copyright (c) 2012 John Ryan
8
- # License:: Distributes under the same terms as Ruby
9
- module HashThatTree
10
-
11
- class Display
12
- attr_accessor :format #the format to output the results to. csv, html or json
13
- attr_accessor :file_data #array of files and associated hashes
14
- attr_accessor :error_data #array of files that could not be processed
15
-
16
- #initialize the class with the folders to be compared
17
- def initialize(options, error_data, *file_data )
18
- @format = options['output']
19
- @displayerrors = options['errors']
20
- @file_data = file_data
21
- @error_data = error_data
22
- p @error_data
23
- end
24
-
25
- #print the contents of the FileHashResults object standard out in the format specified. Default is csv
26
- def display_results()
27
-
28
- case @format
29
- when "csv"
30
- display_results_csv
31
- when "html"
32
- display_results_html
33
- when "json"
34
- display_results_json
35
- else
36
- display_results_std
37
- end
38
- end
39
-
40
- #Prints the results to standard out in the csv format specified.
41
- def display_results_std
42
- puts Mustache.render(StandardTemplate, :filedetails => @file_data[0]);
43
- if(@displayerrors)
44
- puts Mustache.render(StandardTemplate, :errordetails => @error_data[0]);
45
- end
46
- end
47
-
48
- #Prints the results to standard out in the csv format specified.
49
- def display_results_csv
50
- puts Mustache.render(CsvTemplate, :filedetails => @file_data[0]);
51
- if(@displayerrors)
52
- puts Mustache.render(CsvTemplate, :filedetails => @error_data[0]);
53
- end
54
- end
55
-
56
- #Prints the results to standard out in the csv format specified.
57
- def display_results_html
58
- puts Mustache.render(HtmlTemplate, :filedetails => @file_data[0]);
59
- if(@displayerrors)
60
- puts Mustache.render(HtmlTemplate, :filedetails => @error_data[0]);
61
- end
62
- end
63
-
64
- #Prints the results to standard out in the csv format specified.
65
- def display_results_json
66
- puts JSON.pretty_generate(@file_data)
67
- if(@displayerrors)
68
- puts JSON.pretty_generate(@error_data)
69
- end
70
- end
71
-
72
- end
73
- end
1
+ require 'digest/md5'
2
+ require 'mustache'
3
+ require 'json'
4
+ require_relative '../templates/displaytemplates'
5
+
6
+ # Author:: John Ryan (mailto:555john@gmail.com)
7
+ # Copyright:: Copyright (c) 2012 John Ryan
8
+ # License:: Distributes under the same terms as Ruby
9
+ module HashThatTree
10
+
11
+ class Display
12
+ attr_accessor :format #the format to output the results to. csv, html or json
13
+ attr_accessor :file_data #array of files and associated hashes
14
+ attr_accessor :error_data #array of files that could not be processed
15
+
16
+ #initialize the class with the folders to be compared
17
+ def initialize(options, error_data, *file_data )
18
+ @format = options['output']
19
+ @displayerrors = options['errors']
20
+ @file_data = file_data
21
+ @error_data = error_data
22
+ p @error_data
23
+ end
24
+
25
+ #print the contents of the FileHashResults object standard out in the format specified. Default is csv
26
+ def display_results()
27
+
28
+ case @format
29
+ when "csv"
30
+ display_results_csv
31
+ when "html"
32
+ display_results_html
33
+ when "json"
34
+ display_results_json
35
+ else
36
+ display_results_std
37
+ end
38
+ end
39
+
40
+ #Prints the results to standard out in the csv format specified.
41
+ def display_results_std
42
+ puts Mustache.render(StandardTemplate, :filedetails => @file_data[0]);
43
+ if(@displayerrors)
44
+ puts Mustache.render(StandardTemplate, :errordetails => @error_data[0]);
45
+ end
46
+ end
47
+
48
+ #Prints the results to standard out in the csv format specified.
49
+ def display_results_csv
50
+ puts Mustache.render(CsvTemplate, :filedetails => @file_data[0]);
51
+ if(@displayerrors)
52
+ puts Mustache.render(CsvTemplate, :filedetails => @error_data[0]);
53
+ end
54
+ end
55
+
56
+ #Prints the results to standard out in the csv format specified.
57
+ def display_results_html
58
+ puts Mustache.render(HtmlTemplate, :filedetails => @file_data[0]);
59
+ if(@displayerrors)
60
+ puts Mustache.render(HtmlTemplate, :filedetails => @error_data[0]);
61
+ end
62
+ end
63
+
64
+ #Prints the results to standard out in the csv format specified.
65
+ def display_results_json
66
+ puts JSON.pretty_generate(@file_data)
67
+ if(@displayerrors)
68
+ puts JSON.pretty_generate(@error_data)
69
+ end
70
+ end
71
+
72
+ end
73
+ end
@@ -1,53 +1,53 @@
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
- module HashThatTree
7
- # This class accepts a folder array and provides methods to iterate
8
- # through all files in the folder creating a hash of each file within.
9
- # The results are displayed to Standard Out in csv, html, json or standard format
10
- class HashIt
11
- attr_accessor :format #the format to output the results to - standard, csv, html or json
12
- attr_accessor :folders #path to folder containing files to hash
13
- attr_accessor :file_data #the container for the hashing results
14
- attr_accessor :error_data #the container for the files that could not be processed
15
-
16
- #initialize the class with the folders to be processed
17
- def initialize(options, folders )
18
- @format = options['output']
19
- @folders = folders
20
- @file_data = []
21
- @error_data = []
22
- validate
23
- end
24
-
25
- # Validates the supplied folders ensuring they exist
26
- def validate
27
- @folders.each do |item|
28
- if(item==nil) || (item=="") || !Dir.exists?(item)
29
- puts "a valid folder path is required as argument #{item}"
30
- exit
31
- end
32
- end
33
- end
34
-
35
- # Iterates through the folders and creates a FileHashResults object containing the
36
- # results of the comparisson
37
- def create_hash_results
38
-
39
- @folders.each do |folder|
40
- Dir.foreach(folder) do |item|
41
- begin
42
- next if item == '.' or item == '..'
43
- fullfilename = File.expand_path(folder, item)
44
- the_hash = Digest::MD5.hexdigest(File.read(File.join(File.expand_path(folder), item.downcase)))
45
- @file_data << {:filename=>item, :folder=>folder, :filehash => the_hash}
46
- rescue
47
- @error_data << {:error=>"Skipped#{File.expand_path(folder, item)}"}
48
- end
49
- end
50
- end
51
- end
52
- end
53
- 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
+ module HashThatTree
7
+ # This class accepts a folder array and provides methods to iterate
8
+ # through all files in the folder creating a hash of each file within.
9
+ # The results are displayed to Standard Out in csv, html, json or standard format
10
+ class HashIt
11
+ attr_accessor :format #the format to output the results to - standard, csv, html or json
12
+ attr_accessor :folders #path to folder containing files to hash
13
+ attr_accessor :file_data #the container for the hashing results
14
+ attr_accessor :error_data #the container for the files that could not be processed
15
+
16
+ #initialize the class with the folders to be processed
17
+ def initialize(options, folders )
18
+ @format = options['output']
19
+ @folders = folders
20
+ @file_data = []
21
+ @error_data = []
22
+ validate
23
+ end
24
+
25
+ # Validates the supplied folders ensuring they exist
26
+ def validate
27
+ @folders.each do |item|
28
+ if(item==nil) || (item=="") || !Dir.exists?(item)
29
+ puts "a valid folder path is required as argument #{item}"
30
+ exit
31
+ end
32
+ end
33
+ end
34
+
35
+ # Iterates through the folders and creates a FileHashResults object containing the
36
+ # results of the comparisson
37
+ def create_hash_results
38
+
39
+ @folders.each do |folder|
40
+ Dir.foreach(folder) do |item|
41
+ begin
42
+ next if item == '.' or item == '..'
43
+ fullfilename = File.expand_path(folder, item)
44
+ the_hash = Digest::MD5.hexdigest(File.read(File.join(File.expand_path(folder), item.downcase)))
45
+ @file_data << {:filename=>item, :folder=>folder, :filehash => the_hash}
46
+ rescue
47
+ @error_data << {:error=>"Skipped#{File.expand_path(folder, item)}"}
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ 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
@@ -1,38 +1,38 @@
1
- StandardTemplate =<<-TEMPLATE
2
- File Hash\t\t\t\tFile Name\t\t\tFolder
3
- {{#filedetails}}
4
- {{filehash}}\t{{filename}}\t\t{{folder}}
5
- {{/filedetails}}
6
- TEMPLATE
7
-
8
- HtmlTemplate =<<-TEMPLATE
9
- <!DOCTYPE html>
10
- <html xmlns=\"http://www.w3.org/1999/xhtml\">
11
- <head>
12
- <title></title>
13
- </head>
14
- <body>
15
- <table>
16
- <tr>
17
- <th>File Hash</th>
18
- <th>File Name</th>
19
- <th>Folder</th>
20
- </tr>
21
- {{#filedetails}}
22
- <tr>
23
- <td>{{filehash}}</td>
24
- <td>{{filename}}</td>
25
- <td>{{folder}}</td>
26
- </tr>
27
- {{/filedetails}}
28
- </table>
29
- </body>
30
- </html>
31
- TEMPLATE
32
-
33
- CsvTemplate=<<-TEMPLATE
34
- File Hash,File Name,Folder,
35
- {{#filedetails}}
36
- {{filehash}},{{filename}},{{folder}},
37
- {{/filedetails}}
38
- TEMPLATE
1
+ StandardTemplate =<<-TEMPLATE
2
+ File Hash\t\t\t\tFile Name\t\t\tFolder
3
+ {{#filedetails}}
4
+ {{filehash}}\t{{filename}}\t\t{{folder}}
5
+ {{/filedetails}}
6
+ TEMPLATE
7
+
8
+ HtmlTemplate =<<-TEMPLATE
9
+ <!DOCTYPE html>
10
+ <html xmlns=\"http://www.w3.org/1999/xhtml\">
11
+ <head>
12
+ <title></title>
13
+ </head>
14
+ <body>
15
+ <table>
16
+ <tr>
17
+ <th>File Hash</th>
18
+ <th>File Name</th>
19
+ <th>Folder</th>
20
+ </tr>
21
+ {{#filedetails}}
22
+ <tr>
23
+ <td>{{filehash}}</td>
24
+ <td>{{filename}}</td>
25
+ <td>{{folder}}</td>
26
+ </tr>
27
+ {{/filedetails}}
28
+ </table>
29
+ </body>
30
+ </html>
31
+ TEMPLATE
32
+
33
+ CsvTemplate=<<-TEMPLATE
34
+ File Hash,File Name,Folder,
35
+ {{#filedetails}}
36
+ {{filehash}},{{filename}},{{folder}},
37
+ {{/filedetails}}
38
+ TEMPLATE
data/test.htm CHANGED
@@ -1,94 +1,94 @@
1
- "./spec/testfiles/1"
2
- "./spec/testfiles/2"
3
- Skipped:"fileA.txt"
4
- Skipped:"fileB.txt"
5
- Skipped:"fileA.txt"
6
- Skipped:"fileB.txt"
7
- <table>
8
- <tr>
9
- <th>File Name</th>
10
- <th>Folder</th>
11
- <th>File Hash</th>
12
- </tr>
13
- <tr>
14
- <td>file3.txt</td>
15
- <td>./spec/testfiles/1</td>
16
- <td>b1946ac92492d2347c6235b4d2611184</td>
17
- </tr>
18
- <tr>
19
- <td>file1.txt</td>
20
- <td>./spec/testfiles/1</td>
21
- <td>d41d8cd98f00b204e9800998ecf8427e</td>
22
- </tr>
23
- <tr>
24
- <td>file2.txt</td>
25
- <td>./spec/testfiles/1</td>
26
- <td>d41d8cd98f00b204e9800998ecf8427e</td>
27
- </tr>
28
- <tr>
29
- <td>file4.txt</td>
30
- <td>./spec/testfiles/1</td>
31
- <td>b1946ac92492d2347c6235b4d2611184</td>
32
- </tr>
33
- <tr>
34
- <td>file3.txt</td>
35
- <td>./spec/testfiles/2</td>
36
- <td>d164cd9dcf2b16147c4fe8ca3db49a45</td>
37
- </tr>
38
- <tr>
39
- <td>file1.txt</td>
40
- <td>./spec/testfiles/2</td>
41
- <td>d41d8cd98f00b204e9800998ecf8427e</td>
42
- </tr>
43
- <tr>
44
- <td>file2.txt</td>
45
- <td>./spec/testfiles/2</td>
46
- <td>d41d8cd98f00b204e9800998ecf8427e</td>
47
- </tr>
48
- <tr>
49
- <td>file4.txt</td>
50
- <td>./spec/testfiles/2</td>
51
- <td>6e175f736c6eb485932e8f3b8fda535a</td>
52
- </tr>
53
- <tr>
54
- <td>file3.txt</td>
55
- <td>./spec/testfiles/1</td>
56
- <td>b1946ac92492d2347c6235b4d2611184</td>
57
- </tr>
58
- <tr>
59
- <td>file1.txt</td>
60
- <td>./spec/testfiles/1</td>
61
- <td>d41d8cd98f00b204e9800998ecf8427e</td>
62
- </tr>
63
- <tr>
64
- <td>file2.txt</td>
65
- <td>./spec/testfiles/1</td>
66
- <td>d41d8cd98f00b204e9800998ecf8427e</td>
67
- </tr>
68
- <tr>
69
- <td>file4.txt</td>
70
- <td>./spec/testfiles/1</td>
71
- <td>b1946ac92492d2347c6235b4d2611184</td>
72
- </tr>
73
- <tr>
74
- <td>file3.txt</td>
75
- <td>./spec/testfiles/2</td>
76
- <td>d164cd9dcf2b16147c4fe8ca3db49a45</td>
77
- </tr>
78
- <tr>
79
- <td>file1.txt</td>
80
- <td>./spec/testfiles/2</td>
81
- <td>d41d8cd98f00b204e9800998ecf8427e</td>
82
- </tr>
83
- <tr>
84
- <td>file2.txt</td>
85
- <td>./spec/testfiles/2</td>
86
- <td>d41d8cd98f00b204e9800998ecf8427e</td>
87
- </tr>
88
- <tr>
89
- <td>file4.txt</td>
90
- <td>./spec/testfiles/2</td>
91
- <td>6e175f736c6eb485932e8f3b8fda535a</td>
92
- </tr>
93
-
94
- </table>
1
+ "./spec/testfiles/1"
2
+ "./spec/testfiles/2"
3
+ Skipped:"fileA.txt"
4
+ Skipped:"fileB.txt"
5
+ Skipped:"fileA.txt"
6
+ Skipped:"fileB.txt"
7
+ <table>
8
+ <tr>
9
+ <th>File Name</th>
10
+ <th>Folder</th>
11
+ <th>File Hash</th>
12
+ </tr>
13
+ <tr>
14
+ <td>file3.txt</td>
15
+ <td>./spec/testfiles/1</td>
16
+ <td>b1946ac92492d2347c6235b4d2611184</td>
17
+ </tr>
18
+ <tr>
19
+ <td>file1.txt</td>
20
+ <td>./spec/testfiles/1</td>
21
+ <td>d41d8cd98f00b204e9800998ecf8427e</td>
22
+ </tr>
23
+ <tr>
24
+ <td>file2.txt</td>
25
+ <td>./spec/testfiles/1</td>
26
+ <td>d41d8cd98f00b204e9800998ecf8427e</td>
27
+ </tr>
28
+ <tr>
29
+ <td>file4.txt</td>
30
+ <td>./spec/testfiles/1</td>
31
+ <td>b1946ac92492d2347c6235b4d2611184</td>
32
+ </tr>
33
+ <tr>
34
+ <td>file3.txt</td>
35
+ <td>./spec/testfiles/2</td>
36
+ <td>d164cd9dcf2b16147c4fe8ca3db49a45</td>
37
+ </tr>
38
+ <tr>
39
+ <td>file1.txt</td>
40
+ <td>./spec/testfiles/2</td>
41
+ <td>d41d8cd98f00b204e9800998ecf8427e</td>
42
+ </tr>
43
+ <tr>
44
+ <td>file2.txt</td>
45
+ <td>./spec/testfiles/2</td>
46
+ <td>d41d8cd98f00b204e9800998ecf8427e</td>
47
+ </tr>
48
+ <tr>
49
+ <td>file4.txt</td>
50
+ <td>./spec/testfiles/2</td>
51
+ <td>6e175f736c6eb485932e8f3b8fda535a</td>
52
+ </tr>
53
+ <tr>
54
+ <td>file3.txt</td>
55
+ <td>./spec/testfiles/1</td>
56
+ <td>b1946ac92492d2347c6235b4d2611184</td>
57
+ </tr>
58
+ <tr>
59
+ <td>file1.txt</td>
60
+ <td>./spec/testfiles/1</td>
61
+ <td>d41d8cd98f00b204e9800998ecf8427e</td>
62
+ </tr>
63
+ <tr>
64
+ <td>file2.txt</td>
65
+ <td>./spec/testfiles/1</td>
66
+ <td>d41d8cd98f00b204e9800998ecf8427e</td>
67
+ </tr>
68
+ <tr>
69
+ <td>file4.txt</td>
70
+ <td>./spec/testfiles/1</td>
71
+ <td>b1946ac92492d2347c6235b4d2611184</td>
72
+ </tr>
73
+ <tr>
74
+ <td>file3.txt</td>
75
+ <td>./spec/testfiles/2</td>
76
+ <td>d164cd9dcf2b16147c4fe8ca3db49a45</td>
77
+ </tr>
78
+ <tr>
79
+ <td>file1.txt</td>
80
+ <td>./spec/testfiles/2</td>
81
+ <td>d41d8cd98f00b204e9800998ecf8427e</td>
82
+ </tr>
83
+ <tr>
84
+ <td>file2.txt</td>
85
+ <td>./spec/testfiles/2</td>
86
+ <td>d41d8cd98f00b204e9800998ecf8427e</td>
87
+ </tr>
88
+ <tr>
89
+ <td>file4.txt</td>
90
+ <td>./spec/testfiles/2</td>
91
+ <td>6e175f736c6eb485932e8f3b8fda535a</td>
92
+ </tr>
93
+
94
+ </table>