Files

34 lines
1.4 KiB
Python
Executable File

#!/usr/bin/env python3
"""Export one FDS XBPS package, retaining superseded builds outside the active index."""
import argparse
import os
from pathlib import Path
import shutil
import subprocess
import tempfile
project = Path(__file__).resolve().parents[1]
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('package', type=Path)
args = parser.parse_args()
source = args.package.resolve(strict=True)
name, release = source.name.rsplit('-', 1)
if not name.startswith('fds-') or not release.endswith('.aarch64.xbps'):
parser.error('Expected an FDS AArch64 package')
out = project / 'out/packages'
out.mkdir(exist_ok=True)
old = [p for p in out.glob(f'{name}-*.aarch64.xbps') if p.name.rsplit('-', 1)[0] == name]
if old:
history = project / 'out/package-history'
history.mkdir(exist_ok=True)
saved = Path(tempfile.mkdtemp(prefix=f'{name}.', dir=history))
for path in old:
path.rename(saved / path.name)
# Prune entries for archived versions before indexing the selected package.
env = dict(os.environ, XBPS_ARCH='aarch64')
index = project / '.host/xbps/usr/bin/xbps-rindex'
subprocess.run([str(index), '-c', str(out)], env=env, check=True)
shutil.copy2(source, out / source.name)
subprocess.run([str(index), '-fa', str(out / source.name)], env=env, check=True)
print(f'Exported {source.name}; previous builds retained under out/package-history')