Skip to content
Snippets Groups Projects
Commit fc05f221 authored by Thomas Zastrow's avatar Thomas Zastrow :construction_worker:
Browse files

Implementing template functionality

parent 6279ae62
No related branches found
No related tags found
1 merge request!2Main
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment