@@ -84,7 +84,8 @@ def __init__(self, name, project_uri, app, is_optin=False, singlemode=False,defa
8484 self .default_query_resource = "oslc_rm:Requirement"
8585 self ._iscomponent = False
8686 self ._confs_to_load = []
87-
87+ self ._confstoparent = []
88+
8889 # save a folder details, and return the new folder instance
8990 def _savefolder ( self , parent , fname , folderuri ):
9091 ROOTNAME = "+-+root+-+"
@@ -511,13 +512,17 @@ def add_external_component(self,compu):
511512 self ._components [compu ]['component' ] = c
512513 return c
513514
514- def load_configs (self , cacheable = True ):
515- logger .debug ( f"Loading configs { self ._confs_to_load = } " )
515+ # if given stopatnameoruri returns True if found, False if not (which means all configs have been loaded and it isn't there!)
516+ def load_configs (self , cacheable = True , stopatnameoruri = None , verbose = False , incremental = False ):
517+ logger .debug ( f"Loading configs { self ._confs_to_load = } , { stopatnameoruri = } " )
516518 # load configurations
517519 # and build a tree with initial baseline as root, alternating baseline and stream nodes each with a list of children, so it can be walked if needed
518520 self .configTree = anytree .AnyNode (name = 'theroot' ,title = 'root' , created = None , typesystem = None , ismutable = False , ischangeset = False )
519- confstoparent = []
521+ result = False
522+
520523 while True :
524+ if verbose :
525+ print ( "." ,end = "" )
521526 if not self ._confs_to_load :
522527 break
523528 confu = self ._confs_to_load .pop ()
@@ -546,6 +551,8 @@ def load_configs(self, cacheable=True ):
546551 confmembers_x = list ( set ( rdfxml .xml_find_elements (configs_xml , './/oslc_config:Configuration' ) + rdfxml .xml_find_elements (configs_xml , './/oslc_config:Stream' ) + rdfxml .xml_find_elements (configs_xml , './/oslc_config:Baseline' ) + rdfxml .xml_find_elements (configs_xml , './/oslc_config:ChangeSet' ) ) )
547552
548553 for confmember_x in confmembers_x :
554+ if verbose :
555+ print ( ">" ,end = "" ,flush = True )
549556# print( f"========================\n{confmember_x=}" )
550557# print( f"{confmember_x.tag=}" )
551558# print( "XML=",ET.tostring( confmember_x ) )
@@ -563,6 +570,10 @@ def load_configs(self, cacheable=True ):
563570 ismutable = False
564571 ischangeset = False
565572 conftitle = rdfxml .xmlrdf_get_resource_text (confmember_x , './dcterms:title' )
573+
574+ if stopatnameoruri and ( conftitle == stopatnameoruri or thisconfu == stopatnameoruri ):
575+ result = True
576+
566577 created = rdfxml .xmlrdf_get_resource_uri (confmember_x , './dcterms:created' , exceptionifnotfound = True )
567578# print( f"{conftitle=}" )
568579# print( f"{created=}" )
@@ -620,18 +631,21 @@ def load_configs(self, cacheable=True ):
620631 thisnode = anytree .AnyNode ( None , name = thisconfu , title = conftitle , conftype = conftype , created = created , typesystem = _newtypesystem .TypeSystem (conftitle , thisconfu ), ismutable = ismutable ) #TypeSystem(conftitle, thisconfu), ismutable=ismutable, ischangeset=ischangeset )
621632 if parentnode is None :
622633 # do this one later
623- confstoparent .append ( ( thisnode , theparent_u ) )
634+ self . _confstoparent .append ( ( thisnode , theparent_u ) )
624635# print( f"Saved for later {confstoparent[-1]=}" )
625636 else :
626637 # parent is known so attach to it
627638 thisnode .parent = parentnode
628639# print( f"Config {conftitle} Added config {thisconfu} parent={parentnode}" )
640+ # now check if stopatnameoururi is present and if so set result True
641+ if result :
642+ break
629643
630644 # now iterate over the unparented nodes repeatedly finding their parents until there are none left because all have been parented
631- while confstoparent :
645+ while self . _confstoparent :
632646 # we're going to copy unparented node into this new list, then copy the new list into confstoparent
633647 newconfstoparent = []
634- for (i ,nodedetails ) in enumerate (confstoparent ):
648+ for (i ,nodedetails ) in enumerate (self . _confstoparent ):
635649 (node ,theparent_u ) = nodedetails
636650 # if we find the parent, attach it - if not found, add it to this list of those still needing parent
637651 parentnode = anytree .search .find ( self .configTree , filter_ = lambda n : n .name == theparent_u )
@@ -640,10 +654,14 @@ def load_configs(self, cacheable=True ):
640654 thisnode .parent = parentnode
641655# print( f"Parented {node}" )
642656 else :
643- # remember this still needs parenting
644- newconfstoparent .append ( (node ,parent ) )
645- confstoparent = newconfstoparent
646-
657+ # remember this still needs parenting! Will be found on a later pass
658+ newconfstoparent .append ( (node ,theparent_u ) )
659+ self ._confstoparent = newconfstoparent
660+
661+ if verbose :
662+ print ( "" )
663+
664+ return result
647665
648666 def load_configtree ( self , * , fromconfig_u = None , loadbaselines = False , followsubstreams = False , loadchangesets = False , alwayscaching = False ):
649667 # show the config tree
@@ -703,7 +721,7 @@ def load_configtree( self, *, fromconfig_u=None, loadbaselines=False, followsubs
703721 raise Exception ( f"Unkown type { typedetails [1 ]} " )
704722
705723
706- def get_local_config (self , name_or_uri , global_config_uri = None ):
724+ def get_local_config (self , name_or_uri , global_config_uri = None , verbose = False , incremental = False ):
707725 logger .info ( f"GLC { self = } { name_or_uri = } " )
708726# print( f"GLC {self=} {name_or_uri=} {global_config_uri=}" )
709727 if global_config_uri :
@@ -719,7 +737,6 @@ def get_local_config(self, name_or_uri, global_config_uri=None):
719737 raise Exception ( 'Cannot find configuration [%s] in project [%s]' % (name_or_uri , self .uri ))
720738 result = config_uri
721739 else :
722- self .load_configs ()
723740 result = None
724741 filter = None
725742 if name_or_uri .startswith ("S:" ):
@@ -731,14 +748,19 @@ def get_local_config(self, name_or_uri, global_config_uri=None):
731748 elif name_or_uri .startswith ("C:" ):
732749 filter = "ChangeSet"
733750 name_or_uri = name_or_uri [2 :]
734- for cu , cd in self ._configurations .items ():
735- # print( f"{cu=} {cd=}" )
736- if filter and cd ['conftype' ] != filter :
737- continue
738- if cu == name_or_uri or cd ['name' ] == name_or_uri :
739- if result :
740- raise Exception ( f"Config { name_or_uri } isn't unique - you could try prefixing it with S: for stream, B: for baseline, or C: for changeset" )
741- result = cu
751+
752+ while result is None :
753+ for cu , cd in self ._configurations .items ():
754+ # print( f"{cu=} {cd=}" )
755+ if filter and cd ['conftype' ] != filter :
756+ continue
757+ if cu == name_or_uri or cd ['name' ] == name_or_uri :
758+ if result :
759+ raise Exception ( f"Config { name_or_uri } isn't unique - you could try prefixing it with S: for stream, B: for baseline, or C: for changeset" )
760+ result = cu
761+ if result is None :
762+ if not self .load_configs ( stopatnameoruri = name_or_uri , verbose = verbose , incremental = incremental ):
763+ break
742764# print( f"GLC {result} {self=} {name_or_uri=}" )
743765
744766 return result
0 commit comments