Skip to content

Commit 3db9e1b

Browse files
committed
fixes for reqif export not saving file
1 parent dc466df commit 3db9e1b

File tree

7 files changed

+49
-17
lines changed

7 files changed

+49
-17
lines changed

elmclient/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from ._qm import *
1818
from ._relm import *
1919
from .__meta__ import *
20+
from .httpops import *
2021

2122
__app__ = __meta__.app
2223
__version__ = __meta__.version

elmclient/_project.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def _get_request(self, verb, reluri='', *, params=None, headers=None, data=None)
170170
if headers is not None:
171171
fullheaders.update(headers)
172172
sortedparams = None if params is None else {k:params[k] for k in sorted(params.keys())}
173-
request = httpops.HttpRequest( self.app.server._session, verb, self.reluri(reluri), params=sortedparams, headers=fullheaders, data=data)
173+
request = httpops.HttpRequest( self.app.server._session, verb, self.reluri(reluri), params=sortedparams, headers=fullheaders, data=data )
174174
return request
175175

176176
@property

elmclient/_queryparser.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,7 @@ def inop(self, s):
515515

516516
def scoped_term(self, s):
517517
logger.info( f"scoped_term {s=}" )
518+
print( f"scoped_term {s=}" )
518519
return [s[0], "scope", s[1:]]
519520

520521
# from https://tools.oasis-open.org/version-control/svn/oslc-core/trunk/specs/oslc-core.html#selectiveProperties
@@ -526,9 +527,13 @@ def scoped_term(self, s):
526527
dottedname : NAME "." NAME
527528
nested_prop : (identifier | wildcard) "{" properties "}"
528529
wildcard : "*"
529-
identifier : ( ( URI_REF_ESC | NAME ) ":" )? NAME
530+
531+
identifier : ( ( URI_REF_ESC | NAME | "'" SPACYNAME "'" ) ":" )? NAME
532+
| "'" SPACYNAME "'"
533+
530534
URI_REF_ESC : /<https?:.*>/
531535
NAME : /[a-zA-Z0-9_]\w*/
536+
SPACYNAME : /[a-zA-Z0-9_][^']*/
532537
"""
533538

534539
_orderby_grammar = """

elmclient/examples/dn_simple_typesystemimport.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,12 @@
122122
if response.status_code == 202 and location is not None:
123123
# wait for the tracker to finished
124124
result = tgt_c.wait_for_tracker( location, interval=1.0, progressbar=True, msg=f"Importing typesystem")
125-
125+
# TODO: success result is now the xml of the verdict
126126
# result None is a success!
127-
if result is not None:
128-
print( f"Result={result}" )
127+
if result is not None and type(result) is not string:
128+
print( f"Failed Result={result}" )
129129
else:
130-
print( f"Result is None" )
130+
print( f"Success! {result=}" )
131131
else:
132132
raise Exception( "Typesystem import failed!" )
133133

elmclient/examples/reqif_io.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ def reqif_main():
113113

114114
parser_delete.add_argument('definitionnames',nargs='*',default=[],help='One or more names of export definitions to delete - this can be a regex where . matches any character, etc. If you want the regex to match a complete name put ^ at the start and $ at the end')
115115
parser_delete.add_argument('-n', '--noconfirm', action='store_true', help="Don't prompt to confirm each delete (DANGEROUS!)")
116+
parser_delete.add_argument('-x', '--exception', action='store_true', help="Don't raise an exception if definition doesn't exist")
117+
116118

117119
args = parser.parse_args()
118120

@@ -398,7 +400,7 @@ def getmatchingdefs(alldefs,definitionnames):
398400
else:
399401
raise Exception( "Odd response to export command, no Location" )
400402

401-
if args.delaybetween>0:
403+
if len(matches)>1 and args.delaybetween>0:
402404
print( "Delaying between exports" )
403405
time.sleep(args.delaybetween)
404406

@@ -629,30 +631,37 @@ def getmatchingdefs(alldefs,definitionnames):
629631
reffound = False
630632
for ref in allrefs:
631633
logger.debug( f"{ref=}" )
634+
print( f"{ref=}" )
632635
if utils.isint(ref):
633636
# search for an id
634637
if ref in ids:
635638
if ids[ref] not in artincs:
636639
artincs.append(ids[ref])
640+
print( f"Added module {ref}" )
637641
continue
638642
else:
639-
# search for regex match
643+
# search for literal name or a regex match
640644
if re.match(r'^[a-zA-Z0-9 _]+$', ref ):
645+
# literal match
646+
print( f"nre {ref}" )
641647
logger.debug( f"nre" )
642648
# pure string match
643649
# try regex match
644650
for k,v in allmodules.items():
645651
if v.get( 'dcterms:title' ) == ref:
646652
if k not in artincs:
647653
artincs.append(k)
654+
print( f"Added module {ref}" )
648655
continue
649656
else:
650657
logger.debug( f"re" )
658+
print( f"re {ref}" )
651659
# try regex match
652660
for k,v in allmodules.items():
653661
if re.search( ref, v.get( 'dcterms:title' ), re.IGNORECASE ):
654662
if k not in artincs:
655663
artincs.append(k)
664+
print( f"Added module matching {v.get( 'dcterms:title' )} re {ref}" )
656665
continue
657666
if not artincs:
658667
raise Exception( f"No modules found for {ref}!" )
@@ -755,8 +764,10 @@ def getmatchingdefs(alldefs,definitionnames):
755764
if args.definitionnames:
756765
rawmatches = getmatchingdefs(alldefs,args.definitionnames )
757766
if not rawmatches[0]:
758-
raise Exception( f"Definition {args.definitionnames} not found" )
759-
burp
767+
if not args.exception:
768+
raise Exception( f"Definition {args.definitionnames} not found" )
769+
print( f"No definitions matching {args.definitionnames} found - exception suppressed so this isn't a failure" )
770+
return
760771
# merge all the matches so only get reported once
761772
matches = {}
762773
for match in rawmatches:
@@ -765,7 +776,10 @@ def getmatchingdefs(alldefs,definitionnames):
765776
raise Exception( "No definition name provided!" )
766777

767778
if not matches:
768-
raise Exception( f"Definitions {args.definitionnames} not found" )
779+
if not args.exception:
780+
raise Exception( f"Definitions {args.definitionnames} not found" )
781+
print( f"No definitions matching {args.definitionnames} found - exception suppressed so this isn't a failure" )
782+
return
769783

770784
for k in sorted(matches.keys(),key= lambda k: matches[k]['dcterms:title']):
771785
print( f"Deleting {matches[k]['dcterms:title']}" )

elmclient/httpops.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# SPDX-License-Identifier: MIT
44
##
55

6-
76
import codecs
87
import html.parser
98
import http
@@ -253,6 +252,8 @@ def wait_for_tracker( self, location, *, interval=1.0, progressbar=False, msg='W
253252
status = rdfxml.xmlrdf_get_resource_text( response_x, ".//oslc:statusCode" ) or "NO STATUS CODE"
254253
message = rdfxml.xmlrdf_get_resource_text( response_x, ".//oslc:message" ) or "NO MESSAGE"
255254
verdict = f"{status} {message}"
255+
else:
256+
verdict = response_x
256257
break
257258
time.sleep( interval )
258259
if progressbar:
@@ -286,7 +287,14 @@ def _get_delete_request(self, reluri='', *, params=None, headers=None ):
286287

287288
class HttpRequest():
288289
def __init__(self, session, verb, uri, *, params=None, headers=None, data=None):
289-
self._req = requests.Request( verb,uri, params=params, headers=headers, data=data )
290+
# Requests encoding of parameters uses + for space - we need it to use %20!
291+
if params:
292+
paramstring = f"?{urllib.parse.urlencode( params, quote_via=urllib.parse.quote, safe='/')}"
293+
else:
294+
paramstring = ""
295+
296+
# self._req = requests.Request( verb,uri, params=params, headers=headers, data=data )
297+
self._req = requests.Request( verb,uri+paramstring, headers=headers, data=data )
290298
self._session = session
291299

292300
def get_user_password(self, url=None):

elmclient/oslcqueryapi.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ def execute_oslc_query(self, querycapabilityuri, *, whereterms=None, select=None
374374
query_params1 = self.hooks[0](query_params)
375375
else:
376376
query_params1 = query_params
377+
377378
results = self._execute_vanilla_oslc_query(querycapabilityuri,query_params1, select=select, prefixes=prefixes, show_progress=show_progress, verbose=verbose, maxresults=maxresults, delaybetweenpages=delaybetweenpages, pagesize=pagesize, intent=intent)
378379
return results
379380

@@ -407,7 +408,7 @@ def _get_query_clauses(self, whereterms, prefixmap):
407408
if operator == "scope":
408409
# handle nested series of whereterms recursively
409410
scopedterm = self._get_query_clauses(value, prefixmap)
410-
clauses.append(f'{tag} {{ {scopedterm} }}')
411+
clauses.append(f'{tag}{{{scopedterm}}}') # note there are no space chars allowed by the OSLC Query sytax!
411412
elif operator == "in":
412413
inlist = []
413414
for val in value:
@@ -494,6 +495,7 @@ def _execute_vanilla_oslc_query(self, querycapabilityuri, query_params, orderby=
494495
query_params['oslc.paging'] = 'true'
495496
query_params['oslc.pageSize'] = str(pagesize) if maxresults is None or ( pagesize>0 and pagesize<maxresults ) else str(maxresults)
496497

498+
497499
logger.debug(f"execute_query {query_params} {select}")
498500
base_uri = querycapabilityuri
499501
logger.info( f"The base OSLC Query URL is {base_uri}" )
@@ -507,7 +509,9 @@ def _execute_vanilla_oslc_query(self, querycapabilityuri, query_params, orderby=
507509
url_parts[4] = ""
508510
url_parts[5] = ""
509511
# reconstruct just the base scheme:hostname
512+
# inisists on using + instead of %20!
510513
query_url = urllib.parse.urlunparse(url_parts)
514+
511515
logger.info( f"The full OSLC Query URL is {query_url}" )
512516

513517
# in case of paged results, always prepare to collect a list of results
@@ -516,11 +520,11 @@ def _execute_vanilla_oslc_query(self, querycapabilityuri, query_params, orderby=
516520
params.update(query)
517521
logger.info( f"The parameters for this query are {params}" )
518522

519-
fullurl = f"{query_url}?{urllib.parse.urlencode( params, quote_via=urllib.parse.quote, safe='')}"
523+
fullurl = f"{query_url}?{urllib.parse.urlencode( params, quote_via=urllib.parse.quote, safe='/')}"
520524
if verbose:
521525
print( f"Full query URL is {fullurl}" )
522526
# print( f"Full query URL is {fullurl}" )
523-
527+
# burp
524528
# retrieve all pages of results - they will be processed later
525529
total = 1
526530
page = 0
@@ -554,7 +558,7 @@ def _execute_vanilla_oslc_query(self, querycapabilityuri, query_params, orderby=
554558
# no more results to get
555559
break
556560

557-
# no parameters should be sent on following pages
561+
# no parameters should be sent on following pages, they are present in the href link to next page!
558562
params = None
559563

560564
# work out the url for the next page

0 commit comments

Comments
 (0)