38 lines
1.7 KiB
Python
38 lines
1.7 KiB
Python
#!/usr/bin/env python3
|
|
"""Keep current public image/layer refs; resign summary after pruning history."""
|
|
import argparse
|
|
import fcntl
|
|
import json
|
|
from pathlib import Path
|
|
import subprocess
|
|
|
|
def compact(public, home, key):
|
|
with (public / '.publish.lock').open('a') as lock:
|
|
fcntl.flock(lock, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
|
current = (public / 'current').resolve(strict=True)
|
|
refs = set(json.loads((current / 'publication-refs.json').read_text()).values())
|
|
for kind in ('images', 'layers'):
|
|
repo = current / 'ostree' / kind
|
|
def ostree(*args):
|
|
return subprocess.check_output(['ostree', '--repo=' + str(repo), *args], text=True).strip()
|
|
keep = refs | ({'purpose/desktop/gnome', 'purpose/desktop/kde'} if kind == 'layers' else set())
|
|
for ref in ostree('refs').splitlines():
|
|
if ref not in keep:
|
|
ostree('refs', '--delete', ref)
|
|
print(kind, ostree('prune', '--refs-only', '--depth=0'), flush=True)
|
|
ostree('summary', '--update', '--gpg-sign=' + key, '--gpg-homedir=' + str(home))
|
|
print(kind, ostree('refs'), flush=True)
|
|
history = current / 'history.json'
|
|
old = json.loads(history.read_text())
|
|
iso_history = current / 'iso-history.json'
|
|
if not iso_history.exists():
|
|
iso_history.write_text(json.dumps(old, indent=2) + '\n')
|
|
history.write_text(json.dumps({v: rows[-1:] for v, rows in old.items()}, indent=2) + '\n')
|
|
|
|
if __name__ == '__main__':
|
|
p = argparse.ArgumentParser()
|
|
p.add_argument('public', type=Path)
|
|
p.add_argument('home', type=Path)
|
|
p.add_argument('key')
|
|
a = p.parse_args()
|
|
compact(a.public, a.home, a.key)
|