Commit dfffc5af authored by Vincent Stehlé's avatar Vincent Stehlé
Browse files use argparse

Use argparse for command line arguments. This gives us the online help and
will give use more flexibility to add command line options.

We preserve the current behaviour with up to two positional arguments for
the ekl and seq input files, and up to two arguments for the key:value

Signed-off-by: Vincent Stehlé's avatarVincent Stehlé <>
parent e106fa3c
......@@ -3,6 +3,8 @@
import sys
import argparse
#based loosley on
# returns a filtered dict of dicts that meet some Key-value pair.
......@@ -161,16 +163,31 @@ def dict_2_md(input_list,file):
def main():
#Command line argument 1, ekl file to open, else open sample
log_file = sys.argv[1] if len(sys.argv) >= 2 else "sample.ekl"
parser = argparse.ArgumentParser(
description='Process SCT results.'
' This program takes the SCT summary and sequence files,'
' and generates a nice report in mardown format.',
'--md', help='Output .md filename', default='')
'log_file', nargs='?', default='sample.ekl',
help='Input .ekl filename')
'seq_file', nargs='?', default='sample.seq',
help='Input .seq filename')
parser.add_argument('find_key', nargs='?', help='Search key')
parser.add_argument('find_value', nargs='?', help='Search value')
args = parser.parse_args()
#Command line argument 1, ekl file to open
db1 = list() #"database 1" all tests.
with open(log_file,"r",encoding="utf-16") as f: #files are encoded in utf-16
with open(args.log_file,"r",encoding="utf-16") as f: #files are encoded in utf-16
db1 = ekl_parser(f.readlines())
#Command line argument 2, seq file to open, else open sample
seq_file = sys.argv[2] if len(sys.argv) >= 3 else "sample.seq"
#Command line argument 2, seq file to open
db2 = dict() #"database 2" all test sets that should run
with open(seq_file,"r",encoding="utf-16") as f: #files are encoded in utf-16
with open(args.seq_file,"r",encoding="utf-16") as f: #files are encoded in utf-16
db2 = seq_parser(f)
#cross check is filled only with tests labled as "run" int the seq file
......@@ -191,9 +208,8 @@ def main():
warnings = key_value_find(cross_check,"result","WARNING")
passes = key_value_find(cross_check,"result","PASS")
# generate MD summary
with open('', 'w') as resultfile:
with open(, 'w') as resultfile:
resultfile.write("# SCT Summary \n\n")
resultfile.write("| | |\n")
......@@ -218,13 +234,14 @@ def main():
#command line argument 3&4, key are to support a key & value search.
#these will be displayed in CLI
if len(sys.argv) >= 5:
find_key = sys.argv[3]
find_value = sys.argv[4]
found = key_value_find(db1,find_key,find_value)
if args.find_key is not None and args.find_value is not None:
found = key_value_find(db1, args.find_key, args.find_value)
#print the dict
print("found:",len(found),"items with search constraints")
for x in found:
x["guid"], ":", x["name"], "with", args.find_key, ":",
......@@ -10,7 +10,9 @@ It will proceed to generate a Markdown file listing number of failures, passes,
## Usage
Usage to generate a "result md" is such. `python3 <log_file.ekl> <seq_file.seq>`
If you do no provided any command line arguments it will use `sample.ekl` and `sample.seq`.
The output filename can be specified with `--md <filename>`.
An online help is available with the `-h` option.
### Custom search
For a custom Key:value search, the next two arguments *MUST be included together.* The program will search and display files that met that constraint, without the crosscheck, and display the names, guid, and key:value to the command line. `python3 <file.ekl> <file.seq> <search key> <search value>`
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment