-
Notifications
You must be signed in to change notification settings - Fork 0
/
check-report.py
36 lines (27 loc) · 1.37 KB
/
check-report.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import hashlib
import base64
import argparse
import xml.etree.ElementTree as ElementTree
def sha256(filepath):
with open(filepath, "rb") as file:
digest = hashlib.sha256()
while chunk := file.read(8192):
digest.update(chunk)
return digest.hexdigest()
parser_description = "Checks if submission report's dependant documents exist and match the supplied digests"
parser = argparse.ArgumentParser(description=parser_description)
parser.add_argument("-r", "--report", help="submission report file location (ends with .xml)")
parser.add_argument("-c", "--content", help="content folder location (contains all the files for this offer)")
args = parser.parse_args()
namespaces = {'sr': 'https://eten.publicprocurement.be/sr'}
tree = ElementTree.parse(args.report)
documents = tree.findall('sr:tender/sr:documents/sr:document', namespaces=namespaces)
for document in documents:
filename = document.findtext('sr:details/sr:filename', namespaces=namespaces)
expected_digest = base64.b64decode(document.findtext('sr:details/sr:digest/sr:dgValue', namespaces=namespaces)).hex()
try:
actual_digest = sha256(args.content + "/" + filename)
except FileNotFoundError as error:
actual_digest = "[FILE NOT FOUND]"
print(f'[{expected_digest == actual_digest}] {filename} : {expected_digest} vs {actual_digest}')
print("check completed")