aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/ventoo/main.py')
-rw-r--r--src/ventoo/main.py80
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