Skip to content

Commit 49791f8

Browse files
committed
Added list_projects(), list_coomponents() and list_configs() and oslcquery uses these yto show you what's available
1 parent 18fa1d3 commit 49791f8

File tree

4 files changed

+59
-2
lines changed

4 files changed

+59
-2
lines changed

elmclient/_app.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,17 @@ def find_project(self, projectname_or_uri, include_archived=False):
164164
res = self.project_class(self._projects[projectu]['name'], self._projects[projectu]['projectu'], self, is_optin=self._projects[projectu]['is_optin'],singlemode=self._projects[projectu]['singlemode'])
165165
logger.info( f'Project {projectname_or_uri} found {projectu} {res}' )
166166
return res
167-
167+
168+
def is_uri( self, name_or_uri ):
169+
if name_or_uri.startswith('http://') or name_or_uri.startswith('https://'):
170+
return True
171+
return False
172+
173+
def list_projects( self ):
174+
self._load_projects()
175+
projects = [p for p in self._projects if not self.is_uri(p)]
176+
return projects
177+
168178
def report_type_system( self ):
169179
qcdetails = self.get_query_capability_uris()
170180
report = "<HTML><BODY>\n"

elmclient/_qm.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,14 @@ def get_local_config(self, name_or_uri, global_config_uri=None):
174174
return cu
175175
return None
176176

177+
def list_configs( self ):
178+
configs = []
179+
self.load_configs()
180+
for cu, cd in self._configurations.items():
181+
configs.append( cd['name'] )
182+
183+
return configs
184+
177185
# load the typesystem using the OSLC shape resources
178186
def _load_types(self,force=False):
179187
logger.debug( f"load type {self=} {force=}" )
@@ -229,6 +237,15 @@ def find_local_component(self, name_or_uri):
229237
return self
230238
return None
231239

240+
def list_components( self ):
241+
# list all the component names
242+
self.load_components_and_configurations()
243+
components = []
244+
for compuri, compdetail in self._components.items():
245+
if compdetail.get('name'):
246+
components.append( compdetail.get('name') )
247+
return components
248+
232249
def _create_component_api(self, component_prj_url, component_name):
233250
logger.info( f"CREATE QM COMPONENT {self=} {component_prj_url=} {component_name=} {self.app=} {self.is_optin=} {self.singlemode=}" )
234251
result = _QMComponent(component_name, component_prj_url, self.app, self.is_optin, self.singlemode, defaultinit=False, project=self)

elmclient/_rm.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ def load_folders(self,name_or_uri=None,force=False):
121121
while len(self._foldersnotyetloaded)>0:
122122
logger.info( "-----------------------" )
123123
queryuri = self._foldersnotyetloaded.pop(0)
124+
queryuri = self._foldersnotyetloaded.pop(0)
124125
parent = self._folders.get(queryuri) # parent is None for the first query for the root folder
125126

126127
logger.info( f"Retrieving {queryuri=} parent {self._folders.get(queryuri)}" )
@@ -487,6 +488,14 @@ def get_local_config(self, name_or_uri, global_config_uri=None):
487488
result = cu
488489
return result
489490

491+
def list_configs( self ):
492+
configs = []
493+
self.load_configs()
494+
for cu, cd in self._configurations.items():
495+
configs.append( cd['name'] )
496+
497+
return configs
498+
490499
# for RM, load the typesystem using the OSLC shape resources listed for the Requirements and Requirements Collection creation factories
491500
def _load_types(self,force=False):
492501
logger.debug( f"load type {self=} {force=}" )
@@ -626,13 +635,23 @@ def get_local_component_details(self):
626635
results[compuri] = compdetail['name']
627636
return results
628637

638+
629639
def find_local_component(self, name_or_uri):
630640
self.load_components_and_configurations()
631641
for compuri, compdetail in self._components.items():
632642
if compuri == name_or_uri or compdetail['name'] == name_or_uri:
633643
return compdetail['component']
634644
return None
635-
645+
646+
def list_components( self ):
647+
# list all the component names
648+
self.load_components_and_configurations()
649+
components = []
650+
for compuri, compdetail in self._components.items():
651+
if compdetail.get('name'):
652+
components.append( compdetail.get('name') )
653+
return components
654+
636655
def _create_component_api(self, component_prj_url, component_name, confs_to_load):
637656
logger.info( f"CREATE RM COMPONENT {self=} {component_prj_url=} {component_name=} {self.app=} {self.is_optin=} {self.singlemode=}" )
638657
result = _RMComponent(component_name, component_prj_url, self.app, self.is_optin, self.singlemode, defaultinit=False, project=self)

elmclient/examples/oslcquery.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,10 @@ def do_oslc_query(inputargs=None):
305305
# find the project
306306
p = app.find_project(args.projectname)
307307
if p is None:
308+
print( f"Project '{args.projectname}' not found! Available projects are:" )
309+
projlist = app.list_projects()
310+
for p in projlist:
311+
print( f" '{p}'" )
308312
raise Exception( f"Project '{args.projectname}' not found")
309313

310314
# assert default for the component name to be the same as the project name
@@ -355,6 +359,10 @@ def do_oslc_query(inputargs=None):
355359
if args.component:
356360
c = p.find_local_component(args.component)
357361
if not c:
362+
print( f"Component '{args.component}' not found in project {args.projectname} - Available components are:" )
363+
complist = p.list_components()
364+
for c in complist:
365+
print( f" '{c}'" )
358366
raise Exception( f"Component '{args.component}' not found in project {args.projectname}" )
359367
else:
360368
c = None
@@ -373,6 +381,9 @@ def do_oslc_query(inputargs=None):
373381
args.configuration = c.get_default_stream_name()
374382
config = c.get_local_config(args.configuration)
375383
if config is None:
384+
print( f"Configuration '{args.configuration}' not found in component {args.component} - available configs are:" )
385+
for c in c.list_configs():
386+
print( f" '{c}'" )
376387
raise Exception( f"Configuration '{args.configuration}' not found in component {args.component}" )
377388
queryon = c
378389

0 commit comments

Comments
 (0)