Skip to content

Instantly share code, notes, and snippets.

@mirekys
Last active August 7, 2020 16:07
Show Gist options
  • Save mirekys/444cdb7c2884080ded1497de80719ac6 to your computer and use it in GitHub Desktop.
Save mirekys/444cdb7c2884080ded1497de80719ac6 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# pip install bagit
import os
import bagit
import shutil
def export_bagit(record_metadata, attachments):
pwd = os.getcwd()
dir = pwd + "/files_to_bag"
os.mkdir(dir)
for file in attachments:
filename = "/" + os.path.basename(file)
shutil.copy2(file, dir)
bag = bagit.make_bag(dir, processes=4)
# add metadata
for name, val in record_metadata.items():
bag.info[name] = val
bag.save()
return bag
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment