diff options
author | 2010-06-17 06:33:47 -0400 | |
---|---|---|
committer | 2010-06-17 06:33:47 -0400 | |
commit | 49e24578a03bfb7d820e05053ce1b92fc7e47d7d (patch) | |
tree | 8a18e8fb4c2f94515b98ea5190bd93a6ed11969b | |
parent | Various bug fixes and rearragments in tree build. Working better, not perfect. (diff) | |
download | ventoo-49e24578a03bfb7d820e05053ce1b92fc7e47d7d.tar.gz ventoo-49e24578a03bfb7d820e05053ce1b92fc7e47d7d.tar.bz2 ventoo-49e24578a03bfb7d820e05053ce1b92fc7e47d7d.zip |
Added 'probe' flag to the edit tree build function to mark cases where the function is visiting nodes that may not exist and children should not be blindly built as is the parent was there. This fixes the case where there are duplicates in the root of a tree and the children of 0 parents were created.
-rw-r--r-- | src/ventoo/main.py | 80 |
1 files changed, 42 insertions, 38 deletions
diff --git a/src/ventoo/main.py b/src/ventoo/main.py index 9916a26..badf447 100644 --- a/src/ventoo/main.py +++ b/src/ventoo/main.py @@ -249,7 +249,7 @@ class MainWindow(gtk.Window): mRoot = model.get_iter_root() #path into xml description of the tree xRoot = '/VentooModule/root' - self.__buildEditModel(model, aRoot, mRoot, xRoot) + self.__buildEditModel(model, aRoot, mRoot, xRoot, False) """ this is the workhorse behind refreshAugeasEditTree() @@ -257,7 +257,10 @@ class MainWindow(gtk.Window): It can be considered the core of the whole program actually. This code has to be rock solid. """ - def __buildEditModel(self, model, augeasFileRoot, modelPathIter, xmlRoot): + # Sometimes we are at the root node + # but don't want to build the children + # so this flag is used. + def __buildEditModel(self, model, augeasFileRoot, modelPathIter, xmlRoot, buildChildren = True): xElemRoot = self.currentModule.getChildrenOf(osp.join(xmlRoot, '*')) xChildren = list(self.currentModule.getChildrenOf(xmlRoot)) thisMult = self.currentModule.getMultOf(xmlRoot) @@ -304,42 +307,43 @@ class MainWindow(gtk.Window): created = model.append(modelPathIter, [False, str(maxIndex+1), '-------']) maxIndex += 1 else: - listedNodes = [] #a list of nodes that we already found and know about. - for child in xChildren: - #build get a list of either [child.tag] or [child.tag[1], child.tag[n]] - childMult = self.currentModule.getMultOf(osp.join(xmlRoot, child.tag)) - matches = self.a.match(osp.join(augeasFileRoot, child.tag)) - matches.extend(self.a.match(osp.join(augeasFileRoot, child.tag)+'[*]')) - matches = list(set(matches)) #remove dups from matches - listedNodes.extend(matches) - - for match in matches: - userData = self.a.get(match) #add all existing data - if userData == None: - userData = '' - created = model.append(modelPathIter, [True, osp.split(match)[1], userData]) - self.__buildEditModel(model, match, created, osp.join(xmlRoot, child.tag)) - - #add leaves if we're missing some required ones (in augeas itself) - have = len(matches) - toAddtoHave = 0 - numNeeded = augeas_utils.matchDiff(childMult, have) - for i in range(have+1, have+numNeeded+1): - p = osp.join(augeasFileRoot, child.tag) - if have+numNeeded > 1: - p = p + '[' + str(i) + ']' - print 'added ' + p + ' to augeas' - self.a.set(p, '') - toAddtoHave += 1 - have += toAddtoHave - - #maybe we need to add more of child to the tree, and maybe even an option for the user. - #this code is different from the rest because it doesn't update the augeas tree, it only - #tells the user that the tree COULD be undated along this 'child' variable/branch. - needed = not augeas_utils.matchExact(childMult, have) - if needed: - created = model.append(modelPathIter, [False, child.tag + '[' + str(have+1) + ']', '']) - + listedNodes = [] #a list of nodes that we already found and know about. + if buildChildren: + for child in xChildren: + #build get a list of either [child.tag] or [child.tag[1], child.tag[n]] + childMult = self.currentModule.getMultOf(osp.join(xmlRoot, child.tag)) + matches = self.a.match(osp.join(augeasFileRoot, child.tag)) + matches.extend(self.a.match(osp.join(augeasFileRoot, child.tag)+'[*]')) + matches = list(set(matches)) #remove dups from matches + listedNodes.extend(matches) + + for match in matches: + userData = self.a.get(match) #add all existing data + if userData == None: + userData = '' + created = model.append(modelPathIter, [True, osp.split(match)[1], userData]) + self.__buildEditModel(model, match, created, osp.join(xmlRoot, child.tag)) + + #add leaves if we're missing some required ones (in augeas itself) + have = len(matches) + toAddtoHave = 0 + numNeeded = augeas_utils.matchDiff(childMult, have) + for i in range(have+1, have+numNeeded+1): + p = osp.join(augeasFileRoot, child.tag) + if have+numNeeded > 1: + p = p + '[' + str(i) + ']' + print 'added ' + p + ' to augeas' + self.a.set(p, '') + toAddtoHave += 1 + have += toAddtoHave + + #maybe we need to add more of child to the tree, and maybe even an option for the user. + #this code is different from the rest because it doesn't update the augeas tree, it only + #tells the user that the tree COULD be undated along this 'child' variable/branch. + needed = not augeas_utils.matchExact(childMult, have) + if needed: + created = model.append(modelPathIter, [False, child.tag + '[' + str(have+1) + ']', '']) + #now search for and add nodes that haven't been added yet, and may not be in the VentooModule specifically. allInAugeas = self.a.match(osp.join(augeasFileRoot, '*')) lastLineWasDoc = False |