Skip to content

Commit

Permalink
Even more Python3 porting
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitmel committed Nov 18, 2021
1 parent 081cff5 commit 09467eb
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 124 deletions.
24 changes: 12 additions & 12 deletions compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ def create_directory(dir):
if not os.path.exists(path):
dirname = os.path.dirname(path)
create_directory(dirname)
url = url + filename + suffix
with open(path, 'w') as f:
url = url + filename + (suffix or '')
with open(path, 'wb') as f:
print("Downloading " + url)
f.write(urllib.request.urlopen(url).read())

Expand Down Expand Up @@ -436,9 +436,9 @@ def replace_js(markup, prefix):
if version == 'sl3':
continue

search_versions_commands += "'" + version[:3] + "/" + command + "',"
#OpenGL Loop
search_versions_commands += "'" + version[:3] + "/" + command + "',"
#OpenGL Loop
for command in opengl.commands_version_flat:

if command in opengl.commands_version:
Expand Down Expand Up @@ -559,7 +559,7 @@ def spew_category(name, commands, current_command, api):
if api == "sl":
versions_available = glsl.commands_version_flat[command]
versions_available.sort()
if command == current_command:
found_current_command = True

Expand Down Expand Up @@ -626,7 +626,7 @@ def spew_category(name, commands, current_command, api):
#No GLSL 3 docs
if version == 'sl3':
continue
written = 0

print("Compiling " + version + " ..." )
Expand Down Expand Up @@ -829,7 +829,7 @@ def spew_category(name, commands, current_command, api):
fp.close()

if args.buildmode == 'full':
command_html = command_html.decode('utf8')
command_html = command_html

command_html = command_html.replace("{$pipelinestall}", "")

Expand Down Expand Up @@ -945,7 +945,7 @@ def replace_alias(matchobj):
output = open(output_dir + version_dir + "/" + command, "w")
output_string = output_html
if args.buildmode == 'full':
output_string = htmlmin.minify(output_html, remove_comments=True, reduce_boolean_attributes=True, remove_optional_attribute_quotes=False).encode('ascii', 'xmlcharrefreplace')
output_string = htmlmin.minify(output_html, remove_comments=True, reduce_boolean_attributes=True, remove_optional_attribute_quotes=False).encode('ascii', 'xmlcharrefreplace').decode('ascii')
output.write(output_string)
output.close()

Expand All @@ -970,7 +970,7 @@ def replace_alias(matchobj):
# if API_type =="sl":
if len(glsl_unhandled_commands):
glsl_api_commands += spew_category("Uncategorized", glsl_unhandled_commands, "","sl")
header_for_page = header_for_page.replace("{$api_commands}", api_commands)
header_for_page = header_for_page.replace("{$glsl_api_commands}", glsl_api_commands)

Expand All @@ -984,14 +984,14 @@ def replace_alias(matchobj):
fp.close()

if args.buildmode == 'full':
notfound_html = notfound_html.decode('utf8')
notfound_html = notfound_html

output_html = header_for_page + notfound_html + footer_for_page

output = open(output_dir + version + "/404", "w")
output_string = output_html
if args.buildmode == 'full':
output_string = htmlmin.minify(output_html, remove_comments=True, reduce_boolean_attributes=True, remove_optional_attribute_quotes=False).encode('ascii', 'xmlcharrefreplace')
output_string = htmlmin.minify(output_html, remove_comments=True, reduce_boolean_attributes=True, remove_optional_attribute_quotes=False).encode('ascii', 'xmlcharrefreplace').decode('ascii')
output.write(output_string)
output.close()

Expand Down
6 changes: 3 additions & 3 deletions find_glsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

def make_glsl_docs():

print "Creating GLSL docs ..."
print("Creating GLSL docs ...")
sl_filenames = glob.glob(path+"\\gl4\\"+'*.xhtml')
if not os.path.exists("sl4"):
os.makedirs("sl4")
Expand All @@ -16,7 +16,7 @@ def make_glsl_docs():
if not os.path.exists("el3"):
os.makedirs("el3")
get_glsl_docs(es_filenames , "el3" )
print "done"
print("done")


def get_glsl_docs( filenames, foldername ):
Expand All @@ -27,7 +27,7 @@ def get_glsl_docs( filenames, foldername ):
elif foldername[0:2] == "sl":
findtext = "OpenGL Shading Language Version"

