remove problems detected by the linter

This commit is contained in:
Laurent Rineau 2024-09-04 18:21:03 +02:00
parent e7ab525ead
commit 8e6670d8ea
1 changed files with 151 additions and 114 deletions

View File

@ -1,121 +1,74 @@
import sys import sys
import re import re
import os import os
import collections
input_report_file_name=sys.argv[1] CONFIG_REGEX = re.compile(
report_file_name=sys.argv[2] r"(.*Configuring (examples|demo|test)*( in )*(test/|examples/|demo/)*)((?!done)\w+)"
global_report_file_name=sys.argv[3] )
config_regex=re.compile(r'(.*Configuring (examples|demo|test)*( in )*(test/|examples/|demo/)*)((?!done)\w+)') DEMO_REGEX = re.compile(r".*in demo/")
demo_regex=re.compile(r'.*in demo/') EXAMPLES_REGEX = re.compile(r'.*in examples/')
examples_regex=re.compile(r'.*in examples/') SEPARATOR = "------------------------------------------------------------------"
Separator = "------------------------------------------------------------------"
#open the Installation report # open the Installation report
#For each NAME, check if NAME is a directory. If not, create one, create a # For each NAME, check if NAME is a directory. If not, create one, create a
#text report, and write everything that is in the report until the next NAME # text report, and write everything that is in the report until the next NAME
#in it. Then, add 'NAME r' in the global report. This should allow to get all # in it. Then, add 'NAME r' in the global report. This should allow to get all
#the NOTICE and other info explaining why the configuration is skipped. # the NOTICE and other info explaining why the configuration is skipped.
name="" def find_third_separator(contents):
is_writing=False
is_ignored=False
position = 0
lines_to_write = []
installation_cmake_logs = []
def find_third_separator(inner_contents):
separator_count = 0 separator_count = 0
for j, inner_line in enumerate(inner_contents): for j, line in enumerate(contents):
if inner_line.strip() == Separator: if line.strip() == SEPARATOR:
separator_count += 1 separator_count += 1
if separator_count == 3: if separator_count == 3:
return j return j
return len(inner_contents) + 2 return len(contents) + 2
def find_last_separator(inner_contents): def last(iterator):
for j, inner_line in enumerate(inner_contents): return collections.deque(iterator, maxlen=1).pop()
if inner_line.strip() == Separator:
inner_position = j
return inner_position
with open ("{dir}/{file}".format(dir="Installation",file=report_file_name), "r", encoding="utf-8") as file: def find_last_separator(contents):
contents = file.readlines() position, _ = last(filter(lambda x: x[1].strip() == SEPARATOR, enumerate(contents)))
position = find_last_separator(contents) return position
for i, line in enumerate(contents):
if i > position:
installation_cmake_logs.append(line)
if line.strip() == "== Generating build files for tests ==":
break
contents = []
global_report = open(global_report_file_name, "a+", encoding="utf-8") def process_report(input_report_file_name, report_file_name, global_report_file_name):
with open(input_report_file_name, "rt", encoding="utf-8") as input_report_file: name = ""
for myline in input_report_file: is_writing = False
match = config_regex.match(myline) is_ignored = False
if is_writing: position = 0
if match: lines_to_write = []
is_writing = False installation_cmake_logs = []
if is_ignored:
print("{label} {result}".format(label=name, result='r'), file=global_report)
is_ignored = False
if lines_to_write:
file_path = f"{name}/{report_file_name}"
if os.path.exists(file_path):
with open(file_path, "r", encoding="utf-8") as file:
contents = file.readlines()
else:
contents = []
position = find_third_separator(contents) file_path = f"Installation/{report_file_name}"
print(f"Debug: Opening file {file_path}")
if not any(re.search("- CMake Results .*", content) for content in contents): with open(file_path, "r", encoding="utf-8") as file:
lines_to_write.insert(0, f"{Separator}\n- CMake Results for {name}\n{Separator}\n\n") contents = file.readlines()
lines_to_write.insert(0, "\n") position = find_last_separator(contents)
contents[position:position] = lines_to_write print(f"Debug: Position is {position}")
print(f"Debug: Length of contents is {len(contents)}")
with open(file_path, "w", encoding="utf-8") as file: for i, line in enumerate(contents):
file.write("".join(contents)) if i > position:
if line.strip() == "== Generating build files for tests ==":
lines_to_write = [] print(f"Debug: Found the line {line} at position {i}")
if is_ignored: break
is_ignored = False installation_cmake_logs.append(line)
else: contents = []
if myline.strip() != "": print(f"Debug: Length of installation CMake logs is {len(installation_cmake_logs)}")
lines_to_write.append(myline) print(f"Debug: Installation CMake logs are {"".join(installation_cmake_logs)}")
if not is_writing: global_report = open(global_report_file_name, "a+", encoding="utf-8")
if match: with open(input_report_file_name, "rt", encoding="utf-8") as input_report_file:
name=match.group(0).replace(match.group(1), "") for line in input_report_file:
if demo_regex.match(myline): match = CONFIG_REGEX.match(line)
name="{str}_Demo".format(str=name) if is_writing:
elif examples_regex.match(myline): if match:
name="{str}_Examples".format(str=name) is_writing = False
elif name == "libCGAL": if is_ignored:
name="libCGAL_shared" print(f"{name} r", file=global_report)
elif name == "libCGAL_Core":
name="libCGALCore_shared"
elif name == "libCGAL_ImageIO":
name="libCGALimageIO_shared"
elif name == "libCGAL_Qt6":
name="libCGALQt6_shared"
if name=="incomplete":
is_writing=False
is_ignored=False
continue
else:
if not os.path.isdir(name):
is_ignored = True
os.mkdir(name)
with open("{}/../../../../../.scm-branch".format(os.getcwd()), 'r', encoding="utf-8") as scm_branch_file:
scm_branch_content = scm_branch_file.read()
with open("{dir}/{file}".format(dir=name, file=report_file_name), "w+", encoding="utf-8") as report_file_handle:
report_file_handle.write(scm_branch_content)
else:
is_ignored = False is_ignored = False
file_path = "{dir}/{file}".format(dir=name, file=report_file_name) if lines_to_write:
file_path = f"{name}/{report_file_name}"
if os.path.exists(file_path): if os.path.exists(file_path):
with open(file_path, "r", encoding="utf-8") as file: with open(file_path, "r", encoding="utf-8") as file:
contents = file.readlines() contents = file.readlines()
@ -124,20 +77,104 @@ with open(input_report_file_name, "rt", encoding="utf-8") as input_report_file:
position = find_third_separator(contents) position = find_third_separator(contents)
if not any(re.search("- CMake Logs .*", content) for content in contents): if not any(
contents.insert(position - 1, Separator + "\n- CMake Logs from Installation \n" + Separator + "\n\n") re.search("- CMake Results .*", content)
for log in installation_cmake_logs: for content in contents
contents.insert(position, log) ):
position += 1 lines_to_write.insert(
0,
f"{SEPARATOR}\n- CMake Results for {name}\n{SEPARATOR}\n\n",
)
lines_to_write.insert(0, "\n")
contents[position:position] = lines_to_write
with open(file_path, "w", encoding="utf-8") as file: with open(file_path, "w", encoding="utf-8") as file:
file.write("".join(contents)) file.write("".join(contents))
is_writing = True lines_to_write = []
if is_ignored:
is_ignored = False
else:
if line.strip() != "":
lines_to_write.append(line)
if not is_writing:
if match:
name = match.group(0).replace(match.group(1), "")
print(f"Debug: Found name {name}")
if DEMO_REGEX.match(line):
name = f"{name}_Demo"
elif EXAMPLES_REGEX.match(line):
name = f"{name}_Examples"
elif name == "libCGAL":
name = "libCGAL_shared"
elif name == "libCGAL_Core":
name = "libCGALCore_shared"
elif name == "libCGAL_ImageIO":
name = "libCGALimageIO_shared"
elif name == "libCGAL_Qt6":
name = "libCGALQt6_shared"
if name == "incomplete":
is_writing = False
is_ignored = False
continue
else:
if not os.path.isdir(name):
is_ignored = True
os.mkdir(name)
with open(
f"{os.getcwd()}/../../../../../.scm-branch",
"r",
encoding="utf-8",
) as scm_branch_file:
scm_branch_content = scm_branch_file.read()
if is_writing: with open(
is_writing=False f"{name}/{report_file_name}", "w+", encoding="utf-8"
if is_ignored: ) as report_file_handle:
print("{label} {result}".format(label=name, result='r'), file=global_report) report_file_handle.write(scm_branch_content)
is_ignored=False else:
global_report.close() is_ignored = False
file_path = f"{name}/{report_file_name}"
if os.path.exists(file_path):
with open(file_path, "r", encoding="utf-8") as file:
contents = file.readlines()
else:
contents = []
position = find_third_separator(contents)
if not any(
re.search("- CMake Logs .*", content)
for content in contents
):
contents.insert(
position - 1,
SEPARATOR
+ "\n- CMake Logs from Installation \n"
+ SEPARATOR
+ "\n\n",
)
for log in installation_cmake_logs:
contents.insert(position, log)
position += 1
with open(file_path, "w", encoding="utf-8") as file:
file.write("".join(contents))
is_writing = True
if is_writing:
is_writing = False
if is_ignored:
print(f"{name} r", file=global_report)
is_ignored = False
global_report.close()
def main():
input_report_file_name = sys.argv[1]
report_file_name = sys.argv[2]
global_report_file_name = sys.argv[3]
process_report(input_report_file_name, report_file_name, global_report_file_name)
if __name__ == "__main__":
main()