@@ -668,7 +668,7 @@ def add_external_component(self,compu):
668668 return c
669669
670670 # if given stopatnameoruri returns True if found, False if not (which means all configs have been loaded and it isn't there!)
671- def load_configs (self , cacheable = True , stopatnameoruri = None , verbose = False , incremental = False ):
671+ def load_configs (self , cacheable = True , stopatnameoruri = None , verbose = False , incremental = False , load_changesets = True ):
672672 logger .debug ( f"Loading configs { self ._confs_to_load = } , { stopatnameoruri = } " )
673673 # load configurations
674674 # 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
@@ -710,17 +710,19 @@ def load_configs(self, cacheable=True, stopatnameoruri=None, verbose=False, incr
710710 for confmember_x in confmembers_x :
711711 if verbose :
712712 print ( ">" ,end = "" ,flush = True )
713- # print( f"========================\n{confmember_x=}" )
713+ logger .info ( f"========================\n { confmember_x = } " )
714+ logger .info ( f"tree= { anytree .RenderTree (self .configTree , style = anytree .AsciiStyle ())} " )
714715# print( f"{confmember_x.tag=}" )
715716# print( "XML=",ET.tostring( confmember_x ) )
716717 thisconfu = rdfxml .xmlrdf_get_resource_uri ( confmember_x )
717- # print ( f"Member {thisconfu=}" )
718+ logger . info ( f"Member { thisconfu = } " )
718719 # add baselines and changesets
719720 self ._confs_to_load = list (set (self ._confs_to_load ))
720721# print( f"1 {len(self._confs_to_load)} {self._confs_to_load=}" )
721722 self ._confs_to_load .append ( rdfxml .xmlrdf_get_resource_uri (confmember_x , './oslc_config:streams' ) )
722723 self ._confs_to_load .append ( rdfxml .xmlrdf_get_resource_uri (confmember_x , './oslc_config:baselines' ) )
723- self ._confs_to_load .append ( rdfxml .xmlrdf_get_resource_uri (confmember_x , './rm_config:changesets' ) )
724+ if load_changesets :
725+ self ._confs_to_load .append ( rdfxml .xmlrdf_get_resource_uri (confmember_x , './rm_config:changesets' ) )
724726 self ._confs_to_load = list (set (self ._confs_to_load ))
725727# print( f"2 {len(self._confs_to_load)} {self._confs_to_load=}" )
726728 logger .debug ( f"{ thisconfu = } " )
@@ -771,59 +773,88 @@ def load_configs(self, cacheable=True, stopatnameoruri=None, verbose=False, incr
771773 if not theparent_u :
772774 # this is the initial stream
773775 parentnode = self .configTree
774- # print ( f"Config {conftitle} used theroot {parentnode=}" )
776+ logger . info ( f"Config { conftitle } used theroot { parentnode = } " )
775777 else :
776778 parentnode = anytree .search .find ( self .configTree , filter_ = lambda n : n .name == theparent_u )
777- # print ( f"Config {conftitle} found {parentnode=}" )
779+ logger . info ( f"Config { conftitle } found { parentnode = } " )
778780
779781 # try to find this config url to see if it's already known
780782 if anytree .search .find ( self .configTree , filter_ = lambda n : n .name == thisconfu ):
781783 # already in the tree!
782- # print ( f"Config {conftitle} Config has parent in configtree {thisconfu} parent={parentnode}" )
784+ logger . info ( f"Config { conftitle } Config has parent in configtree { thisconfu } parent={ parentnode } " )
783785 pass
784786 else :
787+ logger .info ( f"Not already in tree { thisconfu = } " )
785788 # need to find the parent to attach to
786789 # create the node - if we don't attach it now we'll attach it later - typesystem is set to None so if needed this can be filled in later.
787790 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 )
791+ logger .info ( f"New node { id (thisnode )= } { thisnode = } " )
788792 if parentnode is None :
789793 # do this one later
790794 self ._confstoparent .append ( ( thisnode , theparent_u ) )
791- # print ( f"\nSaved for later {self._confstoparent[-1]=}" )
795+ logger . info ( f"\n Saved for later { id ( thisnode ) = } { self ._confstoparent [- 1 ]= } " )
792796 else :
793797 # parent is known so attach to it
794798 thisnode .parent = parentnode
795- # print ( f"\nConfig {conftitle} Added config {thisconfu} parent={parentnode}" )
799+ logger . info ( f"\n Config { conftitle } Added config { thisconfu } { id ( parentnode ) = } parent={ parentnode } " )
796800 # now check if stopatnameoururi is present and if so set result True
797801 if result :
798802 break
799803
800804 # now iterate over the unparented nodes repeatedly finding their parents until there are none left because all have been parented
801805 while self ._confstoparent :
806+ logger .info ( f"\n \n =======\n \n " )
807+ logger .info ( f"Parenting urls { self ._confstoparent = } " )
808+ logger .info ( f"tree= { anytree .RenderTree (self .configTree , style = anytree .AsciiStyle ())} " )
802809 foundparent = False
810+
803811 # we're going to copy unparented node into this new list, then copy the new list into confstoparent
804812 newconfstoparent = []
805813 for (i ,nodedetails ) in enumerate (self ._confstoparent ):
806- (node ,theparent_u ) = nodedetails
807- # print( f"\n{node=} {theparent_u=}" )
814+ (node ,toparent_u ) = nodedetails
815+ logger .info ( f"\n \n -------------- { toparent_u = } \n \n " )
816+ logger .info ( f"\n { id (node )= } { node = } { toparent_u = } { node .parent = } " )
817+ logger .info ( f"tree= { anytree .RenderTree (self .configTree , style = anytree .AsciiStyle ())} " )
818+ # check it isn't already in the tree
819+
820+ # try to find this config url to see if it's already known
821+ if anytree .search .find ( self .configTree , filter_ = lambda n : n .name == toparent_u ):
822+ # already in the tree!
823+ logger .info ( f"Config { toparent_u } already in the tree!" )
824+ continue
825+
826+ if node .parent is not None :
827+ logger .info ( f"Already parented { toparent_u = } { node = } " )
828+ continue
808829 # if we find the parent, attach it - if not found, add it to this list of those still needing parent
809- parentnode = anytree .search .find ( self .configTree , filter_ = lambda n : n .name == theparent_u )
830+ parentnodes = anytree .search .findall ( self .configTree , filter_ = lambda n : n .name == toparent_u )
831+ if len ( parentnodes ) > 1 :
832+ logger .info ( f"parentnodes for { toparent_u } { parentnodes = } " )
833+ raise Exception ( "Can't have more than one parent for {toparent_u} {parentnodes=}" )
834+ if len ( parentnodes ) < 1 :
835+ logger .info ( f"no parentnodes for { toparent_u } !" )
836+ parentnode = None
837+ else :
838+ parentnode = parentnodes [0 ]
839+ logger .info ( f"no parentnodes for { toparent_u } !" )
840+ logger .info ( f"parentnode for { toparent_u } { parentnode } " )
810841 if parentnode :
811842 # found!
812843 node .parent = parentnode
813844 foundparent = True
814- # print ( f"\nParented {node=} {theparent_u }" )
845+ logger . info ( f"\n Parented { node = } { toparent_u } " )
815846 else :
816847 # remember this still needs parenting! Will be found on a later pass UNLESS it's been tried a few times and always fails
817848 # in which case we'll print a message and ignore the config!
818- newconfstoparent .append ( (node ,theparent_u ) )
819- # print ( f"\npostponing {node=} {theparent_u }" )
849+ newconfstoparent .append ( (node ,toparent_u ) )
850+ logger . info ( f"\n postponing { node = } { toparent_u } " )
820851# print( f"tree= {anytree.RenderTree(self.configTree, style=anytree.AsciiStyle())}" )
821852
822853 self ._confstoparent = newconfstoparent
823854 # if no parent was found on this run through confstoparent, give up with the confs to parent preserved
824855 if not foundparent :
825856 if verbose :
826- print ( f"\n Postponing potentially unparentable configs { self ._confstoparent } " )
857+ logger . info ( f"\n Postponing potentially unparentable configs { self ._confstoparent } " )
827858 break
828859
829860 if verbose :
@@ -889,7 +920,7 @@ def load_configtree( self, *, fromconfig_u=None, loadbaselines=False, followsubs
889920 raise Exception ( f"Unknown type { typedetails [1 ]} " )
890921
891922
892- def get_local_config (self , name_or_uri , global_config_uri = None , verbose = False , incremental = False ):
923+ def get_local_config (self , name_or_uri , global_config_uri = None , verbose = False ):
893924 logger .info ( f"GLC { self = } { name_or_uri = } " )
894925# print( f"GLC {self=} {name_or_uri=} {global_config_uri=}" )
895926 if global_config_uri :
@@ -927,7 +958,8 @@ def get_local_config(self, name_or_uri, global_config_uri=None, verbose=False, i
927958 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" )
928959 result = cu
929960 if result is None :
930- if not self .load_configs ( stopatnameoruri = name_or_uri , verbose = verbose , incremental = incremental ):
961+ # if not self.load_configs( stopatnameoruri=name_or_uri, verbose=verbose, incremental=incremental ):
962+ if not self .load_configs ( stopatnameoruri = name_or_uri , verbose = verbose , incremental = True ):
931963 # config not found - give up (if found, this loops back to scan for the config again
932964 break
933965# print( f"GLC {result} {self=} {name_or_uri=}" )
@@ -1101,7 +1133,8 @@ def _load_type_from_resource_shape(self, el, supershape=None):
11011133 range_xml = self ._get_typeuri_rdf (range_uri )
11021134# print( f"{range_xml=} {ET.tostring(range_xml)}" )
11031135 if range_xml :
1104- enum_els = rdfxml .xml_find_elements (range_xml , './/rdf:Description/rdf:value/..' )
1136+ # enum_els = rdfxml.xml_find_elements(range_xml, './/rdf:Description/rdf:value/..')
1137+ enum_els = rdfxml .xml_find_elements (range_xml , './/dng_types:EnumEntry/rdf:value/..' )
11051138# print( f"{enum_els=}" )
11061139 # now process any enumeration values
11071140 for enum_el in enum_els :
0 commit comments