docs: Make the Python scripts Python 2&3 compatible

This commit is contained in:
Roland Dobai
2018-09-07 13:46:50 +02:00
parent 27d1b04500
commit f5a642840a
6 changed files with 48 additions and 29 deletions

View File

@@ -14,6 +14,8 @@
# All configuration values have a default; values that are commented out # All configuration values have a default; values that are commented out
# serve to show the default. # serve to show the default.
from __future__ import print_function
from __future__ import unicode_literals
import sys, os import sys, os
import re import re
import subprocess import subprocess

View File

@@ -8,6 +8,10 @@
# CONDITIONS OF ANY KIND, either express or implied. # CONDITIONS OF ANY KIND, either express or implied.
# #
from __future__ import print_function
from __future__ import unicode_literals
from builtins import range
from io import open
import sys import sys
import os import os
import re import re
@@ -50,12 +54,12 @@ def get_doxyfile_input():
""" """
if not os.path.isfile(doxyfile_path): if not os.path.isfile(doxyfile_path):
print "Doxyfile '%s' does not exist!" % doxyfile_path print("Doxyfile '%s' does not exist!" % doxyfile_path)
sys.exit() sys.exit()
print "Getting Doxyfile's INPUT" print("Getting Doxyfile's INPUT")
input_file = open(doxyfile_path, "r") input_file = open(doxyfile_path, "r", encoding='utf-8')
line = input_file.readline() line = input_file.readline()
# read contents of Doxyfile until 'INPUT' statement # read contents of Doxyfile until 'INPUT' statement
@@ -258,14 +262,14 @@ def generate_api_inc_files():
""" """
if not os.path.isdir(xml_directory_path): if not os.path.isdir(xml_directory_path):
print "Directory %s does not exist!" % xml_directory_path print("Directory %s does not exist!" % xml_directory_path)
sys.exit() sys.exit()
if not os.path.exists(inc_directory_path): if not os.path.exists(inc_directory_path):
os.makedirs(inc_directory_path) os.makedirs(inc_directory_path)
list_to_generate = get_doxyfile_input() list_to_generate = get_doxyfile_input()
print "Generating 'api_name.inc' files with Doxygen directives" print("Generating 'api_name.inc' files with Doxygen directives")
for header_file_path in list_to_generate.splitlines(): for header_file_path in list_to_generate.splitlines():
api_name = get_api_name(header_file_path) api_name = get_api_name(header_file_path)
inc_file_path = inc_directory_path + "/" + api_name + ".inc" inc_file_path = inc_directory_path + "/" + api_name + ".inc"
@@ -273,11 +277,11 @@ def generate_api_inc_files():
previous_rst_output = '' previous_rst_output = ''
if os.path.isfile(inc_file_path): if os.path.isfile(inc_file_path):
with open(inc_file_path, "r") as inc_file_old: with open(inc_file_path, "r", encoding='utf-8') as inc_file_old:
previous_rst_output = inc_file_old.read() previous_rst_output = inc_file_old.read()
if previous_rst_output != rst_output: if previous_rst_output != rst_output:
with open(inc_file_path, "w") as inc_file: with open(inc_file_path, "w", encoding='utf-8') as inc_file:
inc_file.write(rst_output) inc_file.write(rst_output)
@@ -290,23 +294,23 @@ if __name__ == "__main__":
# Process command line arguments, if any # Process command line arguments, if any
if len(sys.argv) > 1: if len(sys.argv) > 1:
if not os.path.isdir(xml_directory_path): if not os.path.isdir(xml_directory_path):
print "Directory %s does not exist!" % xml_directory_path print("Directory %s does not exist!" % xml_directory_path)
sys.exit() sys.exit()
header_file_path = sys.argv[1] header_file_path = sys.argv[1]
api_name = get_api_name(header_file_path) api_name = get_api_name(header_file_path)
if api_name: if api_name:
rst_output = generate_directives(header_file_path) rst_output = generate_directives(header_file_path)
print "Doxygen directives for '%s'" % header_file_path print("Doxygen directives for '%s'" % header_file_path)
print print()
print rst_output print(rst_output)
else: else:
print "Options to execute 'gen-dxd.py' application:" print("Options to execute 'gen-dxd.py' application:")
print "1: $ python gen-dxd.py" print("1: $ python gen-dxd.py")
print " Generate API 'header_file.inc' files for headers defined in '%s'" % doxyfile_path print(" Generate API 'header_file.inc' files for headers defined in '%s'" % doxyfile_path)
print "2: $ python gen-dxd.py header_file_path" print("2: $ python gen-dxd.py header_file_path")
print " Print out Doxygen directives for a single header file" print(" Print out Doxygen directives for a single header file")
print " example: $ python gen-dxd.py mdns/include/mdns.h" print(" example: $ python gen-dxd.py mdns/include/mdns.h")
print " NOTE: Run Doxygen first to get XML files for the header file" print(" NOTE: Run Doxygen first to get XML files for the header file")
sys.exit() sys.exit()

