Commit 29d85950 authored by Vincent Stehlé's avatar Vincent Stehlé
Browse files add an option for printing

This is useful to print a quick summary, after filtering. We document some
usage in the

Signed-off-by: Vincent Stehlé's avatarVincent Stehlé <>
parent 17177f8a
......@@ -76,7 +76,7 @@ Example command, suitable for triaging:
$ ./ --fields 'result,sub set,descr,name,log' ...
The csv format can retain the fields order.
The csv format and printing to stdout can retain the fields order.
### Collapsing duplicates
......@@ -94,6 +94,28 @@ $ ./ \
--fields 'count,result,sub set,descr,name,log' --uniq ...
### Printing a summary
It is possible to print results to stdout using the `--print` option. This is
more useful when only few fields are printed. Example command:
Example printing command:
``` {.sh}
$ ./ --fields 'result,name' --print ...
More condensed summaries can be obtained with further filtering.
Example summary command:
``` {.sh}
$ ./ \
--filter "x.update({'log': re.sub(r'/.*/', '', x['log'])}) \
or x['result'] in ['FAILURE', 'WARNING']" \
--fields 'count,result,name' --uniq --print ...
## Configuration file
It is possible to use a configuration file with command line option `--config
......@@ -480,6 +480,33 @@ def gen_template(cross_check, filename):
yaml.dump(t, yamlfile, Dumper=Dumper)
# Print to stdout
# The fields to write are supplied as a list
def do_print(cross_check, fields):
logging.debug(f'Print (fields: {fields})')
# First pass to find the width for each field except the last one
fm1 = fields[:len(fields) - 1]
w = {}
for f in fm1:
w[f] = len(f)
for x in cross_check:
for f in fm1:
w[f] = max(w[f], len(str(x[f])))
# Second pass where we print
print(' '.join([
*map(lambda f: f"{f:{w[f]}}", fm1),
fields[len(fields) - 1]]))
for x in cross_check:
print(' '.join([
*map(lambda f: f"{x[f]:{w[f]}}", fm1),
x[fields[len(fields) - 1]]]))
# Combine or two databases db1 and db2 coming from ekl and seq files
# respectively into a single cross_check database
# Tests in db1, which were not meant to be run according to db2 have their
......@@ -573,6 +600,8 @@ def main():
'--fields', help='Comma-separated list of fields to write')
'--uniq', action='store_true', help='Collapse duplicates')
'--print', action='store_true', help='Print results to stdout')
'log_file', nargs='?', default='sample.ekl',
help='Input .ekl filename')
......@@ -706,6 +735,10 @@ def main():
if 'yaml' in args and args.yaml is not None:
gen_yaml(cross_check, args.yaml)
# Print if requested
if args.print:
do_print(cross_check, fields)
# command line argument 3&4, key are to support a key & value search.
# these will be displayed in CLI
if args.find_key is not None and args.find_value is not None:
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