2
# -*- Mode: Python; py-indent-offset: 4 -*-
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'))
21
def scan_index_file(ifile):
22
buf = open(ifile).read()
23
for id, href in anchor_pat.findall(buf):
27
for f in os.listdir(hdir):
28
if os.path.splitext(f)[1] == '.html':
29
fix_html_file(os.path.join(hdir, f))
33
if anchors.has_key(id):
34
return '<a\nhref="../' + anchors[id] + '"\n>' + text + '</a>'
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)
44
sys.stderr.write('fixxref.py: %s\n' % e)
45
sys.stderr.write('usage: fixxref.py [-i index-dir] html-dir\n')
48
if __name__ == '__main__':
50
opts, args = getopt.getopt(sys.argv[1:], "i:h:",
51
["index-dir=", "html-dir="])
52
except getopt.error, e:
57
if opt in ('-i', '--index-dir'):
58
index_dirs.append(arg)
63
for idir in index_dirs: