23 lines
1.1 KiB
Python
23 lines
1.1 KiB
Python
#!/usr/bin/env python3
|
|
"""Validate local vendor archive and stage byte-identical JARs as private WAR resources."""
|
|
from pathlib import Path
|
|
import xml.etree.ElementTree as ET
|
|
import zipfile, io, hashlib, json
|
|
root=Path(__file__).resolve().parents[1]
|
|
manifest=ET.parse(root/'backend/src/main/resources/hmi/Workplace.jnlp')
|
|
names=sorted({j.attrib['href'] for group in manifest.findall('resources')
|
|
if 'os' not in group.attrib and 'arch' not in group.attrib for j in group.findall('jar')})
|
|
output=root/'.workplace-bundle'
|
|
output.mkdir(exist_ok=True)
|
|
checksums={}
|
|
with zipfile.ZipFile(root/'Workplace.zip') as archive:
|
|
for name in names:
|
|
if '/' in name or '\\' in name or not name.endswith('.jar'): raise ValueError(name)
|
|
data=archive.read('Workplace/'+name)
|
|
with zipfile.ZipFile(io.BytesIO(data)) as jar:
|
|
if jar.testzip() is not None: raise ValueError('Corrupt JAR: '+name)
|
|
(output/name).write_bytes(data)
|
|
checksums[name]=hashlib.sha256(data).hexdigest()
|
|
(output/'SHA256.json').write_text(json.dumps(checksums,indent=2)+'\n')
|
|
print('Validated and staged',len(names),'unaltered vendor JARs')
|