#!/usr/bin/python

import os
import sys
import platform
import shutil
import subprocess

def create_page(orig_path, page_name, page_header):
    orig = open(orig_path)
    dest = open("Temp/" + os.path.split(orig_path)[1] + ".txt", "w")
    dest.write("/** @page " + page_name + " " + page_header + "\n")
    dest.write(orig.read())
    dest.write("\n*/")
    orig.close()
    dest.close()
   
beforeDir = os.getcwd()
scriptDir = os.path.dirname(sys.argv[0])
os.chdir(scriptDir)

# Start with C++ reference
   
# create Legal page
if os.path.isdir("Temp"):
    shutil.rmtree("Temp")
os.mkdir("Temp")
create_page("../../NOTICE", "legal", "Legal Stuff & Acknowledgments")
create_page("../../ReleaseNotes.txt", "release_notes", "Release Notes")

errfile = "Temp/doxygen_error"
subprocess.check_call(["doxygen", "Doxyfile"], stdout=open(os.devnull,"w"), stderr=open(errfile,"w"))

# create Java
javaDocExe = ""
if platform.system() == 'Windows':
    javaDocExe = os.path.expandvars(os.path.join('$JAVA_HOME', 'bin', 'javadoc.exe'))
else:
    javaDocExe = 'javadoc'

javaSrc = os.path.join(scriptDir, '..', '..', 'Wrappers', 'java', 'OpenNI.java', 'src', 'org', 'openni', '*')

errfile = "Temp/javadoc_error"
subprocess.check_call([javaDocExe, '-d', 'java', javaSrc], stdout=open(os.devnull,"w"), stderr=open(errfile,"w"))

os.chdir(beforeDir)
@@ -1162,13 +1162,229 @@
 nni'
-, '*'
+)%0A%0A# workaround a strange linux behavior where you must pass the list of files%0Acmd = %5BjavaDocExe, '-d', 'java'%5D%0Afor root, dirs, files in os.walk(javaSrc):%0A    for file in files:%0A        cmd.append(os.path.join(root, file)
 )%0A%0Ae
@@ -1439,43 +1439,11 @@
 all(
-%5BjavaDocExe, '-d', 'java', javaSrc%5D
+cmd
 , st
@@ -1511,12 +1511,13 @@
 r(beforeDir)
+%0A

Fix javadoc creation on Linux