bagit 0.4.1 → 0.4.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ac8457e8aaeb0c0ebf47ab69bd684ef53c39aa06
4
- data.tar.gz: f2d8519577d2eca73c369c4523ebf34ccf1b034d
3
+ metadata.gz: fad8acbb5bb1291e22988803875886a17a8fb569
4
+ data.tar.gz: a85c86ea03545525a408d29b82b6ffdc0de7ac2b
5
5
  SHA512:
6
- metadata.gz: 4b57162bc669f4ae8a739d51a3907f1b053b3980cc5b3331521b2419e21ecc10e12eb32a561ed233955920276ba9ee5e7e5af1baf28a705b84df36b3a6c28008
7
- data.tar.gz: 0ab1ee1aa64b9917bb493aaf94976ab5459680d1fde980dca3632684ddee968320d821c8cb00bc041b3905261db7335d7b2592d33fab557616a1f5fbed940b9c
6
+ metadata.gz: cd98d4c2f70f6cd00d450981657e80e54ba0cb8c6394dd8b7a68069b736be44a4c23780c8bc98cb306c5e62afd3709a15f34c42df45d8613499651fca42923b8
7
+ data.tar.gz: 42ce0063033e43b1f328785f715b8b4e08a0bca0ae3186e4a505c2cef8a91b8adb694d70276f6abd3da0ab1a5b486c6b8d7651decf76fc86c1fb22230210c3c8
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.required_ruby_version = '~> 2.0'
17
-
17
+
18
18
  spec.add_dependency 'validatable', '~> 1.6'
19
19
  spec.add_dependency 'docopt', '~> 0.5.0'
20
20
 
@@ -22,6 +22,8 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency 'rake', '~> 10.4'
23
23
  spec.add_development_dependency 'rspec', '~> 3'
24
24
  spec.add_development_dependency 'coveralls'
25
+ spec.add_development_dependency 'pry'
26
+ spec.add_development_dependency 'pry-byebug'
25
27
 
26
28
  spec.files = `git ls-files`.split($/)
27
29
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
data/bin/bagit CHANGED
@@ -3,22 +3,23 @@
3
3
  require 'bagit'
4
4
  require 'docopt'
5
5
  require 'logger'
6
-
6
+ require 'pry'
7
7
  logger = Logger.new(STDOUT)
8
8
 
9
9
  doc = <<DOCOPT
10
10
  BagIt.
11
11
 
12
- Usage:
13
- bagit add [-f <file>...] [-t <tagfile>...] BAGPATH
12
+ Usage:
13
+ bagit add [-f <file>...] [-t <tagfile>...] [-a <algo>] BAGPATH
14
14
  bagit delete [-f <file>...] [-t <tagfile>...] BAGPATH
15
15
  bagit remove [-t <tagfile>...] BAGPATH
16
- bagit validate [-o] BAGPATH
16
+ bagit validate [-o] BAGPATH
17
17
  bagit manifest [-T] BAGPATH
18
- bagit list [--tags | --all] BAGPATH
18
+ bagit list [--tags | --all] BAGPATH
19
19
  bagit -h | --version
20
20
 
21
21
  Options:
22
+ -a A selected hashing algorithm. (md5, sha1, sha256)
22
23
  -h --help Show this help screen.
23
24
  --version Show version.
24
25
  -f <file> File to add to/delete from bag. Repeatable.
@@ -31,11 +32,11 @@ Options:
31
32
  DOCOPT
32
33
 
33
34
  # Possible commands for bag-info write
34
- #
35
- # bagit new [--source-organization <org>] [--organization-address <org-addr>] [--contact-name <contact>]
36
- # [--contact-phone <phone>] [--contact-email <email>] [--external-description <ext-desc>]
37
- # [--external-identifier <ext-id>] [--group-identifier <group-id>] [--count <count>]
38
- # [--internal-sender-identifier <sender-id>] [--internal-sender-description <sender-desc>]
35
+ #
36
+ # bagit new [--source-organization <org>] [--organization-address <org-addr>] [--contact-name <contact>]
37
+ # [--contact-phone <phone>] [--contact-email <email>] [--external-description <ext-desc>]
38
+ # [--external-identifier <ext-id>] [--group-identifier <group-id>] [--count <count>]
39
+ # [--internal-sender-identifier <sender-id>] [--internal-sender-description <sender-desc>]
39
40
  # [--bag-info-entry <label> <value>] [-f <file>...] [-t <tagfile>...] BAGPATH
40
41
 
41
42
  begin
@@ -86,7 +87,7 @@ begin
86
87
  #TODO: implement delete for data and tag files; remove for tag files.
87
88
 
88
89
  # handle add/delete bag data files
89
- unless opts['-f'].nil?
90
+ unless opts['-f'].nil?
90
91
  #TODO: add files in nested directories
91
92
  opts['-f'].each { |datafile|
92
93
  begin
@@ -98,11 +99,11 @@ begin
98
99
  rescue Exception => e
99
100
  logger.error("Failed operation on bag file: #{e.message}")
100
101
  end
101
- }
102
+ }
102
103
  end
103
104
 
104
105
  # handle adding tag files
105
- unless opts['-t'].nil?
106
+ unless opts['-t'].nil?
106
107
  #TODO: add files in nested directories
107
108
  opts['-t'].each { |tagfile|
108
109
  begin
@@ -126,11 +127,15 @@ begin
126
127
  end
127
128
 
128
129
  # if we haven't quit yet, we need to re-manifest
129
- # only do tags if tag files have been explictly added/removed or it is explictly called
130
+ # only do tags if tag files have been explictly added/removed or it is explictly called
130
131
  bag.tagmanifest! if opts['-T'] or not opts['-t'].nil?
131
- bag.manifest!
132
+
133
+ unless opts['-a'].nil?
134
+ bag.manifest!(algo: opts['<algo>'])
135
+ else
136
+ bag.manifest!
137
+ end
132
138
 
133
139
  rescue Docopt::Exit => e
134
140
  logger.error(e.message.red)
135
141
  end
136
-
@@ -12,7 +12,7 @@ module BagIt
12
12
  return s
13
13
  end
14
14
 
15
-
15
+
16
16
  # All tag files that are bag manifest files (manifest-[algorithm].txt)
17
17
  def manifest_files
18
18
  files = Dir[File.join(@bag_dir, '*')].select { |f|
@@ -27,7 +27,7 @@ module BagIt
27
27
  end
28
28
 
29
29
  # Generate manifest files for all the bag files
30
- def manifest!
30
+ def manifest!(algo: 'default')
31
31
 
32
32
  # nuke all the existing manifest files
33
33
  manifest_files.each { |f| FileUtils::rm f }
@@ -35,18 +35,44 @@ module BagIt
35
35
  # manifest each tag file for each algorithm
36
36
  bag_files.each do |f|
37
37
  rel_path = encode_filename(Pathname.new(f).relative_path_from(Pathname.new(bag_dir)).to_s)
38
-
39
- # sha1
40
- sha1 = Digest::SHA1.file f
41
- File.open(manifest_file(:sha1), 'a') { |io| io.puts "#{sha1} #{rel_path}" }
42
-
43
- # md5
44
- md5 = Digest::MD5.file f
45
- File.open(manifest_file(:md5), 'a') { |io| io.puts "#{md5} #{rel_path}" }
38
+
39
+ case algo
40
+ when 'sha1'
41
+ write_sha1(f, rel_path)
42
+ when 'md5'
43
+ write_md5(f, rel_path)
44
+ when 'sha256'
45
+ write_sha256(f, rel_path)
46
+ when 'sha512'
47
+ write_sha256(f, rel_path)
48
+ when 'default'
49
+ write_sha1(f, rel_path)
50
+ write_md5(f, rel_path)
51
+ end
46
52
  end
47
53
  tagmanifest!
48
54
  end
49
55
 
56
+ def write_sha1(f, rel_path)
57
+ sha1 = Digest::SHA1.file f
58
+ File.open(manifest_file(:sha1), 'a') { |io| io.puts "#{sha1} #{rel_path}" }
59
+ end
60
+
61
+ def write_md5(f, rel_path)
62
+ md5 = Digest::MD5.file f
63
+ File.open(manifest_file(:md5), 'a') { |io| io.puts "#{md5} #{rel_path}" }
64
+ end
65
+
66
+ def write_sha256(f, rel_path)
67
+ sha256 = Digest::SHA256.file f
68
+ File.open(manifest_file(:sha256), 'a') { |io| io.puts "#{sha256} #{rel_path}" }
69
+ end
70
+
71
+ def write_sha512(f, rel_path)
72
+ sha512 = Digest::SHA512.file f
73
+ File.open(manifest_file(:sha512), 'a') { |io| io.puts "#{sha512} #{rel_path}" }
74
+ end
75
+
50
76
  # All tag files that are bag manifest files (tagmanifest-[algorithm].txt)
51
77
  def tagmanifest_files
52
78
  files = Dir[File.join(@bag_dir, '*')].select { |f|
@@ -1,3 +1,3 @@
1
1
  module BagIt
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bagit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Johnson, Francesco Lazzarino, Jamie Little
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-21 00:00:00.000000000 Z
11
+ date: 2018-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: validatable
@@ -94,6 +94,34 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry-byebug
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
97
125
  description: Ruby Library and Command Line tools for bagit
98
126
  email: jamie@jamielittle.org
99
127
  executables:
@@ -147,7 +175,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
175
  version: '0'
148
176
  requirements: []
149
177
  rubyforge_project:
150
- rubygems_version: 2.6.12
178
+ rubygems_version: 2.6.14
151
179
  signing_key:
152
180
  specification_version: 4
153
181
  summary: BagIt package generation and validation