View File

@@ -4,6 +4,9 @@
# Python script to generate ReSTructured Text .inc snippets # Python script to generate ReSTructured Text .inc snippets
# with version-based content for this IDF version # with version-based content for this IDF version
from __future__ import print_function
from __future__ import unicode_literals
from io import open
import subprocess import subprocess
import os import os
import sys import sys
@@ -129,7 +132,7 @@ def write_git_clone_inc(template, out_dir, version, ver_type, is_stable):
"zipfile_note" : zipfile["stable"] if is_stable else zipfile["unstable"] "zipfile_note" : zipfile["stable"] if is_stable else zipfile["unstable"]
} }
out_file = os.path.join(out_dir, "git-clone.inc") out_file = os.path.join(out_dir, "git-clone.inc")
with open(out_file, "w") as f: with open(out_file, "w", encoding='utf-8') as f:
f.write(template["template"] % args) f.write(template["template"] % args)
print("%s written" % out_file) print("%s written" % out_file)
@@ -142,7 +145,7 @@ def write_version_note(template, out_dir, version, ver_type, is_stable):
else: else:
content = template["branch"] % (ver_type, version) content = template["branch"] % (ver_type, version)
out_file = os.path.join(out_dir, "version-note.inc") out_file = os.path.join(out_dir, "version-note.inc")
with open(out_file, "w") as f: with open(out_file, "w", encoding='utf-8') as f:
f.write(content) f.write(content)
print("%s written" % out_file) print("%s written" % out_file)

View File

