added CLI; added comment about tags where keys are useful info

This commit is contained in:
2022-07-29 17:05:29 +02:00
parent ec24e9dd34
commit bcf0cf6456

View File

@@ -1,5 +1,31 @@
#!/usr/bin/env python
import argparse
parser = argparse.ArgumentParser(
description="Convert an elog dump to a scilog json",
formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
parser.add_argument("-d", "--dump", default="dump", help="Folder containing the elog dump")
parser.add_argument("-a", "--authors", default="authors.json", help="JSON file containing the author mapping")
parser.add_argument("-o", "--output", default="scilog.json", help="Output file name")
parser.add_argument("-u", "--default-user", default="default", help="Default user")
parser.add_argument("-p", "--default-pgroup", default="default", help="Default pgroup")
clargs = parser.parse_args()
fn_authors = clargs.authors
fn_dump = clargs.dump
fn_output = clargs.output
default_user = clargs.default_user
default_pgroup = clargs.default_pgroup
from glob import iglob
import json
@@ -13,12 +39,6 @@ def json_save(what, filename, *args, indent=4, sort_keys=True, **kwargs):
json.dump(what, f, *args, indent=indent, sort_keys=sort_keys, **kwargs)
default_pgroup = "default"
default_author = "default"
mapped = {
# "Author": "createdBy",
"Date": "timestamp",
@@ -41,6 +61,9 @@ special = [
"Title"
]
# The key of the tags is not written into the output since it does not look to be very useful information for the given examples
# if there was a case where the key is useful, we could write "Key:Value" as tag instead of just "Value".
# We might want to introduce a separate category (tags_with_keys) for these.
tags = [
"Component",
"Entry",
@@ -55,9 +78,9 @@ tags = [
]
authors = json_load("authors.json")
authors = json_load(fn_authors)
fns = sorted(iglob("dump/msg*.json"))
fns = sorted(iglob(fn_dump + "/msg*.json"))
res = []
for fn in fns:
data_out = {}
@@ -85,7 +108,7 @@ for fn in fns:
# treat special entries
author = data_in.pop("Author")
author = authors.get(author, default_author)
author = authors.get(author, default_user)
data_out["createdBy"] = author
pgroup = data_in.pop("P-Group", default_pgroup)
@@ -127,7 +150,7 @@ for fn in fns:
res.append(data_out)
json_save(res, "scilog.json")
json_save(res, fn_output)