bin/bagit in bagit-0.3.2 vs bin/bagit in bagit-0.3.4
- old
+ new
@@ -1,10 +1,13 @@
#!/usr/bin/env ruby
require 'bagit'
require 'docopt'
+require 'logger'
+logger = Logger.new(STDOUT)
+
doc = <<DOCOPT
BagIt.
Usage:
bagit add [-f <file>...] [-t <tagfile>...] BAGPATH
@@ -35,21 +38,27 @@
# [--internal-sender-identifier <sender-id>] [--internal-sender-description <sender-desc>]
# [--bag-info-entry <label> <value>] [-f <file>...] [-t <tagfile>...] BAGPATH
begin
opts = Docopt::docopt(doc, version: BagIt::VERSION)
-
- bag = BagIt::Bag.new(opts['BAGPATH'])
+ unless opts['validate']
+ bag = BagIt::Bag.new(opts['BAGPATH'])
+ end
#####################################
# commands that don't alter the bag #
#####################################
if opts['validate']
- if opts['--oxum']
- puts bag.valid_oxum?.to_s
+ if File.exists?(opts['BAGPATH']+'/bag-info.txt') && File.directory?(opts['BAGPATH']+'/data') && File.exists?(opts['BAGPATH']+'/manifest-md5.txt') || File.exists?(opts['BAGPATH']+'/manifest-sha1.txt')
+ bag = BagIt::Bag.new(opts['BAGPATH'])
+ if opts['--oxum']
+ logger.info(bag.valid_oxum?.to_s)
+ else
+ logger.info(bag.valid?.to_s)
+ end
else
- puts bag.valid?.to_s
+ logger.error("Not a valid bag")
end
# validation commands MUST NOT change manifest or bag-info files
exit
end
@@ -81,11 +90,11 @@
bag.add_file(File.basename(datafile), datafile)
elsif opts['delete']
bag.remove_file(File.basename(datafile))
end
rescue Exception => e
- puts "Failed operation on bag file: #{e.message}"
+ logger.error("Failed operation on bag file: #{e.message}")
end
}
end
# handle adding tag files
@@ -105,19 +114,19 @@
bag.delete_tag_file(File.basename(tagfile))
elsif opts['remove']
bag.remove_tag_file(File.basename(tagfile))
end
rescue Exception => e
- puts "Failed operation on tag file: #{e.message}"
+ logger.error("Failed operation on tag file: #{e.message}".red)
end
}
end
# if we haven't quit yet, we need to re-manifest
# only do tags if tag files have been explictly added/removed or it is explictly called
bag.tagmanifest! if opts['-T'] or not opts['-t'].nil?
bag.manifest!
rescue Docopt::Exit => e
- puts e.message
+ logger.error(e.message.red)
end