Skip to content

Commit

Permalink
result_summary: support for extra query parameters in cmdline
Browse files Browse the repository at this point in the history
New command line option: --query-params to specify a set of extra query
parameters to complete or override preset parameters.

Signed-off-by: Ricardo Cañuelo <[email protected]>
  • Loading branch information
r-c-n committed Apr 3, 2024
1 parent 228bc55 commit b488e6a
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions src/result_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import gzip
import logging
import os
import re
import shutil

import jinja2
Expand All @@ -60,12 +61,33 @@
OUTPUT_DIR = '/home/kernelci/data/output/'


def split_query_params(query_string):
"""Given a string input formatted like this:
parameter1=value1,parameter2=value2,...,parameterN=valueN
return a dict containing the string information where the
parameters are the dict keys:
{'parameter1': 'value1',
'parameter2': 'value2',
...,
'parameterN': 'valueN'
}
"""
query_dict = {}
matches = re.findall('([^ =,]+)\s*=\s*([^ =,]+)', query_string) # noqa: W605
for operator, value in matches:
query_dict[operator] = value
return query_dict


class ResultSummary(Service):
def __init__(self, configs, args):
super().__init__(configs, args, SERVICE_NAME)
if args.verbose:
self.log._logger.setLevel(logging.DEBUG)
## Load and sanity check command line parameters
# Load and sanity check command line parameters
# self._config: the complete config file contents
# self._preset_name: name of the selected preset to use
# self._preset: loaded config for the selected preset
Expand All @@ -79,6 +101,10 @@ def __init__(self, configs, args):
self.log.error(f"No {self._preset_name} preset found in {args.config}")
sys.exit(1)
self._preset = self._config[self._preset_name]
# Additional query parameters and date parameters
self._extra_query_params = {}
if args.query_params:
self._extra_query_params = split_query_params(args.query_params)
self._created_from = args.created_from
self._created_to = args.created_to
self._last_updated_from = args.last_updated_from
Expand Down Expand Up @@ -266,10 +292,14 @@ def _run(self, ctx):
sys.exit(1)
template = template_env.get_template(metadata['template'])

# Collect results
# Run queries and collect results
nodes = []
metadata['queries'] = []
for params_set in params:
# Apply extra query parameters from command line, if any
params_set.update(self._extra_query_params)
self.log.debug(f"Query: {params_set}")
metadata['queries'].append(params_set)
query_results = self._iterate_node_find(params_set)
self.log.debug(f"Query matches found: {len(query_results)}")
nodes.extend(query_results)
Expand Down Expand Up @@ -387,6 +417,11 @@ class cmd_run(Command):
'name': '--output',
'help': "Override the 'output' preset parameter"
},
{
'name': '--query-params',
'help': ("Additional query parameters: "
"'<paramX>=<valueX>,<paramY>=<valueY>'")
},
Args.verbose,
]

Expand Down

0 comments on commit b488e6a

Please sign in to comment.