moab-versioning 4.2.0 → 4.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5c13dd09bef589a3c4a3314737c2d3b6dfb4589f
4
- data.tar.gz: 629913d22d1ba0b40f62671aabc7cca01767c276
3
+ metadata.gz: 8226ecfe5e815a81aa72bc564fc1abc341b4f570
4
+ data.tar.gz: 9d085cad25bc601caec626edb5cf4f778a979fc3
5
5
  SHA512:
6
- metadata.gz: fe0076d5a2e868613c4e5f081abdee5fd93e76effccfdf4219d7849d8f9944cc11ff728b407ffac22a0d02b9a71c30a75e2077c3f11698bb815e336b951f33b4
7
- data.tar.gz: 6c3e42f3cf596cd16e2d62858da725e93fcf37ab835bfcc4f9a3951eb4bbd569845210f9dfa40f39048bab235162fe2d169494a5469a31229924ad29dbea01db
6
+ metadata.gz: 6c0072f1cd34f7bd192a4231b6c496e81d4ce380edaf08cd5fb997b240ad64b09c8ce94ed4083a65f812c11971b1e11eadf2d8099edb898226d904a8e58c3d17
7
+ data.tar.gz: 71aa7a0ff75185089d2a7705a13635b67b0fbaa600b438a35fde7f75a4bd83061f050b1c4eeef98162e38b64a66e6c23e3f45748bde93b5de42acaee32fadf9e
data/lib/moab/bagger.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  module Moab
2
-
3
2
  # A class used to create a BagIt package from a version inventory and a set of source files.
4
3
  # The {#fill_bag} method is called with a package_mode parameter that specifies
5
4
  # whether the bag is being created for deposit into the repository or is to contain the output of a version reconstruction.
@@ -18,7 +17,6 @@ module Moab
18
17
  # @note Copyright (c) 2012 by The Board of Trustees of the Leland Stanford Junior University.
19
18
  # All rights reserved. See {file:LICENSE.rdoc} for details.
20
19
  class Bagger
21
-
22
20
  # @param version_inventory [FileInventory] The complete inventory of the files comprising a digital object version
23
21
  # @param signature_catalog [SignatureCatalog] The signature catalog, used to specify source paths (in :reconstructor mode),
24
22
  # or to filter the version inventory (in :depositor mode)
@@ -71,7 +69,7 @@ module Moab
71
69
  if bag_pathname.join('data').exist?
72
70
  bag_pathname.rmtree
73
71
  else
74
- bag_pathname.children.each {|file| file.delete}
72
+ bag_pathname.children.each { |file| file.delete }
75
73
  bag_pathname.rmdir
76
74
  end
77
75
  end
@@ -108,13 +106,13 @@ module Moab
108
106
  @package_mode = package_mode
109
107
  bag_pathname.mkpath
110
108
  case package_mode
111
- when :depositor
112
- version_inventory.write_xml_file(bag_pathname, 'version')
113
- @bag_inventory = signature_catalog.version_additions(version_inventory)
114
- bag_inventory.write_xml_file(bag_pathname, 'additions')
115
- when :reconstructor
116
- @bag_inventory = version_inventory
117
- bag_inventory.write_xml_file(bag_pathname, 'version')
109
+ when :depositor
110
+ version_inventory.write_xml_file(bag_pathname, 'version')
111
+ @bag_inventory = signature_catalog.version_additions(version_inventory)
112
+ bag_inventory.write_xml_file(bag_pathname, 'additions')
113
+ when :reconstructor
114
+ @bag_inventory = version_inventory
115
+ bag_inventory.write_xml_file(bag_pathname, 'version')
118
116
  end
119
117
  bag_inventory
120
118
  end
@@ -128,10 +126,10 @@ module Moab
128
126
  bag_inventory.groups.each do |group|
129
127
  group_id = group.group_id
130
128
  case package_mode
131
- when :depositor
132
- deposit_group(group_id, source_base_pathname.join(group_id))
133
- when :reconstructor
134
- reconstuct_group(group_id, source_base_pathname)
129
+ when :depositor
130
+ deposit_group(group_id, source_base_pathname.join(group_id))
131
+ when :reconstructor
132
+ reconstuct_group(group_id, source_base_pathname)
135
133
  end
136
134
  end
137
135
  end
@@ -143,7 +141,7 @@ module Moab
143
141
  def deposit_group(group_id, source_dir)
144
142
  group = bag_inventory.group(group_id)
145
143
  return nil? if group.nil? or group.files.empty?
146
- target_dir = bag_pathname.join('data',group_id)
144
+ target_dir = bag_pathname.join('data', group_id)
147
145
  group.path_list.each do |relative_path|
148
146
  source = source_dir.join(relative_path)
149
147
  target = target_dir.join(relative_path)
@@ -160,7 +158,7 @@ module Moab
160
158
  def reconstuct_group(group_id, storage_object_dir)
161
159
  group = bag_inventory.group(group_id)
162
160
  return nil? if group.nil? or group.files.empty?
163
- target_dir = bag_pathname.join('data',group_id)
161
+ target_dir = bag_pathname.join('data', group_id)
164
162
  group.files.each do |file|
165
163
  catalog_entry = signature_catalog.signature_hash[file.signature]
166
164
  source = storage_object_dir.join(catalog_entry.storage_path)
@@ -251,15 +249,15 @@ module Moab
251
249
  end
252
250
 
253
251
  # @return [Boolean] Create a tar file containing the bag
254
- def create_tarfile(tar_pathname=nil)
252
+ def create_tarfile(tar_pathname = nil)
255
253
  bag_name = bag_pathname.basename
256
254
  bag_parent = bag_pathname.parent
257
255
  tar_pathname ||= bag_parent.join("#{bag_name}.tar")
258
- tar_cmd="cd '#{bag_parent}'; tar --dereference --force-local -cf '#{tar_pathname}' '#{bag_name}'"
256
+ tar_cmd = "cd '#{bag_parent}'; tar --dereference --force-local -cf '#{tar_pathname}' '#{bag_name}'"
259
257
  begin
260
258
  shell_execute(tar_cmd)
261
259
  rescue
262
- shell_execute(tar_cmd.sub('--force-local',''))
260
+ shell_execute(tar_cmd.sub('--force-local', ''))
263
261
  end
264
262
  raise "Unable to create tarfile #{tar_pathname}" unless tar_pathname.exist?
265
263
  return true
data/lib/moab/config.rb CHANGED
@@ -1,13 +1,12 @@
1
1
  require 'moab'
2
2
 
3
3
  module Moab
4
-
5
4
  # @return [Confstruct::Configuration] the configuration data
6
5
  Config = Confstruct::Configuration.new do
7
- storage_roots nil
8
- storage_trunk nil
9
- deposit_trunk nil
10
- path_method :druid_tree
6
+ storage_roots nil
7
+ storage_trunk nil
8
+ deposit_trunk nil
9
+ path_method :druid_tree
10
+ checksum_algos [:md5, :sha1, :sha256]
11
11
  end
12
-
13
12
  end
@@ -1,5 +1,4 @@
1
1
  module Moab
2
-
3
2
  # Given a deposit bag, ensures the contents valid for becoming a StorageObjectVersion
4
3
  # this is a Shameless Green implementation, combining code from:
5
4
  # - sdr-preservation-core/lib/sdr_ingest/validate_bag <-- old preservation robots
@@ -11,7 +10,6 @@ module Moab
11
10
  # - deposit_bag_validator
12
11
  # - file_signature
13
12
  class DepositBagValidator
14
-
15
13
  BAG_DIR_NOT_FOUND = :bag_dir_not_found
16
14
  CHECKSUM_MISMATCH = :checksum_mismatch
17
15
  CHECKSUM_TYPE_UNRECOGNIZED = :checksum_type_unrecognized
@@ -85,7 +83,7 @@ module Moab
85
83
  pathname = deposit_bag_pathname.join(filename)
86
84
  result_array << single_error_hash(REQUIRED_FILE_NOT_FOUND, file_pathname: pathname) unless pathname.exist?
87
85
  end
88
- result_array.empty? ? true : false
86
+ result_array.empty?
89
87
  end
90
88
 
91
89
  def verify_version
@@ -221,7 +219,7 @@ module Moab
221
219
  file_checksums
222
220
  end
223
221
 
224
- def digester_hash(types_to_generate=DEFAULT_CHECKSUM_TYPES)
222
+ def digester_hash(types_to_generate = DEFAULT_CHECKSUM_TYPES)
225
223
  types_to_generate.each_with_object({}) do |checksum_type, digester_hash|
226
224
  case checksum_type
227
225
  when :md5
@@ -1,18 +1,13 @@
1
1
  module Moab
2
2
  class ObjectNotFoundException < RuntimeError
3
-
4
3
  end
5
4
 
6
5
  class FileNotFoundException < RuntimeError
7
-
8
6
  end
9
7
 
10
8
  class InvalidMetadataException < RuntimeError
11
-
12
9
  end
13
10
 
14
11
  class ValidationException < RuntimeError
15
-
16
12
  end
17
-
18
13
  end
@@ -1,7 +1,6 @@
1
1
  require 'moab'
2
2
 
3
3
  module Moab
4
-
5
4
  # A container for a standard subset of a digital objects {FileManifestation} objects
6
5
  # Used to segregate depositor content from repository metadata files
7
6
  # This is a child element of {FileInventory}, which contains a full example
@@ -16,14 +15,13 @@ module Moab
16
15
  # @note Copyright (c) 2012 by The Board of Trustees of the Leland Stanford Junior University.
17
16
  # All rights reserved. See {file:LICENSE.rdoc} for details.
18
17
  class FileGroup < Serializer::Serializable
19
-
20
18
  include HappyMapper
21
19
 
22
20
  # The name of the XML element used to serialize this objects data
23
21
  tag 'fileGroup'
24
22
 
25
23
  # (see Serializable#initialize)
26
- def initialize(opts={})
24
+ def initialize(opts = {})
27
25
  @signature_hash = Hash.new
28
26
  @data_source = ""
29
27
  super(opts)
@@ -39,7 +37,7 @@ module Moab
39
37
 
40
38
  # @attribute
41
39
  # @return [Integer] The total number of data files (dynamically calculated)
42
- attribute :file_count, Integer, :tag => 'fileCount', :on_save => Proc.new {|i| i.to_s}
40
+ attribute :file_count, Integer, :tag => 'fileCount', :on_save => Proc.new { |i| i.to_s }
43
41
 
44
42
  def file_count
45
43
  files.inject(0) { |sum, manifestation| sum + manifestation.file_count }
@@ -47,7 +45,7 @@ module Moab
47
45
 
48
46
  # @attribute
49
47
  # @return [Integer] The total size (in bytes) of all data files (dynamically calculated)
50
- attribute :byte_count, Integer, :tag => 'byteCount', :on_save => Proc.new {|i| i.to_s}
48
+ attribute :byte_count, Integer, :tag => 'byteCount', :on_save => Proc.new { |i| i.to_s }
51
49
 
52
50
  def byte_count
53
51
  files.inject(0) { |sum, manifestation| sum + manifestation.byte_count }
@@ -55,7 +53,7 @@ module Moab
55
53
 
56
54
  # @attribute
57
55
  # @return [Integer] The total disk usage (in 1 kB blocks) of all data files (estimating du -k result) (dynamically calculated)
58
- attribute :block_count, Integer, :tag => 'blockCount', :on_save => Proc.new {|i| i.to_s}
56
+ attribute :block_count, Integer, :tag => 'blockCount', :on_save => Proc.new { |i| i.to_s }
59
57
 
60
58
  def block_count
61
59
  files.inject(0) { |sum, manifestation| sum + manifestation.block_count }
@@ -83,7 +81,7 @@ module Moab
83
81
  # used to test for existence of a filename in this file group
84
82
  def path_hash
