tools/gen-cpydiff.py: Use os.path.join and os.path.isdir.
Makes path handling clearer and simpler. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This commit is contained in:
parent
c1ae7d7534
commit
02ad71468f
|
@ -27,7 +27,6 @@
|
||||||
manually using the command make gen-cpydiff. """
|
manually using the command make gen-cpydiff. """
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import errno
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import time
|
import time
|
||||||
import re
|
import re
|
||||||
|
@ -44,8 +43,8 @@ else:
|
||||||
CPYTHON3 = os.getenv("MICROPY_CPYTHON3", "python3")
|
CPYTHON3 = os.getenv("MICROPY_CPYTHON3", "python3")
|
||||||
MICROPYTHON = os.getenv("MICROPY_MICROPYTHON", "../ports/unix/build-standard/micropython")
|
MICROPYTHON = os.getenv("MICROPY_MICROPYTHON", "../ports/unix/build-standard/micropython")
|
||||||
|
|
||||||
TESTPATH = "../tests/cpydiff/"
|
TESTPATH = "../tests/cpydiff"
|
||||||
DOCPATH = "../docs/genrst/"
|
DOCPATH = "../docs/genrst"
|
||||||
INDEXTEMPLATE = "../docs/differences/index_template.txt"
|
INDEXTEMPLATE = "../docs/differences/index_template.txt"
|
||||||
INDEX = "index.rst"
|
INDEX = "index.rst"
|
||||||
|
|
||||||
|
@ -79,7 +78,8 @@ def readfiles():
|
||||||
files = []
|
files = []
|
||||||
|
|
||||||
for test in tests:
|
for test in tests:
|
||||||
text = open(TESTPATH + test, "r").read()
|
test_fullpath = os.path.join(TESTPATH, test)
|
||||||
|
text = open(test_fullpath, "r").read()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
class_, desc, cause, workaround, code = [
|
class_, desc, cause, workaround, code = [
|
||||||
|
@ -98,7 +98,7 @@ def readfiles():
|
||||||
output = Output(test, class_, desc, cause, workaround, code, "", "", "")
|
output = Output(test, class_, desc, cause, workaround, code, "", "", "")
|
||||||
files.append(output)
|
files.append(output)
|
||||||
except IndexError:
|
except IndexError:
|
||||||
print("Incorrect format in file " + TESTPATH + test)
|
print("Incorrect format in file " + test_fullpath)
|
||||||
|
|
||||||
return files
|
return files
|
||||||
|
|
||||||
|
@ -107,7 +107,8 @@ def run_tests(tests):
|
||||||
"""executes all tests"""
|
"""executes all tests"""
|
||||||
results = []
|
results = []
|
||||||
for test in tests:
|
for test in tests:
|
||||||
with open(TESTPATH + test.name, "rb") as f:
|
test_fullpath = os.path.join(TESTPATH, test.name)
|
||||||
|
with open(test_fullpath, "rb") as f:
|
||||||
input_py = f.read()
|
input_py = f.read()
|
||||||
|
|
||||||
process = subprocess.Popen(
|
process = subprocess.Popen(
|
||||||
|
@ -130,7 +131,7 @@ def run_tests(tests):
|
||||||
|
|
||||||
if output_cpy[0] == output_upy[0] and output_cpy[1] == output_upy[1]:
|
if output_cpy[0] == output_upy[0] and output_cpy[1] == output_upy[1]:
|
||||||
status = "Supported"
|
status = "Supported"
|
||||||
print("Supported operation!\nFile: " + TESTPATH + test.name)
|
print("Supported operation!\nFile: " + test_fullpath)
|
||||||
else:
|
else:
|
||||||
status = "Unsupported"
|
status = "Unsupported"
|
||||||
|
|
||||||
|
@ -197,11 +198,8 @@ def gen_rst(results):
|
||||||
"""creates restructured text documents to display tests"""
|
"""creates restructured text documents to display tests"""
|
||||||
|
|
||||||
# make sure the destination directory exists
|
# make sure the destination directory exists
|
||||||
try:
|
if not os.path.isdir(DOCPATH):
|
||||||
os.mkdir(DOCPATH)
|
os.mkdir(DOCPATH)
|
||||||
except OSError as e:
|
|
||||||
if e.args[0] != errno.EEXIST and e.args[0] != errno.EISDIR:
|
|
||||||
raise
|
|
||||||
|
|
||||||
toctree = []
|
toctree = []
|
||||||
class_ = []
|
class_ = []
|
||||||
|
@ -214,7 +212,7 @@ def gen_rst(results):
|
||||||
if i >= len(class_) or section[i] != class_[i]:
|
if i >= len(class_) or section[i] != class_[i]:
|
||||||
if i == 0:
|
if i == 0:
|
||||||
filename = section[i].replace(" ", "_").lower()
|
filename = section[i].replace(" ", "_").lower()
|
||||||
rst = open(DOCPATH + filename + ".rst", "w")
|
rst = open(os.path.join(DOCPATH, filename + ".rst"), "w")
|
||||||
rst.write(HEADER)
|
rst.write(HEADER)
|
||||||
rst.write(section[i] + "\n")
|
rst.write(section[i] + "\n")
|
||||||
rst.write(RSTCHARS[0] * len(section[i]))
|
rst.write(RSTCHARS[0] * len(section[i]))
|
||||||
|
@ -225,7 +223,7 @@ def gen_rst(results):
|
||||||
rst.write(RSTCHARS[min(i, len(RSTCHARS) - 1)] * len(section[i]))
|
rst.write(RSTCHARS[min(i, len(RSTCHARS) - 1)] * len(section[i]))
|
||||||
rst.write("\n\n")
|
rst.write("\n\n")
|
||||||
class_ = section
|
class_ = section
|
||||||
rst.write(".. _cpydiff_%s:\n\n" % output.name.rsplit(".", 1)[0])
|
rst.write(".. _cpydiff_%s:\n\n" % os.path.splitext(output.name)[0])
|
||||||
rst.write(output.desc + "\n")
|
rst.write(output.desc + "\n")
|
||||||
rst.write("~" * len(output.desc) + "\n\n")
|
rst.write("~" * len(output.desc) + "\n\n")
|
||||||
if output.cause != "Unknown":
|
if output.cause != "Unknown":
|
||||||
|
@ -242,7 +240,7 @@ def gen_rst(results):
|
||||||
rst.write(table)
|
rst.write(table)
|
||||||
|
|
||||||
template = open(INDEXTEMPLATE, "r")
|
template = open(INDEXTEMPLATE, "r")
|
||||||
index = open(DOCPATH + INDEX, "w")
|
index = open(os.path.join(DOCPATH, INDEX), "w")
|
||||||
index.write(HEADER)
|
index.write(HEADER)
|
||||||
index.write(template.read())
|
index.write(template.read())
|
||||||
for section in INDEXPRIORITY:
|
for section in INDEXPRIORITY:
|
||||||
|
|
Loading…
Reference in New Issue