~ubuntu-branches/ubuntu/saucy/nautilus-python/saucy-proposed

« back to all changes in this revision

Viewing changes to docs/xsl/fixxref.py

  • Committer: Package Import Robot
  • Author(s): Laurent Bigonville
  • Date: 2011-10-19 22:04:10 UTC
  • mfrom: (1.1.7) (7.1.6 sid)
  • Revision ID: package-import@ubuntu.com-20111019220410-ynj2zfdo631954ix
Tags: 1.1-1
* New upstream release.
  - Transition to nautilus 3 (Closes: #637315)
* debian/control.in:
  - Adjusts {build-}dependencies
  - Bump Standards-Version to 3.9.2 (no further changes)
  - Add Vcs-* fields
* Switch to dpkg-source 3.0 (quilt) format
* debian/dirs: Create system-wide extensions directory to new location
* debian/watch: Switch to .xz tarballs
* debian/README.Debian: Update to new locations
* debian/lintian-overrides: Add an override for the empty system-wide
  extensions directory
* debian/copyright: Add missing copyright statements

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
# -*- Mode: Python; py-indent-offset: 4 -*-
 
3
 
 
4
import getopt
 
5
import os
 
6
import re
 
7
import sys
 
8
 
 
9
anchors = {}
 
10
anchor_pat = re.compile(r'''^\s*<ANCHOR\s+id\s*=\s*"([^"]*)"\s+
 
11
                            href\s*=\s*"([^"]*)"\s*>''',
 
12
                        re.MULTILINE | re.VERBOSE)
 
13
link_pat = re.compile(r'''<PYGTKDOCLINK\s+HREF="([^"]*)"\s*>(.*?)
 
14
                          </PYGTKDOCLINK\s*>''', re.DOTALL | re.VERBOSE)
 
15
def scan_index_dir(idir):
 
16
    for root, dirs, files in os.walk(idir):
 
17
        if 'index.sgml' in files:
 
18
            scan_index_file(os.path.join(root, 'index.sgml'))
 
19
    return
 
20
 
 
21
def scan_index_file(ifile):
 
22
    buf = open(ifile).read()
 
23
    for id, href in anchor_pat.findall(buf):
 
24
        anchors[id] = href
 
25
 
 
26
def fix_xrefs(hdir):
 
27
    for f in os.listdir(hdir):
 
28
        if os.path.splitext(f)[1] == '.html':
 
29
            fix_html_file(os.path.join(hdir, f))
 
30
 
 
31
def link_subst(m):
 
32
    id, text = m.groups()
 
33
    if anchors.has_key(id):
 
34
        return '<a\nhref="../' + anchors[id] + '"\n>' + text + '</a>'
 
35
    return text
 
36
 
 
37
def fix_html_file(hfile):
 
38
    buf = open(hfile).read()
 
39
    buf = link_pat.sub(link_subst, buf)
 
40
    open(hfile, 'w').write(buf)
 
41
 
 
42
def usage(e=None):
 
43
    if e:
 
44
        sys.stderr.write('fixxref.py: %s\n' % e)
 
45
    sys.stderr.write('usage: fixxref.py [-i index-dir] html-dir\n')
 
46
    sys.exit(1)
 
47
 
 
48
if __name__ == '__main__':
 
49
    try:
 
50
        opts, args = getopt.getopt(sys.argv[1:], "i:h:",
 
51
                                   ["index-dir=", "html-dir="])
 
52
    except getopt.error, e:
 
53
        usage(e)
 
54
 
 
55
    index_dirs = []
 
56
    for opt, arg in opts:
 
57
        if opt in ('-i', '--index-dir'):
 
58
            index_dirs.append(arg)
 
59
 
 
60
    if len(args) != 1:
 
61
        usage()
 
62
 
 
63
    for idir in index_dirs:
 
64
        scan_index_dir(idir)
 
65
 
 
66
    html_dir = args[0]
 
67
    fix_xrefs(html_dir)