1"""Build the C client docs.
2"""
3
4from __future__ import with_statement
5import os
6import shutil
7import socket
8import subprocess
9import time
10import urllib2
11
12def clean_dir(dir):
13    try:
14        shutil.rmtree(dir)
15    except:
16        pass
17    os.makedirs(dir)
18
19def gen_api(dir):
20    clean_dir(dir)
21    clean_dir("docs/source/doxygen")
22
23    with open(os.devnull, 'w') as null:
24        subprocess.call(["doxygen", "doxygenConfig"], stdout=null, stderr=null)
25
26    os.rename("docs/source/doxygen/html", dir)
27
28def gen_sphinx(dir):
29    clean_dir(dir)
30    os.chdir("docs/source/sphinx")
31
32    with open(os.devnull, 'w') as null:
33        subprocess.call(["make", "html"], stdout=null, stderr=null)
34
35    os.chdir("../../../")
36    os.rename("docs/source/sphinx/build/html", dir)
37
38def version():
39    """Get the driver version from doxygenConfig.
40    """
41    with open("doxygenConfig") as f:
42        for line in f.readlines():
43            if line.startswith("PROJECT_NUMBER"):
44                return line.split("=")[1].strip()
45
46
47def main():
48    print("Generating Sphinx docs in docs/html")
49    gen_sphinx("docs/html")
50    print("Generating Doxygen docs in docs/html/api")
51    gen_api("docs/html/api")
52
53
54if __name__ == "__main__":
55    main()
56
57