print foldername[0:2]
print(foldername[0:2])
for filename in filenames:
with open(filename, 'r') as readfile:
if(readfile.read().find(findtext) != -1):
Expand Down
192 changes: 96 additions & 96 deletions read_glsl_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,33 @@
#Get versions for GLSL
def get_versions( path_file ):

xtree = ET.parse(path_file)
element = xtree.find('.//div[@id="versions"]')
table = element[1][0][2]
test = u'\u2714'; #this is the check symbol
versions = []
for x in range(1, 13):
text = table[0][x].text
if text == test:
versions.append(version_check[x])
return versions

#Get version for GLSL ES
xtree = ET.parse(path_file)
element = xtree.find('.//div[@id="versions"]')
table = element[1][0][2]
test = '\u2714'; #this is the check symbol
versions = []
for x in range(1, 13):
text = table[0][x].text
if text == test:
versions.append(version_check[x])
return versions

#Get version for GLSL ES
def get_el_versions( path_file ):
xtree = ET.parse(path_file)
element = xtree.find('.//div[@id="versions"]')
table = element[1][0][2]
test = u'\u2714'; #this is the check symbol
versions = []
for x in range(1, 4):
text = table[0][x].text
if text == test:
versions.append(version_check_el[x])
#print "got it in version " + version_check[x]
return versions
xtree = ET.parse(path_file)
element = xtree.find('.//div[@id="versions"]')
table = element[1][0][2]
test = '\u2714'; #this is the check symbol
versions = []
for x in range(1, 4):
text = table[0][x].text
if text == test:
versions.append(version_check_el[x])
#print "got it in version " + version_check[x]
return versions
def test_extensions(gldir, command):
# See if removing an extension gives us a real entry
for extension in sl_extensions:
Expand All @@ -68,39 +68,39 @@ def test_replacements(gldir, command):
#dfdx
command_test = command.replace("", "x")
if not shared_glsl.find_command_file(gldir, command_test) == False:
return command_test
return command_test

#GLSL tests

#dfdx
command_test = command.replace("y", "x")
if not shared_glsl.find_command_file(gldir, command_test) == False:
return command_test
return command_test
#dfdy
for ext in sl_extensions:
command_test = command.replace("y", "x")
command_test = command_test.replace(ext, "")
if not shared_glsl.find_command_file(gldir, command_test) == False:
return command_test
command_test = command.replace("y", "x")
command_test = command_test.replace(ext, "")
if not shared_glsl.find_command_file(gldir, command_test) == False:
return command_test

command_test = command.replace("U", "")
if not shared_glsl.find_command_file(gldir, command_test) == False:
return command_test
command_test = command.replace("u", "")
if not shared_glsl.find_command_file(gldir, command_test) == False:
return command_test
return command_test

command_test = command.replace("imul", "umul")
if not shared_glsl.find_command_file(gldir, command_test) == False:
return command_test

for ext in sl_extensions:
command_test = command.replace("S", "U")
command_test = command_test.replace(ext, "")
if not shared_glsl.find_command_file(gldir, command_test) == False:
return command_test
command_test = command.replace("S", "U")
command_test = command_test.replace(ext, "")
if not shared_glsl.find_command_file(gldir, command_test) == False:
return command_test

#I don't think we need anything under this part for GLSL

Expand Down Expand Up @@ -205,71 +205,71 @@ def test_replacements(gldir, command):

