support/scripts/pkg-stats: add -N/--needs-update option

This commit adds the -N/--needs-update option, disabled by default,
to list only packages with newer upstream versions. All other packages
will be excluded from the HTML or JSON output.

Signed-off-by: Kadambini Nema <kadambini.nema@gmail.com>
Signed-off-by: Arnout Vandecappelle <arnout@rnout.be>
This commit is contained in:
Kadambini Nema
2025-05-15 01:36:40 -07:00
committed by Arnout Vandecappelle
parent fbad192a4d
commit ed9466e7f9

View File

@@ -1313,12 +1313,22 @@ def parse_args():
default=[])
parser.add_argument('-v', '--verbose', dest='verbose', action='store_true',
help='Increase verbosity')
parser.add_argument('-N', '--needs-update', dest='needs_update', action='store_true',
help='Only include packages with newer versions available')
args = parser.parse_args()
if not args.html and not args.json:
parser.error('at least one of --html or --json (or both) is required')
return args
def is_newer_version_available(pkg):
return not (
pkg.latest_version['status'] in (RM_API_STATUS_ERROR, RM_API_STATUS_NOT_FOUND) or
pkg.latest_version['version'] is None or
pkg.latest_version['version'] == pkg.current_version
)
def __main__():
global cvecheck
@@ -1376,6 +1386,8 @@ def __main__():
if "cve" not in args.disable and args.nvd_path:
print("Checking packages CVEs")
check_package_cves(args.nvd_path, packages)
if args.needs_update:
packages = [pkg for pkg in packages if is_newer_version_available(pkg)]
print("Calculate stats")
stats = calculate_stats(packages)
if args.html: