summaryrefslogtreecommitdiff
path: root/docs/xsl/fixxref.py
diff options
context:
space:
mode:
authorinfirit <[email protected]>2014-01-08 17:18:07 +0100
committerinfirit <[email protected]>2014-01-08 17:18:07 +0100
commit8cd560b2f3ba55a1ac45f4dcd859f8470897ffe4 (patch)
tree6117cb4524e23e78e6bf8bbf7a0cfca460908983 /docs/xsl/fixxref.py
parent2ff6fb9f311f46c757fdbff994b6c45673b1369d (diff)
downloadpython-caja-8cd560b2f3ba55a1ac45f4dcd859f8470897ffe4.tar.bz2
python-caja-8cd560b2f3ba55a1ac45f4dcd859f8470897ffe4.tar.xz
Bring gtk-doc up to date.
It should build again and be properly included with make dist. Based on nautilus-python changes, see below for the details. https://git.gnome.org/browse/nautilus-python/log/docs?h=nautilus-3.0
Diffstat (limited to 'docs/xsl/fixxref.py')
-rwxr-xr-xdocs/xsl/fixxref.py67
1 files changed, 67 insertions, 0 deletions
diff --git a/docs/xsl/fixxref.py b/docs/xsl/fixxref.py
new file mode 100755
index 0000000..f3287b3
--- /dev/null
+++ b/docs/xsl/fixxref.py
@@ -0,0 +1,67 @@
+#!/usr/bin/env python
+# -*- Mode: Python; py-indent-offset: 4 -*-
+
+import getopt
+import os
+import re
+import sys
+
+anchors = {}
+anchor_pat = re.compile(r'''^\s*<ANCHOR\s+id\s*=\s*"([^"]*)"\s+
+ href\s*=\s*"([^"]*)"\s*>''',
+ re.MULTILINE | re.VERBOSE)
+link_pat = re.compile(r'''<PYGTKDOCLINK\s+HREF="([^"]*)"\s*>(.*?)
+ </PYGTKDOCLINK\s*>''', re.DOTALL | re.VERBOSE)
+def scan_index_dir(idir):
+ for root, dirs, files in os.walk(idir):
+ if 'index.sgml' in files:
+ scan_index_file(os.path.join(root, 'index.sgml'))
+ return
+
+def scan_index_file(ifile):
+ buf = open(ifile).read()
+ for id, href in anchor_pat.findall(buf):
+ anchors[id] = href
+
+def fix_xrefs(hdir):
+ for f in os.listdir(hdir):
+ if os.path.splitext(f)[1] == '.html':
+ fix_html_file(os.path.join(hdir, f))
+
+def link_subst(m):
+ id, text = m.groups()
+ if anchors.has_key(id):
+ return '<a\nhref="../' + anchors[id] + '"\n>' + text + '</a>'
+ return text
+
+def fix_html_file(hfile):
+ buf = open(hfile).read()
+ buf = link_pat.sub(link_subst, buf)
+ open(hfile, 'w').write(buf)
+
+def usage(e=None):
+ if e:
+ sys.stderr.write('fixxref.py: %s\n' % e)
+ sys.stderr.write('usage: fixxref.py [-i index-dir] html-dir\n')
+ sys.exit(1)
+
+if __name__ == '__main__':
+ try:
+ opts, args = getopt.getopt(sys.argv[1:], "i:h:",
+ ["index-dir=", "html-dir="])
+ except getopt.error, e:
+ usage(e)
+
+ index_dirs = []
+ for opt, arg in opts:
+ if opt in ('-i', '--index-dir'):
+ index_dirs.append(arg)
+
+ if len(args) != 1:
+ usage()
+
+ for idir in index_dirs:
+ scan_index_dir(idir)
+
+ html_dir = args[0]
+ fix_xrefs(html_dir)