#load version keys
for x in version_check:
stored_version_commands[x] = [ {'':''} ,];
stored_version_commands[x] = [ {'':''} ,];
for x in version_check_el:
stored_version_commands[x] = [ {'':''} ,];
stored_version_commands[x] = [ {'':''} ,];
for command in commads:
if command.tag != 'command':
continue
current_command_list.append(command[0][0].text);
if command.tag != 'command':
continue
current_command_list.append(command[0][0].text);
support_API = {'el3' , 'sl4' }
# go over all supported API
for api in support_API:
for command_name in current_command_list:
path_file = path+"\\"+api+"\\"+command_name+".xhtml"
if(os.path.isfile(path_file)):
versions = []
if api[0:2] == 'sl':
versions = get_versions(path_file)
if api[0:2] == 'el':
versions = get_el_versions(path_file)
for x in xrange(len(versions)):
print command_name
stored_version_commands[versions[x]].append({command_name : command_name})
else:
if os.path.exists(api):
test_extensions(api , command_name )
command_file = shared_glsl.find_command_file(api, command_name)
if command_file == False:
command_docs = test_replacements(api, command_name)
command_file = shared_glsl.find_command_file(api, command_docs)
if command_file == False:
print "No command docs file found for " + command_name + " (" + api + ")"
print command_name + " does not exist"
#Todo: Skip ES errors for now
if api[0:2] != 'el':
assert(False)
else:
versions = []
if api[0:2] == 'sl':
versions = get_versions(path+"\\"+api+"\\"+command_docs+".xhtml")
if api[0:2] == 'el':
versions = get_el_versions(path+"\\"+api+"\\"+command_docs+".xhtml")
for x in xrange(len(versions)):
stored_version_commands[versions[x]].append({command_name : command_docs})
for command_name in current_command_list:
path_file = path+"/"+api+"/"+command_name+".xhtml"
if(os.path.isfile(path_file)):
versions = []
if api[0:2] == 'sl':
versions = get_versions(path_file)
if api[0:2] == 'el':
versions = get_el_versions(path_file)
for x in range(len(versions)):
print(command_name)
stored_version_commands[versions[x]].append({command_name : command_name})
else:
if os.path.exists(api):
test_extensions(api , command_name )
command_file = shared_glsl.find_command_file(api, command_name)
if command_file == False:
command_docs = test_replacements(api, command_name)
command_file = shared_glsl.find_command_file(api, command_docs)
if command_file == False:
print("No command docs file found for " + command_name + " (" + api + ")")
print(command_name + " does not exist")
#Todo: Skip ES errors for now
if api[0:2] != 'el':
assert(False)
else:
versions = []
if api[0:2] == 'sl':
versions = get_versions(path+"/"+api+"/"+command_docs+".xhtml")
if api[0:2] == 'el':
versions = get_el_versions(path+"/"+api+"/"+command_docs+".xhtml")
for x in range(len(versions)):
stored_version_commands[versions[x]].append({command_name : command_docs})

output = open("glsl_spec.py", "w")
output.write("version_commands = {\n")
for version in stored_version_commands:
if version == "":
continue

#print version
output.write(" '" + version[0:5] + "': {\n")
for x in stored_version_commands[version]:
mstring = str(x)
mstring = mstring.replace("{" , "")
mstring = mstring.replace("}" , "")
if mstring == "'': ''":
continue
output.write(" " +mstring+ ",\n")
output.write(" },\n")
if version == "":
continue

#print version
output.write(" '" + version[0:5] + "': {\n")
for x in stored_version_commands[version]:
mstring = str(x)
mstring = mstring.replace("{" , "")
mstring = mstring.replace("}" , "")
if mstring == "'': ''":
continue
output.write(" " +mstring+ ",\n")
output.write(" },\n")
output.write("}\n")
output.close()
2 changes: 1 addition & 1 deletion read_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def test_replacements(gldir, command):

command_file = shared.find_command_file(gldir, command_docs)
if command_file == False:
print "No command docs file found for " + command + " (" + gl_prefix + gl_major_version + ")"
print("No command docs file found for " + command + " (" + gl_prefix + gl_major_version + ")")
output.close()
assert(false)

Expand Down
10 changes: 5 additions & 5 deletions server.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#!/usr/bin/python

import SimpleHTTPServer
import SocketServer
import http.server
import socketserver

PORT = 8000

Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
Handler = http.server.SimpleHTTPRequestHandler
Handler.extensions_map.update({
'': 'text/html',
});

httpd = SocketServer.TCPServer(("", PORT), Handler)
httpd = socketserver.TCPServer(("", PORT), Handler)

print "Serving at port", PORT
print("Serving at port", PORT)
httpd.serve_forever()

2 changes: 1 addition & 1 deletion shared_glsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ def find_command_file(gl_version, command):

gl_version = gl_version[:2] + str(int(gl_version[2]) - 1)
command_file = gl_version + "/" + command + ".xhtml"
return command_file

Loading

0 comments on commit 09467eb

Please sign in to comment.