Display xpointer details to simplify debugging.
[treecutter.git] / treecutter / page.py
index 9f27c918e7a257b34ebd85860c199901618d5994..1cb2bafe9b19a809b5ea9df334a5bdeb0b82dd97 100644 (file)
@@ -6,6 +6,7 @@ from amara import bindery
 from amara.xslt import transform
 from Cheetah.Template import Template
 from pkg_resources import resource_filename, resource_listdir
+from time import time
 import treecutter.const as const
 from treecutter.tools import mkdir_p
 
@@ -41,6 +42,7 @@ class Page():
             self._menu = unicode(self._doc.article.info.titleabbrev)
 
         dirname = os.path.dirname(self._file)
+        cwd = os.getcwd()
         code  = self._doc.xml_select(u"//xi:include[@parse='text']")
         if code:
             for c in code:
@@ -51,8 +53,6 @@ class Page():
                     if os.path.isfile(script):
                         exe.append(script)
                     else:
-                        print resource_listdir('xinclude', '')
-                        print resource_filename('xinclude', c.href)
                         if c.href in resource_listdir('xinclude', ''):
                             script = resource_filename('xinclude', c.href)
                             exe.append(script)
@@ -63,8 +63,14 @@ class Page():
                         exe.append("lang="+alang)
                     if c.xml_select(u"//xi:include[@xpointer]"):
                         exe.append("xptr="+c.xpointer)
+                    print "  executing %15s" % (c.href),
+                    ts = time()
+                    os.chdir(dirname)
                     xml = subprocess.Popen(exe,stdout=subprocess.PIPE)
+                    os.chdir(cwd)
                     xmlblock = str(xml.stdout.read())
+                    te = time()
+                    print " [%5.2f s]  (%s)" % (round(te-ts,2),c.xpointer)
                     xstr = bindery.parse(xmlblock)
                     idp = c.xml_index_on_parent
                     for x in xstr.xml_children: