#!/usr/bin/env python3
"""Publish repository status atomically for the LAN-only inventory endpoint."""
import json,os,socket,tempfile
from pathlib import Path
import mykos_admin
root=Path('/var/www/mykos-repository-inventory');root.mkdir(mode=0o755,exist_ok=True)
value=mykos_admin.repo_status();value['source_host']=socket.gethostname()
fd,name=tempfile.mkstemp(dir=root,prefix='.inventory-')
try:
 with os.fdopen(fd,'w') as stream:
  json.dump(value,stream);stream.write('\n');stream.flush();os.fchmod(stream.fileno(),0o644)
 os.replace(name,root/'inventory.json')
finally:
 if os.path.exists(name):os.unlink(name)
