diff --git a/mmd_tools/mmdCreate.py b/mmd_tools/mmdCreate.py index f785e490d07b27ccf26843e852f707ce55354fff..cafc21b09a24741f8e1abcd317275e94cec659d1 100644 --- a/mmd_tools/mmdCreate.py +++ b/mmd_tools/mmdCreate.py @@ -3,23 +3,27 @@ from datetime import date import uuid import argparse +import json import mmdFormats - if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("-o", help="specify output file") parser.add_argument("-format", help="specify metadata format") + parser.add_argument("-template", help="A JSON file with some pre-filled key value pairs") args = parser.parse_args() outfile = "metadata.mmd" + + # The outfile which will store the metadata: if args.o: print("Outputfile: ", args.o) outfile = args.o else: print("Outputfile: metadata.mmd") + # Was there a metadataformat specified. If not, use MmdSimple: if args.format: print("Metadata format: ", args.format) else: @@ -29,9 +33,19 @@ if __name__ == "__main__": metadata = mmdFormats.DublinCore() else: metadata = mmdFormats.MmdSimple() - + + # Was there a template with JSON encoded key value pairs specified: + if args.template: + infile = open(args.template) + kvps = json.load(infile) + for entry in metadata.data: + if entry.name in kvps: + entry.value = kvps[entry.name] + + # A UUID as id: metadata.id = str(uuid.uuid4()) + # Lets get the metadata from the user: for entry in metadata.data: if entry.vocabulary: record = input(entry.tip + " [" + entry.value + " possible values: " + str(entry.vocabulary) +"]: ") @@ -41,6 +55,7 @@ if __name__ == "__main__": if record != "": entry.value = record + # Writing back the metadata: outputfile = open(outfile, 'w') outputfile.write(metadata.toJson()) outputfile.close() \ No newline at end of file