[Telepathy-commits] [telepathy-qt4/master] xincludator.py: correctly interpret href as relative to the source document

Simon McVittie simon.mcvittie at collabora.co.uk
Wed Nov 26 06:13:33 PST 2008


This assumes Unix filenames, but so did the previous code.

This fixes out-of-tree builds, as used by `make distcheck`.
---
 tools/xincludator.py |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/tools/xincludator.py b/tools/xincludator.py
index 0b673c9..63e106a 100644
--- a/tools/xincludator.py
+++ b/tools/xincludator.py
@@ -2,13 +2,14 @@
 
 from sys import argv, stdout, stderr
 import codecs, locale
+import os
 import xml.dom.minidom
 
 stdout = codecs.getwriter('utf-8')(stdout)
 
 NS_XI = 'http://www.w3.org/2001/XInclude'
 
-def xincludate(dom, dropns = []):
+def xincludate(dom, base, dropns = []):
     remove_attrs = []
     for i in xrange(dom.documentElement.attributes.length):
         attr = dom.documentElement.attributes.item(i)
@@ -21,8 +22,10 @@ def xincludate(dom, dropns = []):
         dom.documentElement.removeAttributeNode(attr)
     for include in dom.getElementsByTagNameNS(NS_XI, 'include'):
         href = include.getAttribute('href')
-        subdom = xml.dom.minidom.parse(href)
-        xincludate(subdom, dropns)
+        # FIXME: assumes Unixy paths
+        filename = os.path.join(os.path.dirname(base), href)
+        subdom = xml.dom.minidom.parse(filename)
+        xincludate(subdom, filename, dropns)
         if './' in href:
             subdom.documentElement.setAttribute('xml:base', href)
         include.parentNode.replaceChild(subdom.documentElement, include)
@@ -30,7 +33,7 @@ def xincludate(dom, dropns = []):
 if __name__ == '__main__':
     argv = argv[1:]
     dom = xml.dom.minidom.parse(argv[0])
-    xincludate(dom)
+    xincludate(dom, argv[0])
     xml = dom.toxml()
     stdout.write(xml)
     stdout.write('\n')
-- 
1.5.6.5




More information about the Telepathy-commits mailing list