ectd_check 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Args: PATH
4
+ #
5
+ # Interactively will parse index.xml and all sub xml files and check linked leafs for md5 mismatch's. Will Offer to correct them if necessary.
6
+
7
+ def help
8
+ puts "ECTD Checker v: 0.0.1"
9
+ puts "Licensed under GPLv2"
10
+ puts "Contact Russell Osborne of Scilucent LLC for other uses rposborne {at} scilucent.com"
11
+ puts "Usage: checkectd path"
12
+ exit
13
+ end
14
+
15
+ args = ARGV.dup
16
+ ARGV.clear
17
+ path = args.shift.strip rescue help
18
+ puts "Checking all Leafs of Submission #{path}"
19
+
20
+ require 'nokogiri'
21
+ require 'digest/md5'
22
+
23
+ files_to_check = Dir[File.join("#{path}","**","*.xml")]
24
+ count_failed_files = 0
25
+ files_to_check.each do |file|
26
+ f = File.open(file)
27
+
28
+ save_flag = false
29
+ doc = Nokogiri::XML(f)
30
+ leafs = doc.css('leaf')
31
+
32
+ leafs.each do |leaf|
33
+ leaf_href_full_path = File.join( File.dirname(file) , leaf.attribute('href'))
34
+ calculated_checksum = Digest::MD5.hexdigest(File.read(leaf_href_full_path))
35
+ leaf_checksum = leaf.attribute("checksum")
36
+
37
+ if calculated_checksum.to_s.chomp != leaf_checksum.to_s.chomp
38
+ save_flag = true
39
+ count_failed_files += 1
40
+ leaf['checksum'] = calculated_checksum
41
+ puts "md5 mismatch #{calculated_checksum} != #{leaf_checksum} for file #{leaf.attribute('href')}"
42
+ end
43
+ end
44
+
45
+ if save_flag
46
+ puts ARGV
47
+ puts "Checkusm Errors Found in #{file}. Would you like us to update them (Y/n)?"
48
+ user_confirm = $stdin.gets.chomp
49
+ if user_confirm == "Y"
50
+ puts "updating bad checksums in #{file}"
51
+ File.open(file, 'w') {|f| f.write(doc.to_xml) }
52
+ end
53
+ user_confirm = nil
54
+ end
55
+
56
+ f.close
57
+ end
58
+
59
+ index_calculated_checksum = Digest::MD5.file(File.join("#{path}", "index.xml"))
60
+ index_checksum = File.read(File.join("#{path}","index-md5.txt"))
61
+
62
+ if index_calculated_checksum != index_checksum
63
+ count_failed_files += 1
64
+ puts "index.xml md5 mismatch. Would you like us to update them (Y/n)?"
65
+ user_confirm = $stdin.gets.chomp
66
+ if user_confirm == "Y"
67
+ puts "updating bad checksums in #{path}/index-md5.txt"
68
+ File.open(File.join("#{path}","index-md5.txt"), 'w') {|f| f.write(index_calculated_checksum) }
69
+ end
70
+ end
71
+
72
+ puts "#{count_failed_files} bad checksums"
73
+
74
+
75
+
@@ -10,8 +10,8 @@ Gem::Specification.new do |gem|
10
10
  gem.email = ["russell@burningpony.com"]
11
11
  gem.description = %q{A simple command line tool to check and repair md5 hashes based upon the FDA eCTD specification}
12
12
  gem.summary = %q{A simple command line tool to check and repair md5 hashes based upon the FDA eCTD specification. It will interactively repair the md5's and list errors found.}
13
- gem.homepage = "http://scilucent.com"
14
- gem.add_dependency "nokogiri"
13
+ gem.homepage = "https://github.com/rposborne/ectd_check"
14
+ gem.add_dependency "nokogiri"
15
15
 
16
16
  gem.files = `git ls-files`.split($/)
17
17
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -1,3 +1,3 @@
1
1
  module EctdCheck
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ectd_check
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -31,7 +31,8 @@ description: A simple command line tool to check and repair md5 hashes based upo
31
31
  the FDA eCTD specification
32
32
  email:
33
33
  - russell@burningpony.com
34
- executables: []
34
+ executables:
35
+ - checkectd
35
36
  extensions: []
36
37
  extra_rdoc_files: []
37
38
  files:
@@ -40,10 +41,11 @@ files:
40
41
  - LICENSE.txt
41
42
  - README.md
42
43
  - Rakefile
44
+ - bin/checkectd
43
45
  - ectd_check.gemspec
44
46
  - lib/ectd_check.rb
45
47
  - lib/ectd_check/version.rb
46
- homepage: http://scilucent.com
48
+ homepage: https://github.com/rposborne/ectd_check
47
49
  licenses: []
48
50
  post_install_message:
49
51
  rdoc_options: []