From e97baf24605a63ca300f6cdef4bdc77593b6c922 Mon Sep 17 00:00:00 2001 From: Henning Glawe <glaweh@debian.org> Date: Fri, 19 Aug 2016 20:51:08 +0200 Subject: [PATCH] add --matchTelemetry option and forward it to JsonParseEventsWriterBackend --- common/python/nomadcore/parser_backend.py | 3 ++- common/python/nomadcore/simple_parser.py | 10 +++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/common/python/nomadcore/parser_backend.py b/common/python/nomadcore/parser_backend.py index f789444..4365c83 100644 --- a/common/python/nomadcore/parser_backend.py +++ b/common/python/nomadcore/parser_backend.py @@ -52,13 +52,14 @@ def valueForStrValue(strValue, dtypeStr): class JsonParseEventsWriterBackend(object): """Simple backend that writes out the parse events in json format""" # json content is written to fileOut - def __init__(self, metaInfoEnv, fileOut = sys.stdout): + def __init__(self, metaInfoEnv, fileOut = sys.stdout, writeMatchTelemetry=False): self.__metaInfoEnv = metaInfoEnv self.fileOut = fileOut self.__gIndex = -1 self.__openSections = set() self.__writeComma = False self.__lastIndex = {} + self.writeMatchTelemetry = writeMatchTelemetry self.stats = {} def addStat(self, name): diff --git a/common/python/nomadcore/simple_parser.py b/common/python/nomadcore/simple_parser.py index ce31ce4..c56160c 100644 --- a/common/python/nomadcore/simple_parser.py +++ b/common/python/nomadcore/simple_parser.py @@ -1251,9 +1251,10 @@ def mainFunction(mainFileDescription, mainFile: The path to the file that is parsed. If not specified, reads the filename from the command line arguments. """ - usage = """{exeName} [--annotate] [--meta-info] [--help] [--specialize] [--stream] [--uri uri] [--verbose] [path/toFile] + usage = """{exeName} [--annotate] [--matchTelemetry] [--meta-info] [--help] [--specialize] [--stream] [--uri uri] [--verbose] [path/toFile] --annotate writes annotated debug info of parsing process to file path/toFile.annotate + --matchTelemetry write information about matches to output JSON stream --meta-info outputs the meta info supported by this parser --help prints this message --specialize expects inclusion and exclusion of meta info to parse via a json dictionary on stdin @@ -1270,6 +1271,7 @@ def mainFunction(mainFileDescription, uri = None verbose = False fileToParse = None + writeMatchTelemetry = False ii = 1 while ii < len(sys.argv): arg = sys.argv[ii] @@ -1288,6 +1290,8 @@ def mainFunction(mainFileDescription, elif arg == "--annotate": global annotate annotate = True + elif arg == "--matchTelemetry": + writeMatchTelemetry = True elif arg == "--uri": if ii >= len(sys.argv): raise Exception("missing uri after --uri") @@ -1326,7 +1330,7 @@ def mainFunction(mainFileDescription, # Initialize the backend where the final results are printed after they are # possibly filtered by the caching ActiveBackend. if superBackend is None: - jsonBackend = JsonParseEventsWriterBackend(metaInfoEnv, outF) + jsonBackend = JsonParseEventsWriterBackend(metaInfoEnv, outF, writeMatchTelemetry=writeMatchTelemetry) else: jsonBackend = superBackend @@ -1392,7 +1396,7 @@ def mainFunction(mainFileDescription, # create file-specific json backend outFile = open(outFileName, 'w') outFile.write("[") - outFilejsonBackend = JsonParseEventsWriterBackend(metaInfoEnv, outFile) + outFilejsonBackend = JsonParseEventsWriterBackend(metaInfoEnv, outFile, writeMatchTelemetry=writeMatchTelemetry) # override superBackend for this parseFile backend.superBackend = outFilejsonBackend logger.warning("# parsing: %s", toRead['mainFile']) -- GitLab