summaryrefslogtreecommitdiff
path: root/doc/redirects.py
blob: 8d41a11e1c6145ce4cbdfe008b992697803f6071 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/python

# Copyright 2018-2019 Collabora Ltd.
# SPDX-License-Identifier: MIT

import os

SRCDIR = os.environ.get('DBUS_TOP_SRCDIR', '.')

if __name__ == '__main__':
    with open(os.path.join(SRCDIR, 'doc', 'redirects'), 'r') as reader:
        for line in reader:
            line = line.strip()

            if not line:
                continue

            if line.startswith('#'):
                continue

            page, dest = line.split(None, 1)

            try:
                os.makedirs(os.path.join('doc', '_build', os.path.dirname(page)))
            except OSError:
                pass

            assert not os.path.exists(os.path.join('doc', '_build', page))

            if dest.startswith('"'):
                assert page.endswith('.txt')
                text = dest.strip('"')

                with open(os.path.join('doc', '_build', page), 'w') as writer:
                    writer.write(text)
                    writer.write('\n')
            else:
                assert page.endswith('.html')

                with open(os.path.join('doc', '_build', page), 'w') as writer:
                    writer.write(
                        '<meta http-equiv="refresh" content="0; url={}" />\n'.format(
                            dest))
                    writer.write(
                        'See <a href="{}">{}</a>\n'.format(
                            dest, dest))