Skip to content

Commit 9ba3d38

Browse files
committed
Added oslcquery options -Q/-R/-I to suppress name resolution, totalize list results, suppress adding select for rm_nav:parent
1 parent 9bfb774 commit 9ba3d38

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+13352
-12851
lines changed

elmclient/examples/oslcquery.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,15 @@ def do_oslc_query(inputargs=None):
8181
parser.add_argument('-F', '--configuration', default=None, help='The local configuration')
8282
parser.add_argument('-G', '--globalconfiguration', default=None, help='The global configuration (you must not specify local config as well!) - you can specify the id, the full URI, or the config name (not implemented yet)')
8383
parser.add_argument('-H', '--saveconfigs', default=None, help='Name of CSV file to save details of the local project components and configurations')
84+
parser.add_argument('-I', '--totalize', action="store_true", help="For any column with multiple results, put in the total instead of the results")
8485
parser.add_argument("-J", "--jazzurl", default=JAZZURL, help=f"jazz server url (without the /jts!) default {JAZZURL} - Default can be set using environemnt variable QUERY_JAZZURL - defaults to https://jazz.ibm.com:9443 which DOESN'T EXIST")
8586
parser.add_argument('-L', '--loglevel', default=None,help=f'Set logging to file and (by adding a "," and a second level) to console to one of DEBUG, TRACE, INFO, WARNING, ERROR, CRITICAL, OFF - default is {LOGLEVEL} - can be set by environment variable QUERY_LOGLEVEL')
8687
parser.add_argument('-M', '--maxresults', default=None, type=int, help='Max number of results to retrieve a pagesize at a time, then the query is terminated. default is no limit')
8788
parser.add_argument('-N', '--noprogressbar', action="store_false", help="Don't show progress bar during query")
8889
parser.add_argument('-O', '--outputfile', default=None, help='Name of file to save the CSV to')
8990
parser.add_argument("-P", "--password", default=PASSWORD, help=f"user password, default {PASSWORD} - Default can be set using environment variable QUERY_PASSWORD - set to PROMPT to be asked for password at runtime")
91+
parser.add_argument('-Q', '--resolvenames', action="store_false", help="toggle name resolving off (default on) - can greatly speed up postprocessing but you'll get URIs rather than names")
92+
parser.add_argument('-R', '--nodefaultselects', action="store_true", help="Suppress adding default select like for rm rm_nav:folder and dcterms:identifier - can speed up postprocessing because e.g. no need to look up folder name")
9093
parser.add_argument('-S', '--sort', action="store_false", help="Don't sort results by increasing dcterms:identifier, as is done by default - specifying -o (orderby) disables automatic sorting by dcterms:identifier")
9194
parser.add_argument('-T', '--certs', action="store_true", help="Verify SSL certificates")
9295
parser.add_argument("-U", "--username", default=USER, help=f"user id, default {USER} - Default can be set using environment variable QUERY_USER")
@@ -290,7 +293,7 @@ def do_oslc_query(inputargs=None):
290293
p = app.find_project(args.projectname)
291294
if p is None:
292295
raise Exception( f"Project '{args.projectname}' not found")
293-
296+
294297
# assert default for the component name to be the same as the project name
295298
# this might need to be done more intelligently, to handle e.g. when the default component has been archived
296299
# for GC the query might be to find a component, so don't override if a component hasn't been specified!
@@ -369,6 +372,7 @@ def do_oslc_query(inputargs=None):
369372
else:
370373
queryon=p
371374
queryon.set_local_config(config,gcconfiguri)
375+
372376
logger.debug( f"setting {config=} {gcconfiguri=}" )
373377
# we're querying the component
374378
else:
@@ -394,7 +398,8 @@ def do_oslc_query(inputargs=None):
394398
# ensure some important attributes are always in the output
395399
# ensure that identifier and parent are always in the results
396400
if themaindomain == 'rm':
397-
args.select = ensure_select(args.select,[app.identifier_uri,'rm_nav:parent'])
401+
if args.nodefaultselects:
402+
args.select = ensure_select(args.select,[app.identifier_uri,'rm_nav:parent'])
398403
elif themaindomain == 'ccm':
399404
args.select = ensure_select(args.select,[app.identifier_uri])
400405
elif themaindomain == 'gc' or themaindomain == 'qm':
@@ -410,7 +415,8 @@ def do_oslc_query(inputargs=None):
410415
raise Exception( f"The {app.domain} application does not support application-level OSLC Queries - perhaps you meant to provide a project name using -p" )
411416

412417
#ensure type system is loaded
413-
queryon.load_types()
418+
if args.resolvenames:
419+
queryon.load_types()
414420

415421
if args.typesystemreport:
416422
# ensure output folder exists
@@ -448,6 +454,8 @@ def do_oslc_query(inputargs=None):
448454
,maxresults=args.maxresults
449455
,delaybetweenpages=args.delaybetweenpages
450456
,pagesize=args.pagesize
457+
,resolvenames = args.resolvenames
458+
,totalize=args.totalize
451459
)
452460

453461
if args.debugprint:

elmclient/oslcqueryapi.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ def do_complex_query(self,queryresource, *, querystring='', searchterms=None, se
9292
,isnotnulls=None, enhanced=True, show_progress=True
9393
,show_info=False, verbose=False, maxresults=None, delaybetweenpages=0.0
9494
, pagesize=200
95+
,resolvenames=True
96+
,totalize=False
9597
):
9698
if searchterms and querystring:
9799
logger.info( f"{searchterms=}" )
@@ -187,19 +189,25 @@ def do_complex_query(self,queryresource, *, querystring='', searchterms=None, se
187189
logger.info( f"{kattr=} {vattr=}" )
188190
# first try to convert the value to a name
189191
if isinstance(vattr, list):
190-
remappedvalue = []
191-
for lv in vattr:
192-
remappedvalue.append(self.resolve_uri_to_name(lv))
192+
if totalize:
193+
remappedvalue = len(vattr)
194+
else:
195+
remappedvalue = []
196+
for lv in vattr:
197+
if resolvenames:
198+
remappedvalue.append(self.resolve_uri_to_name(lv))
199+
else:
200+
remappedvalue.append(lv)
193201
else:
194-
remappedvalue = self.resolve_uri_to_name(vattr)
202+
remappedvalue = self.resolve_uri_to_name(vattr) if resolvenames else vattr
195203
# then check the attribute itself for one of the mappings we created while parsing the querystring to turn it into an oslc query
196204
if kattr in uri_to_name_mapping:
197205
# this name was locally mapped
198206
v1[uri_to_name_mapping[kattr]] = remappedvalue
199207
else:
200208
# try to map back to a name
201209
if kattr not in remappednames:
202-
remappedname = self.resolve_uri_to_name(kattr)
210+
remappedname = self.resolve_uri_to_name(kattr) if resolvenames else kattr
203211
remappednames[kattr] = remappedname
204212
if remappednames[kattr] is not None:
205213
v1[remappednames[kattr]] = remappedvalue

0 commit comments

Comments
 (0)