Commit 29d85950 authored by Vincent Stehlé's avatar Vincent Stehlé
Browse files

parser.py: add an option for printing



This is useful to print a quick summary, after filtering. We document some
usage in the README.md.
Signed-off-by: Vincent Stehlé's avatarVincent Stehlé <vincent.stehle@arm.com>
parent 17177f8a
......@@ -76,7 +76,7 @@ Example command, suitable for triaging:
$ ./parser.py --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 @@ $ ./parser.py \
--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}
$ ./parser.py --fields 'result,name' --print ...
```
More condensed summaries can be obtained with further filtering.
Example summary command:
``` {.sh}
$ ./parser.py \
--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')
parser.add_argument(
'--uniq', action='store_true', help='Collapse duplicates')
parser.add_argument(
'--print', action='store_true', help='Print results to stdout')
parser.add_argument(
'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:
......
Markdown is supported
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