Skip to content

Commit

Permalink
dump file mode and yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
privatezero committed Sep 7, 2018
1 parent 18c0c0b commit 2f7ef43
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions ltomanifest
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'bagit'
require 'yaml'
require 'optparse'
require 'pathname'

option = {}

Expand All @@ -15,10 +16,13 @@ OptionParser.new do |opts|
opts.on("-c", "--confirm", "Confirm manifest") do |d|
option = 'confirm'
end
opts.on("-b", "--bagdump=val", "Bag dump", String) { |val| $bagdump = val }

opts.on("-h", "--help", "Help") do
puts opts
exit
end

if ARGV.empty?
puts opts
end
Expand All @@ -36,6 +40,13 @@ def green(input)
puts "\e[36m#{input}\e[0m"
end

# Parse Bag Dump if selected
if ! $bagdump.nil?
bagdumppath = Pathname.new($bagdump)
bagdumpcontents = YAML::load_file(bagdumppath)
@confirmed_dumpbags = bagdumpcontents['ConfirmedBags']
end

def Create_manifest(input)
#Check and limit input
if input.length > 1
Expand All @@ -52,9 +63,21 @@ def Create_manifest(input)
red("#{input}/tapemanifest.txt already exists. Exiting.")
exit
end
#Get list of directories
#Get list of directories (skip dump list bags if present)
Dir.chdir(input)
bag_list = Dir.glob('*')
if ! @confirmed_dumpbags.nil?
green("Will skip previously confirmed bags listed in BagListDump.txt")
bag_list = Dir.glob('*') - @confirmed_dumpbags
@confirmed_dumpbags.each do |isvalidbag|
TargetBags << isvalidbag
end
else
bag_list = Dir.glob('*')
end
if bag_list.include? 'BagListDump.txt'
red("BagListDump.txt detected in target directory. Please move this outside of target and try again! Exiting.")
end

#Check if supposed bags are actually directories
bag_list.each do |isdirectory|
if ! File.directory?(isdirectory)
Expand Down Expand Up @@ -96,12 +119,13 @@ def Create_manifest(input)
targetBagsSorted.each do |bagparse|
metafile = "#{bagparse}/manifest-md5.txt"
contents = File.readlines(metafile)
bagcontents << bagparse
bagcontents << contents
parsedcontents = {"Bag Name" => bagparse, "Bag Contents" => contents}
bagcontents << parsedcontents
end

#Write manifest of bags and checksums
data = {"Bag List" => targetBagsSorted, "Contents" => bagcontents}

File.write('tapemanifest.txt',data.to_yaml)
green("Manifest written at #{input}/tapemanifest.txt")
end
Expand Down

0 comments on commit 2f7ef43

Please sign in to comment.