"""Build the C client docs.
"""

from __future__ import with_statement
import os
import shutil
import socket
import subprocess
import time
import urllib2

def clean_dir(dir):
    try:
        shutil.rmtree(dir)
    except:
        pass
    os.makedirs(dir)

def gen_api(dir):
    clean_dir(dir)
    clean_dir("docs/source/doxygen")

    with open(os.devnull, 'w') as null:
        subprocess.call(["doxygen", "doxygenConfig"], stdout=null, stderr=null)

    os.rename("docs/source/doxygen/html", dir)

def gen_sphinx(dir):
    clean_dir(dir)
    os.chdir("docs/source/sphinx")

    with open(os.devnull, 'w') as null:
        subprocess.call(["make", "html"], stdout=null, stderr=null)

    os.chdir("../../../")
    if os.path.isdir("docs/source/sphinx/build/html"):
        os.rename("docs/source/sphinx/build/html", dir)

def version():
    """Get the driver version from doxygenConfig.
    """
    with open("doxygenConfig") as f:
        for line in f.readlines():
            if line.startswith("PROJECT_NUMBER"):
                return line.split("=")[1].strip()


def main():
    print("Generating Sphinx docs in docs/html")
    gen_sphinx("docs/html")
    print("Generating Doxygen docs in docs/html/api")
    gen_api("docs/html/api")


if __name__ == "__main__":
    main()


[((17, 4, 17, 20), 'os.makedirs', 'os.makedirs', ({(17, 16, 17, 19): 'dir'}, {}), '(dir)', False, 'import os\n'), ((26, 4, 26, 46), 'os.rename', 'os.rename', ({(26, 14, 26, 40): '"""docs/source/doxygen/html"""', (26, 42, 26, 45): 'dir'}, {}), "('docs/source/doxygen/html', dir)", False, 'import os\n'), ((30, 4, 30, 34), 'os.chdir', 'os.chdir', ({(30, 13, 30, 33): '"""docs/source/sphinx"""'}, {}), "('docs/source/sphinx')", False, 'import os\n'), ((35, 4, 35, 25), 'os.chdir', 'os.chdir', ({(35, 13, 35, 24): '"""../../../"""'}, {}), "('../../../')", False, 'import os\n'), ((36, 7, 36, 53), 'os.path.isdir', 'os.path.isdir', ({(36, 21, 36, 52): '"""docs/source/sphinx/build/html"""'}, {}), "('docs/source/sphinx/build/html')", False, 'import os\n'), ((14, 8, 14, 26), 'shutil.rmtree', 'shutil.rmtree', ({(14, 22, 14, 25): 'dir'}, {}), '(dir)', False, 'import shutil\n'), ((24, 8, 24, 79), 'subprocess.call', 'subprocess.call', (), '', False, 'import subprocess\n'), ((33, 8, 33, 67), 'subprocess.call', 'subprocess.call', (), '', False, 'import subprocess\n'), ((37, 8, 37, 55), 'os.rename', 'os.rename', ({(37, 18, 37, 49): '"""docs/source/sphinx/build/html"""', (37, 51, 37, 54): 'dir'}, {}), "('docs/source/sphinx/build/html', dir)", False, 'import os\n')]