#!/usr/bin/python3
# -*- coding: utf-8 -*-

#	content-diff : Analyze diff between two versions of cve-basealt package
#	Copyright (C) 2024-2025 Alexey Appolonov
#
#	This program is free software: you can redistribute it and/or modify
#	it under the terms of the GNU General Public License as published by
#	the Free Software Foundation, either version 3 of the License, or
#	(at your option) any later version.
#
#	This program is distributed in the hope that it will be useful,
#	but WITHOUT ANY WARRANTY; without even the implied warranty of
#	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#	GNU General Public License for more details.
#
#	You should have received a copy of the GNU General Public License
#	along with this program.  If not, see <http://www.gnu.org/licenses/>.

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

import argparse
import os
from sys                        import argv
from cve_inform.current_content import CurrentContent

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Parse the arguments

argparser = argparse.ArgumentParser()
argparser.add_argument(
	'-p', '--paths',
	metavar='DIR_ABS_PATH', type=str, nargs=2,
	help='Paths of the "content" dirs of two compared versions of the '
	'cve-basealt package'
	)
args = argparser.parse_args()

if len(argv) < 2:
	argparser.print_help()
	exit(1)

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

# Get all presented vulnerability IDs from both paths
content = {i: CurrentContent(path).GetVulsSet()
	for i, path in enumerate(args.paths)}

# Vul IDs that are present in second version that are not present in first
diff = content[1] - content[0]

# Display the results
paths = [os.path.basename(path.rstrip('/')) for path in args.paths]
if paths[0] == paths[1]:
	paths = args.paths
print(f'Vul IDs that are missing in "{paths[0]}" compared to "{paths[1]}":')
if diff:
	for vul in sorted(diff):
		print(vul)
else:
	print('-- None --')

exit(0)
