summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorKohei Yoshida <kyoshida@novell.com>2009-12-23 18:51:19 -0500
committerKohei Yoshida <kyoshida@novell.com>2009-12-23 18:51:19 -0500
commit0ab5dd74d986ec69db3d6ea8ccea1908601fd338 (patch)
tree75db2b978e45989b807320929adbae1662dac9e7 /source
parent2e2fd65997b0029571905f07ecd9ad7c77ca10ca (diff)
Finished parsing the 'tree' xml files.
The '.tree' files define the structure of the help contents.
Diffstat (limited to 'source')
-rw-r--r--source/node.py11
-rw-r--r--source/tree.py49
2 files changed, 59 insertions, 1 deletions
diff --git a/source/node.py b/source/node.py
index 0296993..dc37dcb 100644
--- a/source/node.py
+++ b/source/node.py
@@ -57,10 +57,12 @@ class Content(NodeBase):
self.content = content
class Element(NodeBase):
- def __init__ (self, name, attrs={}):
+ def __init__ (self, name, attrs=None):
NodeBase.__init__(self, NodeType.Element)
self.name = name
self.attrs = attrs
+ if self.attrs == None:
+ self.attrs = {}
def getContent (self):
text = ''
@@ -76,6 +78,13 @@ class Element(NodeBase):
text += child.getContent()
return text
+ def getAttrByName (self, name):
+ if not self.attrs.has_key(name):
+ return None
+ return self.attrs[name]
+
+ def setAttr (self, name, val):
+ self.attrs[name] = val
encodeTable = {
'>': 'gt',
diff --git a/source/tree.py b/source/tree.py
new file mode 100644
index 0000000..b859e6e
--- /dev/null
+++ b/source/tree.py
@@ -0,0 +1,49 @@
+
+import sys
+import globals, node
+
+class TreeBuilder:
+ def __init__ (self, treeroots):
+ self.treeroots = treeroots
+ self.root = node.Root()
+
+ def build (self):
+
+ for key in self.treeroots.keys():
+ treeroot = self.treeroots[key]
+ treeview = treeroot.firstChild()
+ # tree_view node has one or more help_section elements.
+ for helpsection in treeview.getChildNodes():
+ if helpsection.nodeType != node.NodeType.Element or helpsection.name != 'help_section':
+ continue
+
+ # help_section element has a 'title' attribute.
+ title = helpsection.getAttrByName('title')
+ elem = self.root.appendElement('section')
+ elem.setAttr('title', title)
+ for child in helpsection.getChildNodes():
+ self.__walkNode(child, elem)
+
+ node.prettyPrint(sys.stdout, self.root)
+
+ def __walkNode (self, src, dest):
+ if src.nodeType != node.NodeType.Element:
+ return
+
+ # 'topic' is a leaf node while 'node' is a non-leaf node.
+ if src.name == 'topic':
+ # the 'id' attribute contains the corresponding xhp file path, while
+ # the content of this element is the title of this section.
+ xhppath = src.getAttrByName('id')
+ title = src.getContent()
+ elem = dest.appendElement('section')
+ elem.setAttr('title', title)
+ elem.setAttr('path', xhppath)
+ elif src.name == 'node':
+ # A 'node' element is just a branch point; it doesn't have any content.
+ title = src.getAttrByName('title')
+ elem = dest.appendElement('section')
+ elem.setAttr('title', title)
+ for child in src.getChildNodes():
+ self.__walkNode(child, elem)
+