From 325210b130343655f18b4206eaaeb199d8972e0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Brunner?= Date: Mon, 3 Jun 2024 08:49:44 +0200 Subject: [PATCH] Publishing: Fix then the Securtiy.md file didn't exists --- c2cciutils/audit.py | 10 +++++++--- c2cciutils/scripts/publish.py | 6 ++---- c2cciutils/security.py | 5 ++--- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/c2cciutils/audit.py b/c2cciutils/audit.py index 0edda2261..712d6d125 100644 --- a/c2cciutils/audit.py +++ b/c2cciutils/audit.py @@ -211,12 +211,16 @@ def outdated_versions( with open("SECURITY.md", encoding="utf-8") as security_file: security = c2cciutils.security.Security(security_file.read()) - version_index = security.headers.index("Version") - date_index = security.headers.index("Supported Until") + version_index = security.version_index + date_index = security.support_until_index for row in security.data: str_date = row[date_index] - if str_date not in ("Unsupported", "Best effort", "To be defined"): + if str_date not in ( + c2cciutils.security.HEADER_SUPPORT_UNTIL, + c2cciutils.security.HEADER_BEST_EFFORT, + c2cciutils.security.HEADER_TO_BE_DEFINED, + ): date = datetime.datetime.strptime(row[date_index], "%d/%m/%Y") if date < datetime.datetime.now(): c2cciutils.error( diff --git a/c2cciutils/scripts/publish.py b/c2cciutils/scripts/publish.py index d348c9ad7..790385617 100644 --- a/c2cciutils/scripts/publish.py +++ b/c2cciutils/scripts/publish.py @@ -214,10 +214,8 @@ def main() -> None: sys.exit(1) security = c2cciutils.security.Security(security_text) - version_index = security.headers.index("Version") if "Version" in security.headers else -1 - alternate_tag_index = ( - security.headers.index("Alternate Tag") if "Alternate Tag" in security.headers else -1 - ) + version_index = security.version_index + alternate_tag_index = security.alternate_tag_index row_index = -1 if version_index >= 0: diff --git a/c2cciutils/security.py b/c2cciutils/security.py index ea653e6a4..8b8ab6939 100644 --- a/c2cciutils/security.py +++ b/c2cciutils/security.py @@ -45,8 +45,6 @@ def __init__(self, status: str, check: bool = True): self._pe(elem.getroot()) self.data = [r for r in self.data if len([c for c in r if c is not None]) > 0] - for row in self.data: - row.append("") self.version_index = self.headers.index(HEADER_VERSION) if HEADER_VERSION in self.headers else -1 self.alternate_tag_index = ( @@ -56,7 +54,8 @@ def __init__(self, status: str, check: bool = True): self.headers.index(HEADER_SUPPORT_UNTIL) if HEADER_SUPPORT_UNTIL in self.headers else -1 ) - if check: + # Check the content if the content isn't empty + if check and status: if not self.check(verbose=0): raise ValueError("SECURITY.md file is not valid.")