"""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, 'os.makedirs', 'os.makedirs', (['dir'], {}), False, 'import os\n'), (26, 'os.rename', 'os.rename', (['"""docs/source/doxygen/html"""', 'dir'], {}), False, 'import os\n'), (30, 'os.chdir', 'os.chdir', (['"""docs/source/sphinx"""'], {}), False, 'import os\n'), (35, 'os.chdir', 'os.chdir', (['"""../../../"""'], {}), False, 'import os\n'), (36, 'os.path.isdir', 'os.path.isdir', (['"""docs/source/sphinx/build/html"""'], {}), False, 'import os\n'), (14, 'shutil.rmtree', 'shutil.rmtree', (['dir'], {}), False, 'import shutil\n'), (24, 'subprocess.call', 'subprocess.call', (["['doxygen', 'doxygenConfig']"], {'stdout': 'null', 'stderr': 'null'}), False, 'import subprocess\n'), (33, 'subprocess.call', 'subprocess.call', (["['make', 'html']"], {'stdout': 'null', 'stderr': 'null'}), False, 'import subprocess\n'), (37, 'os.rename', 'os.rename', (['"""docs/source/sphinx/build/html"""', 'dir'], {}), False, 'import os\n')]