Skip to content

Commit

Permalink
Added list_projects(), list_coomponents() and list_configs() and oslc…
Browse files Browse the repository at this point in the history
…query uses these yto show you what's available
  • Loading branch information
barny committed Apr 11, 2023
1 parent 18fa1d3 commit 49791f8
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
12 changes: 11 additions & 1 deletion elmclient/_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,17 @@ def find_project(self, projectname_or_uri, include_archived=False):
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'])
logger.info( f'Project {projectname_or_uri} found {projectu} {res}' )
return res


def is_uri( self, name_or_uri ):
if name_or_uri.startswith('http://') or name_or_uri.startswith('https://'):
return True
return False

def list_projects( self ):
self._load_projects()
projects = [p for p in self._projects if not self.is_uri(p)]
return projects

def report_type_system( self ):
qcdetails = self.get_query_capability_uris()
report = "<HTML><BODY>\n"
Expand Down
17 changes: 17 additions & 0 deletions elmclient/_qm.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,14 @@ def get_local_config(self, name_or_uri, global_config_uri=None):
return cu
return None

def list_configs( self ):
configs = []
self.load_configs()
for cu, cd in self._configurations.items():
configs.append( cd['name'] )

return configs

# load the typesystem using the OSLC shape resources
def _load_types(self,force=False):
logger.debug( f"load type {self=} {force=}" )
Expand Down Expand Up @@ -229,6 +237,15 @@ def find_local_component(self, name_or_uri):
return self
return None

def list_components( self ):
# list all the component names
self.load_components_and_configurations()
components = []
for compuri, compdetail in self._components.items():
if compdetail.get('name'):
components.append( compdetail.get('name') )
return components

def _create_component_api(self, component_prj_url, component_name):
logger.info( f"CREATE QM COMPONENT {self=} {component_prj_url=} {component_name=} {self.app=} {self.is_optin=} {self.singlemode=}" )
result = _QMComponent(component_name, component_prj_url, self.app, self.is_optin, self.singlemode, defaultinit=False, project=self)
Expand Down
21 changes: 20 additions & 1 deletion elmclient/_rm.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def load_folders(self,name_or_uri=None,force=False):
while len(self._foldersnotyetloaded)>0:
logger.info( "-----------------------" )
queryuri = self._foldersnotyetloaded.pop(0)
queryuri = self._foldersnotyetloaded.pop(0)
parent = self._folders.get(queryuri) # parent is None for the first query for the root folder

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

def list_configs( self ):
configs = []
self.load_configs()
for cu, cd in self._configurations.items():
configs.append( cd['name'] )

return configs

# for RM, load the typesystem using the OSLC shape resources listed for the Requirements and Requirements Collection creation factories
def _load_types(self,force=False):
logger.debug( f"load type {self=} {force=}" )
Expand Down Expand Up @@ -626,13 +635,23 @@ def get_local_component_details(self):
results[compuri] = compdetail['name']
return results


def find_local_component(self, name_or_uri):
self.load_components_and_configurations()
for compuri, compdetail in self._components.items():
if compuri == name_or_uri or compdetail['name'] == name_or_uri:
return compdetail['component']
return None


def list_components( self ):
# list all the component names
self.load_components_and_configurations()
components = []
for compuri, compdetail in self._components.items():
if compdetail.get('name'):
components.append( compdetail.get('name') )
return components

def _create_component_api(self, component_prj_url, component_name, confs_to_load):
logger.info( f"CREATE RM COMPONENT {self=} {component_prj_url=} {component_name=} {self.app=} {self.is_optin=} {self.singlemode=}" )
result = _RMComponent(component_name, component_prj_url, self.app, self.is_optin, self.singlemode, defaultinit=False, project=self)
Expand Down
11 changes: 11 additions & 0 deletions elmclient/examples/oslcquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,10 @@ def do_oslc_query(inputargs=None):
# find the project
p = app.find_project(args.projectname)
if p is None:
print( f"Project '{args.projectname}' not found! Available projects are:" )
projlist = app.list_projects()
for p in projlist:
print( f" '{p}'" )
raise Exception( f"Project '{args.projectname}' not found")

# assert default for the component name to be the same as the project name
Expand Down Expand Up @@ -355,6 +359,10 @@ def do_oslc_query(inputargs=None):
if args.component:
c = p.find_local_component(args.component)
if not c:
print( f"Component '{args.component}' not found in project {args.projectname} - Available components are:" )
complist = p.list_components()
for c in complist:
print( f" '{c}'" )
raise Exception( f"Component '{args.component}' not found in project {args.projectname}" )
else:
c = None
Expand All @@ -373,6 +381,9 @@ def do_oslc_query(inputargs=None):
args.configuration = c.get_default_stream_name()
config = c.get_local_config(args.configuration)
if config is None:
print( f"Configuration '{args.configuration}' not found in component {args.component} - available configs are:" )
for c in c.list_configs():
print( f" '{c}'" )
raise Exception( f"Configuration '{args.configuration}' not found in component {args.component}" )
queryon = c

Expand Down

0 comments on commit 49791f8

Please sign in to comment.