@@ -65,7 +65,13 @@ Credits: Written by Ulf "Ulfalizer" Magnusson
Send bug reports, suggestions and other feedback to ulfalizer a.t Google's Send bug reports, suggestions and other feedback to ulfalizer a.t Google's
email service. Don't wrestle with internal APIs. Tell me what you need and I email service. Don't wrestle with internal APIs. Tell me what you need and I
might add it in a safe way as a client API instead.""" might add it in a safe way as a client API instead."""
from __future__ import unicode_literals
from builtins import str
from builtins import hex
from builtins import range
from builtins import object
from io import open
import os import os
import re import re
import sys import sys
@@ -518,7 +524,7 @@ class Config(object):
for sym in self.syms_iter(): for sym in self.syms_iter():
sym.already_written = False sym.already_written = False
with open(filename, "w") as f: with open(filename, "w", encoding='utf-8') as f:
# Write header # Write header
if header is not None: if header is not None:
f.write(_comment(header)) f.write(_comment(header))
@@ -3099,7 +3105,7 @@ class _FileFeed(object):
def __init__(self, filename): def __init__(self, filename):
self.filename = _clean_up_path(filename) self.filename = _clean_up_path(filename)
with open(filename, "r") as f: with open(filename, "r", encoding='utf-8') as f:
# No interleaving of I/O and processing yet. Don't know if it would # No interleaving of I/O and processing yet. Don't know if it would
# help. # help.
self.lines = f.readlines() self.lines = f.readlines()
@@ -3392,7 +3398,7 @@ def _internal_error(msg):
T_BOOL, T_TRISTATE, T_HEX, T_INT, T_STRING, T_BOOL, T_TRISTATE, T_HEX, T_INT, T_STRING,
T_DEF_BOOL, T_DEF_TRISTATE, T_DEF_BOOL, T_DEF_TRISTATE,
T_SELECT, T_RANGE, T_OPTION, T_ALLNOCONFIG_Y, T_ENV, T_SELECT, T_RANGE, T_OPTION, T_ALLNOCONFIG_Y, T_ENV,
T_DEFCONFIG_LIST, T_MODULES, T_VISIBLE) = range(39) T_DEFCONFIG_LIST, T_MODULES, T_VISIBLE) = list(range(39))
# The leading underscore before the function assignments below prevent pydoc # The leading underscore before the function assignments below prevent pydoc
# from listing them. The constants could be hidden too, but they're fairly # from listing them. The constants could be hidden too, but they're fairly
@@ -3433,7 +3439,7 @@ _id_keyword_re_match = re.compile(r"\s*([\w./-]+)\s*").match
_sym_ref_re_search = re.compile(r"\$[A-Za-z0-9_]+").search _sym_ref_re_search = re.compile(r"\$[A-Za-z0-9_]+").search
# Integers representing symbol types # Integers representing symbol types
UNKNOWN, BOOL, TRISTATE, STRING, HEX, INT = range(6) UNKNOWN, BOOL, TRISTATE, STRING, HEX, INT = list(range(6))
# Strings to use for types # Strings to use for types
TYPENAME = {UNKNOWN: "unknown", BOOL: "bool", TRISTATE: "tristate", TYPENAME = {UNKNOWN: "unknown", BOOL: "bool", TRISTATE: "tristate",
@@ -3451,7 +3457,7 @@ DEFAULT_VALUE = {BOOL: "n", TRISTATE: "n", STRING: "", INT: "", HEX: ""}
NO_SELECTION = 0 NO_SELECTION = 0
# Integers representing expression types # Integers representing expression types
AND, OR, NOT, EQUAL, UNEQUAL = range(5) AND, OR, NOT, EQUAL, UNEQUAL = list(range(5))
# Map from tristate values to integers # Map from tristate values to integers
TRI_TO_INT = {"n": 0, "m": 1, "y": 2} TRI_TO_INT = {"n": 0, "m": 1, "y": 2}

View File

@@ -1,5 +1,7 @@
# based on http://protips.readthedocs.io/link-roles.html # based on http://protips.readthedocs.io/link-roles.html
from __future__ import print_function
from __future__ import unicode_literals
import re import re
import os import os
from docutils import nodes from docutils import nodes
@@ -8,9 +10,9 @@ from local_util import run_cmd_get_output
def get_github_rev(): def get_github_rev():
path = run_cmd_get_output('git rev-parse --short HEAD') path = run_cmd_get_output('git rev-parse --short HEAD')
tag = run_cmd_get_output('git describe --exact-match') tag = run_cmd_get_output('git describe --exact-match')
print ('Git commit ID: ', path) print('Git commit ID: ', path)
if len(tag): if len(tag):
print ('Git tag: ', tag) print('Git tag: ', tag)
path = tag path = tag
return path return path

View File

@@ -14,6 +14,8 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from __future__ import unicode_literals
from io import open
import re import re
import os import os
import shutil import shutil
@@ -25,10 +27,10 @@ def files_equal(path_1, path_2):
if not os.path.exists(path_1) or not os.path.exists(path_2): if not os.path.exists(path_1) or not os.path.exists(path_2):
return False return False
file_1_contents = '' file_1_contents = ''
with open(path_1, "r") as f_1: with open(path_1, "r", encoding='utf-8') as f_1:
file_1_contents = f_1.read() file_1_contents = f_1.read()
file_2_contents = '' file_2_contents = ''
with open(path_2, "r") as f_2: with open(path_2, "r", encoding='utf-8') as f_2:
file_2_contents = f_2.read() file_2_contents = f_2.read()
return file_1_contents == file_2_contents return file_1_contents == file_2_contents