import os
import shutil
import time
import sys
import argparse
import re
import opengl
import glsl
import shared
import shared_glsl
import subprocess
import platform
sys.path.append("htmlmin")
import htmlmin
parser = argparse.ArgumentParser(description="Compile openGL documentation, generate a static webpage.")
parser.add_argument('--full', dest='buildmode', action='store_const', const='full', default='fast', help='Full build (Default: fast build)')
parser.add_argument('--only-glsl', dest='buildtype', action='store_const', const='glsl', default='all', help='build OpenGL docs only (Default: GL and GLSL)')
parser.add_argument('--only-gl', dest='buildtype', action='store_const', const='gl', default='all', help='build GLSL docs only (Default: GL and GLSL)')
args = parser.parse_args()
if args.buildmode == 'full':
print "FULL BUILD"
else:
print "FAST BUILD"
if args.buildtype == 'glsl':
print "BUILD GLSL Docs only"
elif args.buildtype == 'gl':
print "BUILD OpenGL Docs only"
else:
print "BUILD OpenGL and GLSL Docs only"
def create_directory(dir):
if not os.path.exists(dir):
os.makedirs(dir)
output_dir = ""
if args.buildtype == 'glsl':
output_dir = "glsl_htdocs/"
elif args.buildtype == 'gl':
output_dir = "htdocs/"
else:
output_dir = "all_htdocs/"
print "Resetting output dir..."
while os.path.exists(output_dir):
try:
shutil.rmtree(output_dir);
except:
pass # It gives an error sometimes. If it didn't work try again.
while not os.path.exists(output_dir):
try:
create_directory(output_dir)
except:
pass # It gives an error sometimes. If it didn't work try again.
f = []
d = []
for (dirpath, dirnames, filenames) in os.walk("html/copy"):
dirpath = dirpath[10:]
if "test" in dirpath:
continue
d.append(dirpath)
for file in filenames:
if file[-3:] != '.js' and file[-4:] != '.css' and file[-4:] != '.png' and file[-5:] != '.html':
continue
if file == 'Gruntfile.js':
continue
f.append(dirpath + "/" + file)
for directory in d:
create_directory(output_dir + directory)
for file in f:
shutil.copy("html/copy/" + file, output_dir + file)
#Copy the docs.gl.js from the appropriate destination
if args.buildtype == 'glsl':
shutil.copy("glsl_html/" + "docs.gl.js", output_dir + "docs.gl.js")
#elif args.buildtype == 'gl':
#this has already been done for GL
#shutil.copy("html/copy/" + file, output_dir + file)
else:
shutil.copy("all_html/" + "docs.gl.js", output_dir + "docs.gl.js")
print "Copied " + str(len(f)) + " files"
print "Reading templates..."
header_path = ""
index_path = ""
#the header and index is different for each build
if args.buildtype == 'glsl':
header_path = "html/header.html" #not sure this may cause issues later
index_path = "glsl_html/index.html"
elif args.buildtype == 'gl':
header_path = "html/header.html"
index_path = "html/index.html"
else: #both GL GLSL
header_path = "all_html/header.html"
index_path = "all_html/index.html"
header_fp = open(header_path)
header = header_fp.read()
header_fp.close()
footer_fp = open("html/footer.html")
footer = footer_fp.read()
footer_fp.close()
search_fp = open("html/docs.gl.search.js")
search = search_fp.read()
search_fp.close()
index_fp = open(index_path)
index = index_fp.read()
index_fp.close()
print "Done."
if os.path.exists('html/copy/jquery.min.js'):
index = index.replace("{$jquery}", "")
else:
index = index.replace("{$jquery}", "")
if os.path.exists('html/copy/jquery-ui.min.js'):
index = index.replace("{$jqueryui}", "")
else:
index = index.replace("{$jqueryui}", '')
#openGL
index_commands_version = opengl.commands_version_flat.keys()
index_commands_version.sort()
index_versions_commands = ""
#GLSL
glsl_index_commands_version = glsl.commands_version_flat.keys()
glsl_index_commands_version.sort()
glsl_index_versions_commands = ""
#openGL
for command in index_commands_version:
#dirty but easy hack
if args.buildtype == 'glsl':
break
major_versions = opengl.get_major_versions_available(command)
aliases = {}
# Add aliases to this command. Need to do this because ES has glClearDepthf while GL has glClearDepth
for alias in opengl.aliased_functions[command]:
if alias == command:
continue
if alias in index_commands_version:
for version in opengl.get_major_versions_available(alias):
if not version in major_versions:
major_versions.append(version)
aliases[version] = alias
# If the command is an alias we've already done it, skip
if command in opengl.function_aliases and command != opengl.function_aliases[command] and opengl.function_aliases[command] in index_commands_version:
continue
latest_version = ''
all_major_versions_available = []
for version in major_versions:
if len(latest_version) == 0 or (latest_version[:2] == 'es' and version[:2] == 'gl') or (latest_version[:2] == version[:2] and float(version[2:]) > float(latest_version[2:])):
latest_version = version
all_major_versions_available.append(version)
index_versions_commands += "" + command + ""
index_versions_commands += ""
index_versions_commands += command
for alias in opengl.aliased_functions[command]:
if alias == command:
continue
index_versions_commands += " " + alias
index_versions_commands += ""
all_major_versions = opengl.get_major_versions(opengl.version_commands_flat.keys())
for version in all_major_versions:
if int(version[2:3]) < 2:
continue
alias = command
if version in aliases:
alias = aliases[version]
if version in all_major_versions_available:
index_versions_commands += "" + version + ""
else:
index_versions_commands += " "
index_versions_commands += "
\n"
#GLSL
for command in glsl_index_commands_version:
#dirty but easy hack
if args.buildtype == 'gl':
break;
major_versions = glsl.get_major_versions_available(command)
aliases = {}
# Add aliases to this command. Need to do this because ES has glClearDepthf while GL has glClearDepth
for alias in glsl.aliased_functions[command]:
if alias == command:
continue
if alias in index_commands_version:
for version in glsl.get_major_versions_available(alias):
if not version in major_versions:
major_versions.append(version)
aliases[version] = alias
# If the command is an alias we've already done it, skip
if command in glsl.function_aliases and command != glsl.function_aliases[command] and glsl.function_aliases[command] in glsl_index_commands_version:
continue
latest_version = ''
all_major_versions_available = []
for version in major_versions:
if len(latest_version) == 0 or (latest_version[:2] == 'el' and version[:2] == 'sl') or (latest_version[:2] == version[:2] and float(version[2:]) > float(latest_version[2:])):
latest_version = version
all_major_versions_available.append(version)
glsl_index_versions_commands += "" + command + ""
glsl_index_versions_commands += ""
glsl_index_versions_commands += command
for alias in glsl.aliased_functions[command]:
if alias == command:
continue
glsl_index_versions_commands += " " + alias
glsl_index_versions_commands += ""
all_major_versions = glsl.get_major_versions(glsl.version_commands_flat.keys())
for version in all_major_versions:
if int(version[2:3]) < 3:
continue
if version == "sl3":
continue
alias = command
if version in aliases:
alias = aliases[version]
if version in all_major_versions_available:
glsl_index_versions_commands += "" + version + ""
else:
glsl_index_versions_commands += " "
glsl_index_versions_commands += "
\n"
index = index.replace("{$commandlist}", index_versions_commands+glsl_index_versions_commands)
index_fp = open(output_dir + "/index.html", "w")
index_fp.write(index)
index_fp.close()
#################################################################
#openGL
search_versions_commands = "var search_versions = {"
search_function_aliases = {}
#GLSL
#we will append glsl_search_versions_commands to search_versions_commands
glsl_search_versions_commands = ""
glsl_search_function_aliases = {}
for version in opengl.version_commands:
if args.buildtype == 'glsl':
break;
if version[0:2] == "gl" and float(version[2:]) < 2.1:
continue
if version[0:2] == "es" and float(version[2:]) < 2.0:
continue
search_versions_commands += "'" + version + "':["
if not version[:2] in search_function_aliases:
search_function_aliases[version[:2]] = {}
included_commands = []
for command in opengl.version_commands[version]:
if not command in included_commands:
included_commands.append(command)
if command != opengl.version_commands[version][command]:
search_function_aliases[version[:2]][command] = opengl.version_commands[version][command]
for command in opengl.version_commands_flat[version]:
if not command in opengl.version_commands[version] and not command in included_commands:
included_commands.append(command)
included_commands.sort()
for command in included_commands:
search_versions_commands += "'" + command + "',"
search_versions_commands += "],"
for version in glsl.version_commands:
if args.buildtype == 'gl':
break;
if version[0:2] == "sl" and float(version[2:]) < 4.0:
continue
if version[0:2] == "el" and float(version[2:]) < 3.0:
continue
glsl_search_versions_commands += "'" + version + "':["
if not version[:2] in glsl_search_function_aliases:
glsl_search_function_aliases[version[:2]] = {}
included_commands = []
for command in glsl.version_commands[version]:
if not command in included_commands:
included_commands.append(command)
if command != glsl.version_commands[version][command]:
glsl_search_function_aliases[version[:2]][command] = glsl.version_commands[version][command]
for command in glsl.version_commands_flat[version]:
if not command in glsl.version_commands[version] and not command in included_commands:
included_commands.append(command)
included_commands.sort()
for command in included_commands:
glsl_search_versions_commands += "'" + command + "',"
glsl_search_versions_commands += "],"
search_versions_commands += glsl_search_versions_commands
# all for both GLSL and GL
search_versions_commands += "'all': ["
#openGL
for command in opengl.commands_version:
if args.buildtype == 'glsl':
break;
major_versions = opengl.get_major_versions(opengl.commands_version[command])
for version in major_versions:
if int(version[2]) < 2:
continue
search_versions_commands += "'" + version[:3] + "/" + command + "',"
#GLSL
for command in glsl.commands_version:
if args.buildtype == 'gl':
break;
major_versions = glsl.get_major_versions(glsl.commands_version[command])
for version in major_versions:
if int(version[2]) < 3:
continue
search_versions_commands += "'" + version[:3] + "/" + command + "',"
#openGL
for command in opengl.commands_version_flat:
if args.buildtype == 'glsl':
break;
if command in opengl.commands_version:
continue
major_versions = opengl.get_major_versions(opengl.commands_version_flat[command])
for version in major_versions:
if int(version[2]) < 2:
continue
search_versions_commands += "'" + version[:3] + "/" + command + "',"
#GLSL
for command in glsl.commands_version_flat:
if args.buildtype == 'gl':
break;
if command in glsl.commands_version:
continue
major_versions = glsl.get_major_versions(glsl.commands_version_flat[command])
for version in major_versions:
if int(version[2]) < 3:
continue
search_versions_commands += "'" + version[:3] + "/" + command + "',"
#close
search_versions_commands += "]};"
search_versions_commands += "var function_aliases = {"
#openGL Aliases
for version in search_function_aliases:
if args.buildtype == 'glsl':
break;
search_versions_commands += "'" + version + "':{"
for alias in search_function_aliases[version]:
search_versions_commands += alias + ":'" + search_function_aliases[version][alias] + "',"
search_versions_commands += "},"
#GLSL Aliases
for version in glsl_search_function_aliases:
if args.buildtype == 'gl':
break;
glsl_search_versions_commands += "'" + version + "':{"
for alias in glsl_search_function_aliases[version]:
glsl_search_versions_commands += alias + ":'" + glsl_search_function_aliases[version][alias] + "',"
glsl_search_versions_commands += "},"
search_versions_commands += glsl_search_versions_commands+ "};"
search = search.replace("{$search_versions_commands}", search_versions_commands)
search_fp = open(output_dir + "/docs.gl.search.js", "w")
search_fp.write(search)
search_fp.close()
####################################################################################
search_versions_options = ""
#openGL
for version_option in glsl.version_commands.keys():
if args.buildtype == 'gl':
break;
if version_option[0:2] == "sl" and float(version_option[2:]) < 4.0:
continue
if version_option[0:2] == "el" and float(version_option[2:]) < 3.0:
continue
if version_option[:2] == 'sl':
search_versions_options += ""
elif version_option[:2] == 'el':
search_versions_options += ""
#GLSL
for version_option in opengl.version_commands.keys():
if args.buildtype == 'glsl':
break;
if version_option[0:2] == "gl" and float(version_option[2:]) < 2.1:
continue
if version_option[0:2] == "es" and float(version_option[2:]) < 2.0:
continue
if version_option[:2] == 'gl':
search_versions_options += ""
elif version_option[:2] == 'es':
search_versions_options += ""
search_versions_options += ""
header = header.replace("{$search_versions}", search_versions_options)
unhandled_commands = opengl.commands_version_flat.keys()
#forget about the unhandled in glsl for now
glsl_unhandled_commands = glsl.commands_version_flat.keys()
#glsl_unhandled_commands += glsl_unhandled_commands
def spew_category(name, commands, current_command, api):
commands.sort()
api_commands = ""
commands_list = ""
category_versions = []
found_current_command = False
for command in commands:
versions_available ={}
if api == "gl":
versions_available = opengl.commands_version_flat[command]
versions_available.sort()
if api == "sl":
versions_available = glsl.commands_version_flat[command]
versions_available.sort()
if command == current_command:
found_current_command = True
classes = "command"
if command == current_command:
classes += " current"
for v in versions_available:
classes += " " + v.replace(".", "")
if not v in category_versions:
category_versions.append(v)
latest_present = versions_available[-1][0:3]
commands_list += "
" examples += code examples += "" examples += "
"
tutorials_done = []
tutorial_list={}
if API_type =="gl":
tutorial_list = opengl.tutorial_functions[command]
tutorial_list = sorted(tutorial_list, key=lambda tutorial: opengl.tutorials[tutorial['tutorial']]['name'])
if API_type =="sl":
tutorial_list = glsl.tutorial_functions[command]
tutorial_list = sorted(tutorial_list, key=lambda tutorial: glsl.tutorials[tutorial['tutorial']]['name'])
for tutorial in tutorial_list:
if not version[:3] in tutorial['versions']:
continue
if tutorial['tutorial'] in examples_done:
continue
examples_done.append(tutorial['tutorial'])
if API_type =="gl":
tutorials += '' + opengl.tutorials[tutorial['tutorial']]['name'] + "
"
if API_type =="sl":
tutorials += '' + glsl.tutorials[tutorial['tutorial']]['name'] + "
"
tutorials += "