"""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()


[((240, 256), 'os.makedirs', 'os.makedirs', (['dir'], {}), '(dir)\n', (251, 256), False, 'import os\n'), ((458, 500), 'os.rename', 'os.rename', (['"""docs/source/doxygen/html"""', 'dir'], {}), "('docs/source/doxygen/html', dir)\n", (467, 500), False, 'import os\n'), ((546, 576), 'os.chdir', 'os.chdir', (['"""docs/source/sphinx"""'], {}), "('docs/source/sphinx')\n", (554, 576), False, 'import os\n'), ((691, 712), 'os.chdir', 'os.chdir', (['"""../../../"""'], {}), "('../../../')\n", (699, 712), False, 'import os\n'), ((720, 766), 'os.path.isdir', 'os.path.isdir', (['"""docs/source/sphinx/build/html"""'], {}), "('docs/source/sphinx/build/html')\n", (733, 766), False, 'import os\n'), ((192, 210), 'shutil.rmtree', 'shutil.rmtree', (['dir'], {}), '(dir)\n', (205, 210), False, 'import shutil\n'), ((381, 452), 'subprocess.call', 'subprocess.call', (["['doxygen', 'doxygenConfig']"], {'stdout': 'null', 'stderr': 'null'}), "(['doxygen', 'doxygenConfig'], stdout=null, stderr=null)\n", (396, 452), False, 'import subprocess\n'), ((626, 685), 'subprocess.call', 'subprocess.call', (["['make', 'html']"], {'stdout': 'null', 'stderr': 'null'}), "(['make', 'html'], stdout=null, stderr=null)\n", (641, 685), False, 'import subprocess\n'), ((776, 823), 'os.rename', 'os.rename', (['"""docs/source/sphinx/build/html"""', 'dir'], {}), "('docs/source/sphinx/build/html', dir)\n", (785, 823), False, 'import os\n')]