From 09467eb0f878ed02766f932106647f61374ab9eb Mon Sep 17 00:00:00 2001 From: Dmytro Meleshko Date: Thu, 18 Nov 2021 18:29:20 +0200 Subject: [PATCH] Even more Python3 porting --- compile.py | 24 +++--- find_glsl.py | 6 +- read_glsl_spec.py | 192 +++++++++++++++++++++++----------------------- read_spec.py | 2 +- server.py | 10 +-- shared_glsl.py | 2 +- strip.py | 12 +-- 7 files changed, 124 insertions(+), 124 deletions(-) diff --git a/compile.py b/compile.py index f3da1f7e..ac6749e6 100644 --- a/compile.py +++ b/compile.py @@ -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()) @@ -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: @@ -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 @@ -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 + " ..." ) @@ -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}", "") @@ -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() @@ -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) @@ -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() diff --git a/find_glsl.py b/find_glsl.py index 56eacfb9..f7787984 100644 --- a/find_glsl.py +++ b/find_glsl.py @@ -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") @@ -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 ): @@ -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): diff --git a/read_glsl_spec.py b/read_glsl_spec.py index 36d4f0d3..8c7db684 100644 --- a/read_glsl_spec.py +++ b/read_glsl_spec.py @@ -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: @@ -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 @@ -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() \ No newline at end of file diff --git a/read_spec.py b/read_spec.py index bf9c220e..613fa752 100644 --- a/read_spec.py +++ b/read_spec.py @@ -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) diff --git a/server.py b/server.py index b8c9f1f1..5ab8c5c5 100755 --- a/server.py +++ b/server.py @@ -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() diff --git a/shared_glsl.py b/shared_glsl.py index c24d3bf3..fd80a8de 100644 --- a/shared_glsl.py +++ b/shared_glsl.py @@ -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 diff --git a/strip.py b/strip.py index 821bd67f..a0cc580e 100644 --- a/strip.py +++ b/strip.py @@ -11,7 +11,7 @@ def strip_gl2(): f.extend(filenames) for filename in f: - print "Processing " + filename + print("Processing " + filename) fp = open ("gl2/" + filename) content = fp.readlines() @@ -41,7 +41,7 @@ def strip_gl3(): f.extend(filenames) for filename in f: - print "Processing " + filename + print("Processing " + filename) fp = open ("gl3/" + filename) content = fp.readlines() @@ -71,7 +71,7 @@ def strip_gl4(): f.extend(filenames) for filename in f: - print "Processing " + filename + print("Processing " + filename) fp = open ("gl4/" + filename) content = fp.readlines() @@ -103,7 +103,7 @@ def strip_es1(): f.extend(filenames) for filename in f: - print "Processing " + filename + print("Processing " + filename) fp = open ("es1/" + filename) content = fp.readlines() @@ -136,7 +136,7 @@ def strip_es2(): f.extend(filenames) for filename in f: - print "Processing " + filename + print("Processing " + filename) fp = open ("es2/" + filename) content = fp.readlines() @@ -169,7 +169,7 @@ def strip_es3(): f.extend(filenames) for filename in f: - print "Processing " + filename + print("Processing " + filename) fp = open ("es3/" + filename) content = fp.readlines()