Files
Investidor-V2/tools/portal-stability-gis-scan.py
nala 287e991486
tests / ci (push) Waiting to run
oportunidades 7
2026-10-13 11:40:29 +02:00

21 lines
1.9 KiB
Python

"""Complete the retained ADM3 GIS scan without changing document upload limits."""
from pathlib import Path
import datetime, hashlib, json, subprocess
ROOT=Path(__file__).resolve().parent.parent
PRIVATE=ROOT/'storage/app/private/investmoz-v2/portal-audit'
p=json.loads((PRIVATE/'portal-stability-latest.json').read_text(encoding='utf-8'))
source=Path(p['source']);directory=source/'storage/app/private/investmoz-v2/portal-audit'
file=directory/'moz-adm3-ine-20190607.geojson'
digest=hashlib.sha256(file.read_bytes()).hexdigest()
scans=json.loads((directory/'geometry-source-scans.json').read_text(encoding='utf-8'))
row=next(s for s in scans['files'] if s['file']==file.name)
assert digest==row['sha256']
command=[str(Path(p['antivirus_QA']['binary'])/'clamscan.exe'), '--database='+str(Path(p['antivirus_QA']['work'])/'database'), '--max-filesize=40M', '--max-scansize=100M', '--no-summary', str(file)]
result=subprocess.run(command,capture_output=True,text=True,timeout=90)
assert result.returncode==0 and result.stdout.rstrip().endswith(': OK'), 'Retained GIS scan did not complete cleanly.'
row['gis_scan']={'result':'clean','engine':'ClamAV','engine_version':row['scan']['engine_version'],'signatures_at':row['scan']['signatures_at'],'scope':'retained official GIS exemplar only','original_sha256':digest,'max_file_size':'40M','max_scan_size':'100M','exit_code':0,'captured_at':datetime.datetime.now(datetime.timezone.utc).isoformat()}
(directory/'geometry-source-scans.json').write_text(json.dumps(scans,indent=2),encoding='utf-8')
proof={'at':row['gis_scan']['captured_at'],'file':file.name,'sha256':digest,'ClamD_result_preserved':row['scan'],'GIS_scan':row['gis_scan'],'document_upload_limits_unchanged':True,'active_writes':0}
(PRIVATE/'portal-stability-gis-scan.json').write_text(json.dumps(proof,indent=2),encoding='utf-8')
print(json.dumps({'result':'retained_GIS_scan_clean','file':file.name,'document_upload_limits_unchanged':True,'active_writes':0}))