Last active
March 14, 2024 19:07
-
-
Save jcoyne/574671a617ee1b680d3628aef6f26e35 to your computer and use it in GitHub Desktop.
Test migration of OCFL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# TODO: There is one problem with this approach | |
# We have no way to differentiate the cocina.json/public/mods files from purl from the files from stacks. | |
# It may be possible that one of the stacks files could have a name collision (e.g. if the name was "public") | |
require 'ocfl' | |
require 'druid-tools' | |
DRUIDS = %w[ | |
bd072pn1284 | |
] | |
OCFL_ROOT = '/stacks/ocfl-experiment-jcoyne' | |
def migrate_druid(druid) | |
puts "DRUID #{druid}" | |
stacks = DruidTools::PurlDruid.new("druid:#{druid}", '/stacks') | |
purl = DruidTools::PurlDruid.new("druid:#{druid}", '/purl/document_cache') | |
object_root = DruidTools::PurlDruid.new("druid:#{druid}", OCFL_ROOT).path | |
builder = OCFL::Object::DirectoryBuilder.new(object_root:, id: "https://purl.stanford.edu/#{druid}") | |
Dir.foreach(purl.path) do |file| | |
next if ['.', '..'].include?(file) | |
builder.copy_file(File.join(purl.path, file), destination_path: 'metadata/') | |
end | |
builder.copy_recursive(stacks.path, destination_path: 'data') if Dir.exist?(stacks.path) | |
directory = builder.save | |
puts directory.object_root.to_s | |
end | |
DRUIDS.each do |druid| | |
migrate_druid(druid) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment