Skip to content

Instantly share code, notes, and snippets.

@milothiesen
Created January 11, 2019 20:23
Show Gist options
  • Save milothiesen/99f41b87cb4970869156f8cfc17c2948 to your computer and use it in GitHub Desktop.
Save milothiesen/99f41b87cb4970869156f8cfc17c2948 to your computer and use it in GitHub Desktop.
bulk_validate.py
import bagit
import os
import asyncio
root_path = "/Users/thiesm/Desktop/test_bags/"
class BulkValidate:
#this method prints all paths and checksums and validates the bag
def verify_bag(self, bag):
try:
#for each path and fixity in the bage.entires.items list, print the info
for path, fixity in bag.entries.items():
print("path:%s md5:%s" % (path, fixity["md5"]))
print("calling bag.validate()")
except bagit.BagValidationError as e:
for d in e.details:
if isinstance(d, bagit.ChecksumMismatch):
print("expected %s to have %s checksum of %s but found %s" %
(d.path, d.algorithm, d.expected, d.found))
try:
self.bv = bag.validate(processes=4)
self.bv
# print(self.bv)
self.vv = bag._validate_entries(processes=1)
self.vv
print(self.vv)
except Exception as e:
print(e)
class Directories:
def get_dirs(self):
try:
sub_dirs = next(os.walk(root_path))[1]
for bag in sub_dirs:
build_path = root_path + bag
bag = bagit.Bag(build_path)
print(bag)
bulkvalidate = BulkValidate()
bulkvalidate.verify_bag(bag)
except Exception as e:
print(e)
def clean_dirs(self):
try:
#add something about deleting .DS_Store and Thumbs.db here
except Exception as e:
print(e)
# bulkvalidate = BulkValidate()
# bulkvalidate.verify_bag()
dirs = Directories()
dirs.get_dirs()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment