diff --git a/poetry.lock b/poetry.lock index 438b2a1d..d0b68f69 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 2.1.1 and should not be changed by hand. +# This file is automatically @generated by Poetry 2.1.2 and should not be changed by hand. [[package]] name = "attrs" @@ -164,7 +164,6 @@ description = "Cross-platform colored terminal text." optional = false python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7" groups = ["main"] -markers = "sys_platform == \"win32\"" files = [ {file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"}, {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, @@ -626,6 +625,18 @@ files = [ {file = "soupsieve-2.7.tar.gz", hash = "sha256:ad282f9b6926286d2ead4750552c8a6142bc4c783fd66b0293547c8fe6ae126a"}, ] +[[package]] +name = "types-colorama" +version = "0.4.15.20240311" +description = "Typing stubs for colorama" +optional = false +python-versions = ">=3.8" +groups = ["main"] +files = [ + {file = "types-colorama-0.4.15.20240311.tar.gz", hash = "sha256:a28e7f98d17d2b14fb9565d32388e419f4108f557a7d939a66319969b2b99c7a"}, + {file = "types_colorama-0.4.15.20240311-py3-none-any.whl", hash = "sha256:6391de60ddc0db3f147e31ecb230006a6823e81e380862ffca1e4695c13a0b8e"}, +] + [[package]] name = "types-jsonschema" version = "4.23.0.20241208" @@ -689,4 +700,4 @@ zstd = ["zstandard (>=0.18.0)"] [metadata] lock-version = "2.1" python-versions = ">= 3.13" -content-hash = "d7bc900df425f2915995c0104ae203b58adcb55f22282da9b5acbc96842aae0a" +content-hash = "d01a497c88d6d315860a3ce2da8777dd3a83759f33bf3119f28382bf7be88090" diff --git a/pyproject.toml b/pyproject.toml index d8a3c938..daed841a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,6 +3,7 @@ name = "drupal-advisory-database" requires-python = ">= 3.13" [tool.poetry.dependencies] +colorama = "^0.4.6" jsonschema = "^4.23.0" markdownify = "^1.1.0" mypy = "^1.15.0" @@ -12,6 +13,7 @@ ruff = "~0.14.0" semver = "^3.0.4" types-jsonschema = "^4.23.0.20241208" types-requests = "^2.32.0.20250328" +types-colorama = "^0.4.15.20240311" [tool.poetry] package-mode = false diff --git a/scripts/generate_osv_advisories.py b/scripts/generate_osv_advisories.py index f539776c..5107a524 100755 --- a/scripts/generate_osv_advisories.py +++ b/scripts/generate_osv_advisories.py @@ -16,6 +16,7 @@ import requests import semver +from helpers import text_is from markdownify import markdownify from typings import drupal, osv @@ -350,10 +351,13 @@ def patch_advisory(sa_id: str, sa_advisory: drupal.Advisory) -> bool: if before == sa_advisory['field_affected_versions']: sa_advisory['field_affected_versions'] = after - print(' \\- patched affected versions') + print(' \\- ' + text_is.success('patched affected versions')) return True print( - f' \\- skipped patching as affected version is now "{sa_advisory["field_affected_versions"]}"' + ' \\- ' + + text_is.warning( + f'skipped patching as affected version is now "{sa_advisory["field_affected_versions"]}"' + ) ) return False @@ -375,14 +379,14 @@ def build_osv_advisory( # we expect that the downloader has excluded PSA type entries, but # we still guard against them here just in case one slips through if sa_advisory['field_is_psa'] == '1': - print(' \\- skipping as it is a psa? (this should not happen)') + print(' \\-' + text_is.error('skipping as it is a psa? (this should not happen)')) return None # there's not really much we can do if there isn't an affected version # todo: since build_affected_ranges throws if this isn't present, it might # make more sense to use that, with a custom exception class if sa_advisory['field_affected_versions'] is None: - print(' \\- skipping as we do not have any affected versions') + print(' \\- ' + text_is.notice('skipping as we do not have any affected versions')) return None osv_advisory: osv.Vulnerability = { @@ -461,7 +465,10 @@ def generate_osv_advisories() -> None: os.makedirs(f'advisories/{name}', exist_ok=True) if is_existing_advisory_ahead(name, sa_id, osv_advisory['modified']): print( - ' \\- error: current modified date is ahead of the proposed modified date (is your cache up to date?)' + ' \\- ' + + text_is.error( + 'error: current modified date is ahead of the proposed modified date (is your cache up to date?)' + ) ) exit(1) diff --git a/scripts/helpers/__init__.py b/scripts/helpers/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/scripts/helpers/text_is.py b/scripts/helpers/text_is.py new file mode 100644 index 00000000..8aa3cb45 --- /dev/null +++ b/scripts/helpers/text_is.py @@ -0,0 +1,19 @@ +from colorama import Fore, Style, just_fix_windows_console + +just_fix_windows_console() + + +def notice(message: str) -> str: + return f'{Fore.YELLOW}{Style.DIM}{message}{Style.RESET_ALL}' + + +def success(message: str) -> str: + return f'{Fore.GREEN}{message}{Style.RESET_ALL}' + + +def warning(message: str) -> str: + return f'{Fore.YELLOW}{message}{Style.RESET_ALL}' + + +def error(message: str) -> str: + return f'{Fore.RED}{message}{Style.RESET_ALL}'