|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: LGPL-2.1-or-later |
| 4 | +# |
| 5 | +# Copyright (C) 2024 Collabora Limited |
| 6 | +# Author: Jeny Sadadia <[email protected]> |
| 7 | + |
| 8 | +import sys |
| 9 | + |
| 10 | +import kernelci |
| 11 | +import kernelci.config |
| 12 | +from kernelci.legacy.cli import Args, Command, parse_opts |
| 13 | + |
| 14 | +from base import Service |
| 15 | + |
| 16 | + |
| 17 | +class GetBuilds(Service): |
| 18 | + |
| 19 | + def __init__(self, configs, args): |
| 20 | + super().__init__(configs, args, 'get_builds') |
| 21 | + |
| 22 | + def _setup(self, args): |
| 23 | + return self._api_helper.subscribe_filters({ |
| 24 | + 'kind': 'kbuild', |
| 25 | + 'state': 'done', |
| 26 | + 'result': 'pass' |
| 27 | + }, 'build') |
| 28 | + |
| 29 | + def _stop(self, sub_id): |
| 30 | + if sub_id: |
| 31 | + self._api_helper.unsubscribe_filters(sub_id) |
| 32 | + sys.stdout.flush() |
| 33 | + |
| 34 | + def _run(self, sub_id): |
| 35 | + self.log.info("Listening for events... ") |
| 36 | + self.log.info("Press Ctrl-C to stop.") |
| 37 | + |
| 38 | + while True: |
| 39 | + node, _ = self._api_helper.receive_event_node(sub_id) |
| 40 | + self.log.info(f"Build node received: {node}") |
| 41 | + self.log.info(f"artifacts: {node.get('artifacts')}") |
| 42 | + return True |
| 43 | + |
| 44 | + |
| 45 | +class cmd_run(Command): |
| 46 | + help = "Listen for successful kernel build events" |
| 47 | + args = [Args.api_config] |
| 48 | + |
| 49 | + def __call__(self, configs, args): |
| 50 | + return GetBuilds(configs, args).run(args) |
| 51 | + |
| 52 | + |
| 53 | +if __name__ == '__main__': |
| 54 | + opts = parse_opts('get_builds', globals()) |
| 55 | + yaml_configs = opts.get_yaml_configs() or 'config' |
| 56 | + configs = kernelci.config.load(yaml_configs) |
| 57 | + status = opts.command(configs, opts) |
| 58 | + sys.exit(0 if status is True else 1) |
0 commit comments