Datasets:
File size: 2,132 Bytes
870b85a | 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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | """Record an explicit derived source snapshot while retaining parent hashes."""
import hashlib
import json
from pathlib import Path
BASE = Path(__file__).resolve().parents[1]
PARENT = BASE.with_name('wholehouse_generation_20261023')
def sha(path):
return hashlib.sha256(path.read_bytes()).hexdigest()
def main():
inventory = PARENT / 'BASE_SHA256SUMS'
parent = {}
for line in inventory.read_text().splitlines():
expected, name = line.split(' ', 1)
if sha(PARENT / name) != expected:
raise ValueError('Parent source has changed: ' + name)
parent[name] = expected
for path in (PARENT / 'source').rglob('*'):
if path.is_file() and '__pycache__' not in path.parts and path.suffix != '.pyc':
parent.setdefault(str(path.relative_to(PARENT)), sha(path))
paths = sorted(p for p in (BASE / 'source').rglob('*') if p.is_file()
and '__pycache__' not in p.parts and p.suffix != '.pyc')
current = {str(path.relative_to(BASE)): sha(path) for path in paths}
changes = [{'path': name, 'parent_sha256': parent.get(name),
'derived_sha256': current.get(name)} for name in sorted(parent.keys() | current.keys())
if parent.get(name) != current.get(name)]
(BASE / 'PARENT_BASE_SHA256SUMS').write_bytes(inventory.read_bytes())
(BASE / 'BASE_SHA256SUMS').write_text(''.join(value + ' ' + name + '\n'
for name, value in current.items()))
origin = dict(schema='rhg.derived-source-origin.v1', version='v16.21p-wholehouse-opt3-20261023',
parent_directory=PARENT.name, parent_version='v16.21p-wholehouse-opt2-20261023',
parent_inventory_sha256=sha(inventory), source_directory='source',
base_hash_inventory='BASE_SHA256SUMS', base_files=len(current),
parent_source_unchanged=True, derived_source_modified=True, changes=changes)
(BASE / 'BASE_ORIGIN.json').write_text(json.dumps(origin, indent=2, sort_keys=True) + '\n')
print(json.dumps(dict(files=len(current), changed_files=len(changes), parent_unchanged=True)))
if __name__ == '__main__':
main()
|