| 1 |
#!/usr/bin/env python3 |
| 2 |
# |
| 3 |
# Copyright (C) 2026 Matthias Klumpp <[email protected]> |
| 4 |
# |
| 5 |
# SPDX-License-Identifier: LGPL-2.1-or-later |
| 6 |
# |
| 7 |
|
| 8 |
"""Small helper to ensure a test that needs it has a running D-Bus instance""" |
| 9 |
|
| 10 |
import os |
| 11 |
import sys |
| 12 |
import shutil |
| 13 |
import argparse |
| 14 |
import subprocess |
| 15 |
|
| 16 |
from utils import terminate, system_bus_reachable, start_system_bus_if_needed |
| 17 |
|
| 18 |
|
| 19 |
def main(): |
| 20 |
parser = argparse.ArgumentParser( |
| 21 |
description='Run a PackageKit test and ensure D-Bus is available.' |
| 22 |
) |
| 23 |
parser.add_argument('test_binary') |
| 24 |
args = parser.parse_args() |
| 25 |
|
| 26 |
bus_proc = None |
| 27 |
bus_tmpdir = None |
| 28 |
|
| 29 |
if system_bus_reachable(): |
| 30 |
os.execv(args.test_binary, sys.argv[1:]) |
| 31 |
|
| 32 |
try: |
| 33 |
bus_proc, bus_tmpdir = start_system_bus_if_needed(None) |
| 34 |
|
| 35 |
proc = subprocess.run([args.test_binary], check=False) |
| 36 |
if proc.returncode != 0: |
| 37 |
return proc.returncode |
| 38 |
finally: |
| 39 |
terminate(bus_proc) |
| 40 |
if bus_tmpdir is not None: |
| 41 |
shutil.rmtree(bus_tmpdir, ignore_errors=True) |
| 42 |
|
| 43 |
|
| 44 |
if __name__ == '__main__': |
| 45 |
sys.exit(main()) |