Skip to content

Commit 2a7da98

Browse files
committed
fixed represt :-) Requirements.txt are now completely version-free!
1 parent c6f81c0 commit 2a7da98

28 files changed

+2675
-2648
lines changed

elmclient/_rm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1105,7 +1105,7 @@ def add_represt_arguments( cls, subparsers, common_args ):
11051105
NOTE this is called on the class (i.e. is a class method) because at this point don't know which app with be queried
11061106
'''
11071107
parser_rm = subparsers.add_parser('rm', help='RM Reportable REST actions', parents=[common_args] )
1108-
1108+
11091109
parser_rm.add_argument('artifact_format', choices=cls.artifact_formats, default=None, help=f'RM artifact format - possible values are {", ".join(cls.artifact_formats)}')
11101110

11111111
# SCOPE settings

elmclient/examples/OSLCQUERY.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,8 @@ options:
191191
SECRET used to encrypt and decrypt the obfuscated credentials (make this longer for greater
192192
security) - only affects if using -0 or -1
193193
-4, --credspassword Prompt user for a password to save/read obfuscated credentials (make this longer for greater
194-
security)```
194+
security)
195+
```
195196

196197

197198
BEFORE you start:
@@ -389,9 +390,9 @@ Use the typesystem report to see all the shapes, properties and enumeration name
389390

390391
If the title of a module (or anything) includes a double-quote " then you have to escape it with \\ and double the quote to "" so it becomes \\"" in the command line. For example to find a module with title `A "specification"` use `-q "dcterms:title=""A \\""specification\"""""`
391392

392-
You can add a filter like `-v rm_nav:parent` to only show results where parent isn't empty - i.e. to get only core artifacts - unfortunately this filters can only be done is by postprocessing the query results so it doesn't speed up the query itself.
393+
You can add a filter like `-v rm_nav:parent` to only show results where parent isn't empty - i.e. to get only core artifacts - unfortunately this filters can only be done by postprocessing the query results so it doesn't speed up the query itself.
393394

394-
The converse filter is `-n rm_nav:parent`, which filters out results where parent is empty, i.e. only returns module artifacts. You can use -n and -v but that only makes sense (i.e. if you want to possibly get some results) if they reference different attributes.
395+
The converse filter is `-n rm_nav:parent`, which post-filters out results where parent is empty, i.e. only returns module artifacts. You can use -n and -v but that only makes sense (i.e. if you want to possibly get some results) if they reference different attributes.
395396

396397
You can use a global configuration name with a DN query on a project and it will return resources matching the query which are in components which have a configuration contributing to that GC. To use a global configuration you *must* include gc in the --APPSTRING after rm, e.g. -A rm,gc (it is included as /gc by default).
397398

elmclient/examples/dn_simple_createfolderpath.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,5 +103,5 @@
103103
thefolder = c.create_folder( path )
104104
print( f"Folder '{path}' created uri is {thefolder.folderuri}" )
105105
else:
106-
print( f"Folder '{path}' already exists" )
106+
print( f"Folder '{path}' already exists {thefolder.folderuri}" )
107107

elmclient/examples/oslcquery.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def do_oslc_query(inputargs=None):
7777
parser.add_argument('-s', '--select', default='', help='A comma-separate list of properties that should be included in the results - NOTE the app may include additional properties, and may not include the requested properties')
7878
parser.add_argument('-u', '--unique', action="store_true", help="Post-filter: Remove results with an rm_nav:parent value which are not-unique in the results on dcterms:identifier - this keeps module artifacts (which don't have rm_nav:parent) and artifacts for modules (which don't have a module artifact)) - RELEVANT ONLY FOR DOORS Next!")
7979
parser.add_argument('-v', '--value', action='append', default=[], help='Post-filter: A property name that must have a value for the resource to be included in the results - you can specify this option more than once')
80-
parser.add_argument('-A', '--appstrings', default=None, help=f'A comma-seperated list of apps, the query goes to the first entry, default "rm". Each entry must be a domain or domain:contextroot e.g. rm or rm:rm1 - Default can be set using environemnt variable QUERY_APPSTRINGS')
80+
parser.add_argument('-A', '--appstrings', default=None, help=f'A comma-seperated list of apps, the query goes to the first entry, default "{APPSTRINGS}". Each entry must be a domain or domain:contextroot e.g. rm or rm:rm1 - Default can be set using environemnt variable QUERY_APPSTRINGS')
8181
parser.add_argument('-C', '--component', help='The local component (optional, you *have* to specify the local configuration using -F)')
8282
parser.add_argument('-D', '--delaybetweenpages', type=float,default=0.0, help="Delay in seconds between each page of results - use this to reduce overall server load particularly for large result sets or when retrieving many properties")
8383
parser.add_argument('-E', '--globalproject', default=None, help="The global configuration project - optional if the globalconfiguration is unique in the gcm app")

elmclient/examples/represt.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ def represt_main():
8888
common_args.add_argument('-X', '--xmloutputfile', default=None, help='Name of file to save the XML results to')
8989
common_args.add_argument('-Z', '--proxyport', default=8888, type=int, help='Port for proxy default is 8888 - used if found to be active - set to 0 to disable')
9090

91-
9291
# various options
9392
# common_args.add_argument('--nresults', default=-1, type=int, help="TESTING UNFINISHED: Number of results expected (used for regression testing against stored data, doesn't need the target server - use -1 to disable checking")
9493

@@ -103,13 +102,16 @@ def represt_main():
103102
for appcls in _app._App.__subclasses__():
104103
if appcls.supports_reportable_rest:
105104
appcls.add_represt_arguments( subparsers, common_args )
106-
105+
107106
args = parser.parse_args()
108107

108+
# if no appstring specified use the default
109+
args.appstrings = args.appstrings or APPSTRINGS
110+
109111
if not args.appstrings.split(",")[0].startswith(args.subparser_name):
110112
args.appstrings=f"{args.subparser_name}:{args.subparser_name},{args.appstrings}"
111113
print( f"{args.subparser_name} added to front of appstrings - using {args.appstrings} if you need a different context root from /{args.subparser_name} use -A to specify it" )
112-
114+
113115
# setup logging
114116
levels = [utils.loglevels.get(l,-1) for l in args.loglevel.split(",",1)]
115117
if len(levels)<2:
@@ -274,7 +276,7 @@ def represt_main():
274276
timer_start = time.perf_counter()
275277

276278
# call the REST API
277-
result = mainapp.execute_get_xml(reluri=queryurl, headers=headers, cacheable=False, intent="Retrieve Reportable REST content" )
279+
result = mainapp.execute_get_xml(reluri=queryurl, headers=headers, cacheable=False, intent=f"Retrieve Reportable REST content page {npages+1}" )
278280

279281
# calculate and record the duration
280282
duration = time.perf_counter()-timer_start

elmclient/oslcqueryapi.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ def do_complex_query(self,queryresource, *, querystring='', searchterms=None, se
179179
mappedresult = {}
180180
originalresults = resultstack[0]
181181

182+
# print( f"{len(originalresults)=}" )
183+
182184
# add requested columns to each result
183185
if len(addcolumns)>0:
184186
# print( f"Adding columns {addcolumns}" )
@@ -247,6 +249,7 @@ def do_complex_query(self,queryresource, *, querystring='', searchterms=None, se
247249

248250
if show_progress:
249251
pbar.update(1)
252+
# print( f"{len(mappedresult)=}" )
250253

251254
# if showing progress and pbar has been created (after the first set of results if paged)
252255
if show_progress and pbar is not None:
@@ -545,6 +548,7 @@ def _execute_vanilla_oslc_query(self, querycapabilityuri, query_params, orderby=
545548
searchterms = searchterms or []
546549
prefixes = prefixes or {}
547550
logger.debug( f"{prefixes=}" )
551+
548552
headers = {}
549553

550554
if pagesize > 0 or maxresults:
@@ -618,7 +622,7 @@ def _execute_vanilla_oslc_query(self, querycapabilityuri, query_params, orderby=
618622
# no more results to get
619623
break
620624

621-
# no parameters should be sent on following pages, they are present in the href link to next page!
625+
# no parameters should be sent on following pages, they are already present in the href link to next page!
622626
params = None
623627

624628
# work out the url for the next page
@@ -669,6 +673,7 @@ def _execute_vanilla_oslc_query(self, querycapabilityuri, query_params, orderby=
669673
pbar.update(donesofar-donelasttime)
670674
donelasttime = donesofar
671675

676+
# check for any keypresses - user can abort by pressing escape key
672677
while kbhit():
673678
ch = getch()
674679
if ch == b'\x1b':
@@ -683,7 +688,12 @@ def _execute_vanilla_oslc_query(self, querycapabilityuri, query_params, orderby=
683688
if delaybetweenpages>0.0:
684689
time.sleep(delaybetweenpages)
685690

686-
691+
# suppress the Configuration-Context header because it seems that
692+
# when that and param oslc_config.context are provided they both get added
693+
# to each nextpage URL which grows ever longer and eventually breaks
694+
# requests see https://github.com/IBM/ELM-Python-Client/discussions/44#discussioncomment-6151370
695+
headers = {'Configuration-Context': None}
696+
687697
# finished doing the actual query - now process what's been received!
688698

689699
# if showing progress and pbar has been created (after the first set of results if paged)
@@ -753,6 +763,7 @@ def _execute_vanilla_oslc_query(self, querycapabilityuri, query_params, orderby=
753763
for sel in select:
754764
selecturis[rdfxml.tag_to_uri(sel,prefix_map=revprefixes)] = sel
755765
result = {}
766+
nresults = 0
756767
for result_xml in result_xmls:
757768

758769
# find the elements:
@@ -769,10 +780,12 @@ def _execute_vanilla_oslc_query(self, querycapabilityuri, query_params, orderby=
769780
rdfs_member_es = rdfxml.xml_find_elements( result_xml, './/rdf:Description[@rdf:about]/dcterms:title/..')
770781
# print( f"2 {rdfs_member_es=}" )
771782

772-
783+
# print( f"{len(rdfs_member_es)=}" )
773784
# process them
774785
if len(rdfs_member_es) > 0:
775786
for rdfs_member in rdfs_member_es:
787+
nresults += 1
788+
# print( f"{nresults=}" )
776789
# print( f"{rdfs_member.tag=}" )
777790
# about is the uri of the resource
778791
if cmmode or gcmode:
@@ -785,6 +798,7 @@ def _execute_vanilla_oslc_query(self, querycapabilityuri, query_params, orderby=
785798
desc = rdfs_member
786799
# skip entries which have a totalCount - they're not actual results, these are the summary provided by QM
787800
if qmmode and len(rdfxml.xml_find_elements( rdfs_member, './/oslc:totalCount'))>0:
801+
# print( f"SKIPPED!" )
788802
continue
789803
else:
790804
raise Exception("Query result extraction mode not set to anything!")
@@ -794,6 +808,12 @@ def _execute_vanilla_oslc_query(self, querycapabilityuri, query_params, orderby=
794808
# dup = False
795809
else:
796810
# dup = True
811+
# print( f"DUP {about}" )
812+
# print( f"{result[about]=}" )
813+
# print( f"{desc=}" )
814+
# print( f"{ET.tostring(desc)=}" )
815+
# print( "\n" )
816+
# burp
797817
pass
798818
if desc is not None:
799819
# for an entry with no children, if dup and value is same then ignore it
@@ -859,7 +879,7 @@ def _execute_vanilla_oslc_query(self, querycapabilityuri, query_params, orderby=
859879
# now look at itse children
860880
if len(ent)>0 and rdfxml.xmlrdf_get_resource_uri(ent,attrib="rdf:parseType") != "Literal":
861881
# this has children and isn't literal text
862-
# print( "has subs")
882+
# print( "has subs")
863883
# this entity has children; it's like using oslc.selct=oslc_rm:uses{dcterms:identifier}
864884
# work out a heading for this column by concatenating the ent tag with its child's tags
865885
for subent in ent[0]:
@@ -876,6 +896,9 @@ def _execute_vanilla_oslc_query(self, querycapabilityuri, query_params, orderby=
876896
else:
877897
result[about][place] = [value]
878898
logger.debug( f"Saving1 {about} {place} {value}" )
899+
else:
900+
# print( f"desc is none {about}" )
901+
raise Exception( f"desc is none {about}" )
879902

880903
return result
881904

0 commit comments

Comments
 (0)