@@ -84,7 +84,8 @@ def __init__(self, name, project_uri, app, is_optin=False, singlemode=False,defa
84
84
self .default_query_resource = "oslc_rm:Requirement"
85
85
self ._iscomponent = False
86
86
self ._confs_to_load = []
87
-
87
+ self ._confstoparent = []
88
+
88
89
# save a folder details, and return the new folder instance
89
90
def _savefolder ( self , parent , fname , folderuri ):
90
91
ROOTNAME = "+-+root+-+"
@@ -511,13 +512,17 @@ def add_external_component(self,compu):
511
512
self ._components [compu ]['component' ] = c
512
513
return c
513
514
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 = } " )
516
518
# load configurations
517
519
# 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
518
520
self .configTree = anytree .AnyNode (name = 'theroot' ,title = 'root' , created = None , typesystem = None , ismutable = False , ischangeset = False )
519
- confstoparent = []
521
+ result = False
522
+
520
523
while True :
524
+ if verbose :
525
+ print ( "." ,end = "" )
521
526
if not self ._confs_to_load :
522
527
break
523
528
confu = self ._confs_to_load .pop ()
@@ -546,6 +551,8 @@ def load_configs(self, cacheable=True ):
546
551
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' ) ) )
547
552
548
553
for confmember_x in confmembers_x :
554
+ if verbose :
555
+ print ( ">" ,end = "" ,flush = True )
549
556
# print( f"========================\n{confmember_x=}" )
550
557
# print( f"{confmember_x.tag=}" )
551
558
# print( "XML=",ET.tostring( confmember_x ) )
@@ -563,6 +570,10 @@ def load_configs(self, cacheable=True ):
563
570
ismutable = False
564
571
ischangeset = False
565
572
conftitle = rdfxml .xmlrdf_get_resource_text (confmember_x , './dcterms:title' )
573
+
574
+ if stopatnameoruri and ( conftitle == stopatnameoruri or thisconfu == stopatnameoruri ):
575
+ result = True
576
+
566
577
created = rdfxml .xmlrdf_get_resource_uri (confmember_x , './dcterms:created' , exceptionifnotfound = True )
567
578
# print( f"{conftitle=}" )
568
579
# print( f"{created=}" )
@@ -620,18 +631,21 @@ def load_configs(self, cacheable=True ):
620
631
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 )
621
632
if parentnode is None :
622
633
# do this one later
623
- confstoparent .append ( ( thisnode , theparent_u ) )
634
+ self . _confstoparent .append ( ( thisnode , theparent_u ) )
624
635
# print( f"Saved for later {confstoparent[-1]=}" )
625
636
else :
626
637
# parent is known so attach to it
627
638
thisnode .parent = parentnode
628
639
# 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
629
643
630
644
# 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 :
632
646
# we're going to copy unparented node into this new list, then copy the new list into confstoparent
633
647
newconfstoparent = []
634
- for (i ,nodedetails ) in enumerate (confstoparent ):
648
+ for (i ,nodedetails ) in enumerate (self . _confstoparent ):
635
649
(node ,theparent_u ) = nodedetails
636
650
# if we find the parent, attach it - if not found, add it to this list of those still needing parent
637
651
parentnode = anytree .search .find ( self .configTree , filter_ = lambda n : n .name == theparent_u )
@@ -640,10 +654,14 @@ def load_configs(self, cacheable=True ):
640
654
thisnode .parent = parentnode
641
655
# print( f"Parented {node}" )
642
656
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
647
665
648
666
def load_configtree ( self , * , fromconfig_u = None , loadbaselines = False , followsubstreams = False , loadchangesets = False , alwayscaching = False ):
649
667
# show the config tree
@@ -703,7 +721,7 @@ def load_configtree( self, *, fromconfig_u=None, loadbaselines=False, followsubs
703
721
raise Exception ( f"Unkown type { typedetails [1 ]} " )
704
722
705
723
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 ):
707
725
logger .info ( f"GLC { self = } { name_or_uri = } " )
708
726
# print( f"GLC {self=} {name_or_uri=} {global_config_uri=}" )
709
727
if global_config_uri :
@@ -719,7 +737,6 @@ def get_local_config(self, name_or_uri, global_config_uri=None):
719
737
raise Exception ( 'Cannot find configuration [%s] in project [%s]' % (name_or_uri , self .uri ))
720
738
result = config_uri
721
739
else :
722
- self .load_configs ()
723
740
result = None
724
741
filter = None
725
742
if name_or_uri .startswith ("S:" ):
@@ -731,14 +748,19 @@ def get_local_config(self, name_or_uri, global_config_uri=None):
731
748
elif name_or_uri .startswith ("C:" ):
732
749
filter = "ChangeSet"
733
750
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
742
764
# print( f"GLC {result} {self=} {name_or_uri=}" )
743
765
744
766
return result
0 commit comments