Skip to content
Snippets Groups Projects
Commit f19e7cdb authored by Sebastian Ohlmann's avatar Sebastian Ohlmann
Browse files

Add tool to list all bags below a certain directory

parent e68d165f
No related branches found
No related tags found
1 merge request!6Add tool to list all bags below a certain directory
#!/usr/bin/env python3
import argparse
import bagit
import pathlib
import sys
def main():
parser = argparse.ArgumentParser(
description="Find and display all bagit files below a certain folder.")
parser.add_argument("folder",
help="The folder under which bags are searched.")
parser.add_argument("-o", "--outputfile", help="Output file")
parser.add_argument("-s", "--showempty", help="Show empty values",
action='store_true')
args = parser.parse_args()
if args.outputfile is None:
outputfile = sys.stdout
else:
outputfile = open(args.outputfile, "w")
try:
folder = pathlib.Path(args.folder)
file_list = folder.glob("**/bag-info.txt")
for file in file_list:
bag = bagit.Bag(str(file.parent))
outputfile.write("Folder: {} \n".format(str(file.parent)))
for k, v in bag.info.items():
if v != "" or args.showempty:
outputfile.write(f" {k}: {v}\n")
outputfile.write("\n")
finally:
outputfile.close()
if __name__ == "__main__":
main()
...@@ -28,3 +28,4 @@ console_scripts = ...@@ -28,3 +28,4 @@ console_scripts =
mmdShow = mmd_tools.mmdShow:main mmdShow = mmd_tools.mmdShow:main
mmdLoad = mmd_tools.mmdLoad:main mmdLoad = mmd_tools.mmdLoad:main
mmd2bagit = mmd_tools.mmd2bagit:main mmd2bagit = mmd_tools.mmd2bagit:main
mmdListBags = mmd_tools.mmdListBags:main
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment