File: removeexamples.py

package info (click to toggle)
igraph 1.0.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 22,444 kB
  • sloc: ansic: 155,759; cpp: 32,544; xml: 2,960; python: 411; makefile: 168; javascript: 20; sh: 9
file content (37 lines) | stat: -rw-r--r-- 749 bytes parent folder | download | duplicates (5)
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
#!/usr/bin/env python3
"""Helper script used to remove the bundled examples from the DocBook files
that are used to generate the PDF documentation.

This file is part of the documentation build process. You do not need to call
it manually.
"""

import sys
from xml.etree.ElementTree import ElementTree


def usage():
    print(sys.argv[0], "<infile> <outfile>")


def main():
    if len(sys.argv) != 3:
        usage()
        sys.exit(2)

    # Read in
    tree = ElementTree()
    tree.parse(sys.argv[1])

    # Remove examples
    examples = tree.findall(".//example")
    for ex in examples:
        prog = ex.find("programlisting")
        ex.remove(prog)

    # Write result
    tree.write(sys.argv[2])


if __name__ == "__main__":
    main()