Html templating

This commit is contained in:
2023-02-08 15:31:54 +00:00
parent 3f2dfb323e
commit 0287752589
10 changed files with 1613 additions and 26 deletions

View File

@ -4,6 +4,35 @@ import os
import re
import shutil
from datetime import date
from pytablewriter import AsciiDocTableWriter
def asciidoc_dump(list, name, steps):
matrix = []
if len(list) > 1:
list_range = len(list) - steps + 1
for index in range(0, list_range, steps):
matrix_row = [list[index].split()[0]]
if steps == 2:
matrix_row += [
list[index + 1].split()[1] + "->" + list[index].split()[1]
]
else:
matrix_row += [list[index].split()[1]]
matrix_row += [
list[index].split()[2],
" ".join(list[index].split()[3:]),
str(date.today()),
]
matrix.append(matrix_row)
writer = AsciiDocTableWriter(
table_name=name.capitalize() + " modules",
headers=["Name/Version", "Release Stage", "Group", "Deps", "Change Date"],
value_matrix=matrix,
)
writer.dump(os.path.join("doc", name + "_modules.adoc"))
def db_check_diff(current_pmodule_state, Pmodules_db_path, Pmodules_states):
current_sha = hashlib.sha256(current_pmodule_state.encode()).hexdigest()
@ -32,8 +61,6 @@ def db_check_diff(current_pmodule_state, Pmodules_db_path, Pmodules_states):
print_pmodules_differences(
current_pmodule_state, old_pmodule_state, Pmodules_states
)
else:
print_to_markdown([], [], [])
# There is no database available or there are differences with the old pmodule state, writing current state.
if no_current_db or compare_states_sha(
@ -51,23 +78,10 @@ def compare_states_sha(current_pmodule_state, old_pmodule_state, current_sha):
return False
def print_to_markdown(new_module_list, deleted_module_list, changed_module_list):
with open("pmodules_changes.md", "w") as md_file:
standard_print(md_file, new_module_list, "New modules:")
md_file.write("\n# Changed modules: \n")
if len(changed_module_list) > 1:
for index in range(0, len(changed_module_list) - 1, 2):
md_file.write(
changed_module_list[index]
+ "<br/>Changed state from "
+ changed_module_list[index + 1].split()[1]
+ " to ---> "
+ changed_module_list[index].split()[1]
+ "<br/>"
)
standard_print(md_file, deleted_module_list, "Deleted modules:")
def print_to_asciidoc(new_module_list, deleted_module_list, changed_module_list):
asciidoc_dump(new_module_list, "new", 1)
asciidoc_dump(deleted_module_list, "deleted", 1)
asciidoc_dump(changed_module_list, "changed", 2)
def print_pmodules_differences(
@ -111,7 +125,7 @@ def print_pmodules_differences(
changed_module_list,
)
print_to_markdown(new_module_list, deleted_module_list, changed_module_list)
print_to_asciidoc(new_module_list, deleted_module_list, changed_module_list)
def set_changed_module_list(