Last active
August 7, 2020 16:07
-
-
Save mirekys/444cdb7c2884080ded1497de80719ac6 to your computer and use it in GitHub Desktop.
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
#!/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