85
83
  path_hash = Hash.new
86
- signature_hash.each do |signature,manifestation|
84
+ signature_hash.each do |signature, manifestation|
87
85
  manifestation.instances.each do |instance|
88
86
  path_hash[instance.path] = signature
89
87
  end
@@ -93,7 +91,7 @@ module Moab
93
91
 
94
92
  # @return [Array<String>] The list of file paths in this group
95
93
  def path_list
96
- files.collect{|file| file.instances.collect{|instance| instance.path}}.flatten
94
+ files.collect { |file| file.instances.collect { |instance| instance.path } }.flatten
97
95
  end
98
96
 
99
97
  # @api internal
@@ -116,7 +114,7 @@ module Moab
116
114
  def files=(manifestiation_array)
117
115
  manifestiation_array.each do |manifestiation|
118
116
  add_file(manifestiation)
119
- end
117
+ end
120
118
  end
121
119
 
122
120
  # @api internal
@@ -133,7 +131,7 @@ module Moab
133
131
  # @param instance [FileInstance] The pathname and datetime of the file instance to be added
134
132
  # @return [void] Add a single {FileSignature},{FileInstance} key/value pair to this group.
135
133
  # Data is actually stored in the {#signature_hash}
136
- def add_file_instance(signature,instance)
134
+ def add_file_instance(signature, instance)
137
135
  if signature_hash.has_key?(signature)
138
136
  manifestation = signature_hash[signature]
139
137
  else
@@ -165,7 +163,7 @@ module Moab
165
163
  def is_descendent_of_base?(pathname)
166
164
  raise("base_directory has not been set") if @base_directory.nil?
167
165
  is_descendent = false
168
- pathname.expand_path.ascend {|ancestor| is_descendent ||= (ancestor == @base_directory)}
166
+ pathname.expand_path.ascend { |ancestor| is_descendent ||= (ancestor == @base_directory) }
169
167
  raise("#{pathname} is not a descendent of #{@base_directory}") unless is_descendent
170
168
  is_descendent
171
169
  end
@@ -174,7 +172,7 @@ module Moab
174
172
  # @param signatures_from_bag [Hash<Pathname,Signature>] The fixity data already calculated for the files
175
173
  # @param recursive [Boolean] if true, descend into child directories
176
174
  # @return [FileGroup] Harvest a directory (using digest hash for fixity data) and add all files to the file group
177
- def group_from_bagit_subdir(directory, signatures_from_bag, recursive=true)
175
+ def group_from_bagit_subdir(directory, signatures_from_bag, recursive = true)
178
176
  @signatures_from_bag = signatures_from_bag
179
177
  group_from_directory(directory, recursive)
180
178
  end
@@ -183,7 +181,7 @@ module Moab
183
181
  # @param directory [Pathname,String] The location of the files to harvest
184
182
  # @param recursive [Boolean] if true, descend into child directories
185
183
  # @return [FileGroup] Harvest a directory and add all files to the file group
186
- def group_from_directory(directory, recursive=true)
184
+ def group_from_directory(directory, recursive = true)
187
185
  self.base_directory = directory
188
186
  @data_source = @base_directory.to_s
189
187
  harvest_directory(directory, recursive)
@@ -201,7 +199,7 @@ module Moab
201
199
  # Note that unlike Find.find and Dir.glob, Pathname passes through symbolic links
202
200
  # @see http://stackoverflow.com/questions/3974087/how-to-make-rubys-find-find-follow-symlinks
203
201
  # @see http://stackoverflow.com/questions/357754/can-i-traverse-symlinked-directories-in-ruby-with-a-glob
204
- def harvest_directory(path, recursive, validated=nil)
202
+ def harvest_directory(path, recursive, validated = nil)
205
203
  pathname = Pathname.new(path).expand_path
206
204
  validated ||= is_descendent_of_base?(pathname)
207
205
  pathname.children.sort.each do |child|
@@ -221,7 +219,7 @@ module Moab
221
219
  # @param _validated (unused; kept here for backwards compatibility)
222
220
  # @return [void] Add a single physical file's data to the array of files in this group.
223
221
  # If fixity data was supplied in bag manifests, then utilize that data.
224
- def add_physical_file(pathname, _validated=nil)
222
+ def add_physical_file(pathname, _validated = nil)
225
223
  pathname = Pathname.new(pathname).expand_path
226
224
  instance = FileInstance.new.instance_from_file(pathname, @base_directory)
227
225
  if @signatures_from_bag && @signatures_from_bag[pathname]
@@ -234,7 +232,5 @@ module Moab
234
232
  end
235
233
  add_file_instance(signature, instance)
236
234
  end
237
-
238
235
  end
239
-
240
236
  end
@@ -1,7 +1,6 @@
1
1
  require 'moab'
2
2
 
3
3
  module Moab
4
-
5
4
  # Performs analysis and reports the differences between two matching {FileGroup} objects.
6
5
  # The descending elements of the report hold a detailed breakdown of file-level differences, organized by change type.
7
6
  # This stanza is a child element of {FileInventoryDifference}, the documentation of which contains a full example.
@@ -53,8 +52,8 @@ module Moab
53
52
  end
54
53
 
55
54
  # (see Serializable#initialize)
56
- def initialize(opts={})
57
- @subset_hash = Hash.new {|hash, key| hash[key] = FileGroupDifferenceSubset.new(:change => key.to_s)}
55
+ def initialize(opts = {})
56
+ @subset_hash = Hash.new { |hash, key| hash[key] = FileGroupDifferenceSubset.new(:change => key.to_s) }
58
57
  super(opts)
59
58
  end
60
59
 
@@ -135,7 +134,7 @@ module Moab
135
134
 
136
135
  def subsets=(array)
137
136
  if array
138
- array.each{|subset| subset_hash[subset.change.to_sym] = subset}
137
+ array.each { |subset| subset_hash[subset.change.to_sym] = subset }
139
138
  end
140
139
  end
141
140
 
@@ -144,19 +143,18 @@ module Moab
144
143
  %w{group_id difference_count identical copyadded copydeleted renamed modified deleted added}
145
144
  end
146
145
 
147
-
148
146
  # @api internal
149
147
  # @return [FileGroupDifference] Clone just this element for inclusion in a versionMetadata structure
150
148
  def summary()
151
149
  FileGroupDifference.new(
152
- :group_id => group_id,
153
- :identical => identical,
154
- :copyadded => copyadded,
155
- :copydeleted => copydeleted,
156
- :renamed => renamed,
157
- :modified => modified,
158
- :added => added,
159
- :deleted => deleted
150
+ :group_id => group_id,
151
+ :identical => identical,
152
+ :copyadded => copyadded,
153
+ :copydeleted => copydeleted,
154
+ :renamed => renamed,
155
+ :modified => modified,
156
+ :added => added,
157
+ :deleted => deleted
160
158
  )
161
159
  end
162
160
 
@@ -258,7 +256,7 @@ module Moab
258
256
  basis_only_paths = basis_paths - other_paths
259
257
  other_only_paths = other_paths - basis_paths
260
258
  maxsize = [basis_only_paths.size, other_only_paths.size].max
261
- (0..maxsize-1).each do |n|
259
+ (0..maxsize - 1).each do |n|
262
260
  fid = FileInstanceDifference.new()
263
261
  fid.basis_path = basis_only_paths[n]
264
262
  fid.other_path = other_only_paths[n]
@@ -335,10 +333,10 @@ module Moab
335
333
  # @return [Hash<Symbol,Array>] Sets of filenames grouped by change type for use in performing file or metadata operations
336
334
  def file_deltas()
337
335
  # The hash to be returned
338
- deltas = Hash.new {|hash, key| hash[key] = []}
336
+ deltas = Hash.new { |hash, key| hash[key] = [] }
339
337
  # case where other_path is empty or 'same'. (create array of strings)
340
338
  [:identical, :modified, :deleted, :copydeleted].each do |change|
341
- deltas[change].concat(subset_hash[change].files.collect{ |file| file.basis_path })
339
+ deltas[change].concat(subset_hash[change].files.collect { |file| file.basis_path })
342
340
  end
343
341
  # case where basis_path and other_path are both present. (create array of arrays)
344
342
  [:copyadded, :renamed].each do |change|
@@ -372,9 +370,7 @@ module Moab
372
370
  # @param [Array<Array<String>>] filepairs The set of oldname, newname pairs for all files being renamed
373
371
  # @return [Array<Array<String>>] a set of file triples containing oldname, tempname, newname
374
372
  def rename_tempfile_triplets(filepairs)
375
- filepairs.collect{ |old, new| [old, new, "#{new}-#{Time.now.strftime('%Y%m%d%H%H%S')}-tmp"] }
373
+ filepairs.collect { |old, new| [old, new, "#{new}-#{Time.now.strftime('%Y%m%d%H%H%S')}-tmp"] }
376
374
  end
377
-
378
375
  end
379
-
380
376
  end
@@ -1,7 +1,6 @@
1
1
  require 'moab'
2
2
 
3
3
  module Moab
4
-
5
4
  # A container for reporting a set of file-level differences of the type specified by the change attribute
6
5
  #
7
6
  # ====Data Model
@@ -20,7 +19,7 @@ module Moab
20
19
  tag 'subset'
21
20
 
22
21
  # (see Serializable#initialize)
23
- def initialize(opts={})
22
+ def initialize(opts = {})
24
23
  @files = Array.new
25
24
  super(opts)
26
25
  end
@@ -39,7 +38,6 @@ module Moab
39
38
 
40
39
  # @attribute
41
40
  # @return [Array<FileInstanceDifference>] The set of file instances having this type of change
42
- has_many :files, FileInstanceDifference, :tag=>'file'
43
-
41
+ has_many :files, FileInstanceDifference, :tag => 'file'
44
42
  end
45
43
  end
@@ -1,7 +1,6 @@
1
1
  require 'moab'
2
2
 
3
3
  module Moab
4
-
5
4
  # The file path and last modification date properties of a file
6
5
  #
7
6
  # ====Data Model
@@ -14,14 +13,13 @@ module Moab
14
13
  # @note Copyright (c) 2012 by The Board of Trustees of the Leland Stanford Junior University.
15
14
  # All rights reserved. See {file:LICENSE.rdoc} for details.
16
15
  class FileInstance < Serializer::Serializable
17
-
18
16
  include HappyMapper
19
17
 
20
18
  # The name of the XML element used to serialize this objects data
21
19
  tag 'fileInstance'
22
20
 
23
21
  # (see Serializable#initialize)
24
- def initialize(opts={})
22
+ def initialize(opts = {})
25
23
  super(opts)
26
24
  end
27
25
 
@@ -34,14 +32,13 @@ module Moab
34
32
  attribute :datetime, String
35
33
 
36
34
  def datetime=(event_datetime)
37
- @datetime=Moab::UtcTime.input(event_datetime)
35
+ @datetime = Moab::UtcTime.input(event_datetime)
38
36
  end
39
37
 
40
38
  def datetime
41
39
  Moab::UtcTime.output(@datetime)
42
40
  end
43
41
 
44
-
45
42
  # @api internal
46
43
  # @param pathname [Pathname] The location of the physical file
47
44
  # @param base_directory [Pathname] The full path used as the basis of the relative paths reported
@@ -56,7 +53,7 @@ module Moab
56
53
  # @param other [FileInstance] The other file instance being compared to this instance
57
54
  # @return [Boolean] Returns true if self and other have the same path.
58
55
  def eql?(other)
59
- return false unless other.respond_to?(:path) # Cannot equal an incomparable type!
56
+ return false unless other.respond_to?(:path) # Cannot equal an incomparable type!
60
57
  self.path == other.path
61
58
  end
62
59
 
@@ -77,7 +74,5 @@ module Moab
77
74
  def hash
78
75
  path.hash
79
76
  end
80
-
81
77
  end
82
-
83
78
  end