Adding some getters and setters to Class Page.
[treecutter.git] / src / tree-cutter.py
index 4c0f01946f1e748d45c23bef388fbf4110ba5d3b..b764af41c7822e3fe016c8537206fb0bbca963b0 100755 (executable)
@@ -26,6 +26,8 @@ style_xslt = args.style+"docbook.xsl"
 style_tmpl = args.style+"index.en.html.tmpl"
 outputdir = args.output
 
+tmptarget = tempfile.mkdtemp()+'/'
+
 valid_scripts = ['.py','.pl']
 MAXLEVEL = 10000
 
@@ -81,12 +83,21 @@ class Page():
         self._menu = None
         self._rendered_article = None
 
+    def language(self):
+        return self._lang
+
+    def menu(self):
+        return self._menu
+
+    def set_article(self,art):
+        self._rendered_article = art
+
     def prepare(self):
         self._doc = bindery.parse(self._file, prefixes=PREFIXES)
         if self._doc.xml_select(u'/db:article/db:info/db:title'):
-            self._title = unicode(doc.article.info.title)
+            self._title = unicode(self._doc.article.info.title)
         if self._doc.xml_select(u'/db:article/db:info/db:titleabbrev'):
-            self._menu = unicode(doc.article.info.titleabbrev)
+            self._menu = unicode(self._doc.article.info.titleabbrev)
 
         dirname = os.path.dirname(self._file)
         code  = self._doc.xml_select(u"//xi:include[@parse='text']")
@@ -120,7 +131,7 @@ class Page():
         infile  = os.path.basename(tempfile.mktemp())
         outfile = tempfile.mktemp()
         tfi = open(infile,'w')
-        tfi.write(doc.xml_encode())
+        tfi.write(self._doc.xml_encode())
         tfi.close()
 #  cmd = ["saxon-xslt-xinclude","-o",outfile,infile,style_xslt]
         cmd = ["xsltproc","--xinclude","--output",outfile,style_xslt,infile]
@@ -193,6 +204,15 @@ class Trie():
     def __init__(self):
         self._root = []
 
+    def __iter__(self):
+        return self.inorder(self._root)
+
+    def inorder(self,t):
+        for l in t:
+            yield l.value()
+            for ch in l.children():
+                self.inorder(ch)
+
     def _add(self,trie, key, content):
         # is the key a leaf
         k = key.pop(0)
@@ -222,7 +242,7 @@ class Trie():
         self._graph(self._root, G)
 #        G.layout('dot')
 #        G.draw('g.png')
-        print G.string()
+#        print G.string()
 
 class Sitemap():
     """Class keeping the internal site structure"""