Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 1 | # |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 2 | # Copyright BitBake Contributors |
| 3 | # |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 4 | # SPDX-License-Identifier: GPL-2.0-only |
| 5 | # |
| 6 | |
| 7 | import logging |
| 8 | import bb.asyncrpc |
| 9 | |
| 10 | logger = logging.getLogger("BitBake.PRserv") |
| 11 | |
| 12 | class PRAsyncClient(bb.asyncrpc.AsyncClient): |
| 13 | def __init__(self): |
Patrick Williams | 44b3caf | 2024-04-12 16:51:14 -0500 | [diff] [blame] | 14 | super().__init__("PRSERVICE", "1.0", logger) |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 15 | |
| 16 | async def getPR(self, version, pkgarch, checksum): |
Patrick Williams | ac13d5f | 2023-11-24 18:59:46 -0600 | [diff] [blame] | 17 | response = await self.invoke( |
Patrick Williams | 44b3caf | 2024-04-12 16:51:14 -0500 | [diff] [blame] | 18 | {"get-pr": {"version": version, "pkgarch": pkgarch, "checksum": checksum}} |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 19 | ) |
| 20 | if response: |
Patrick Williams | 44b3caf | 2024-04-12 16:51:14 -0500 | [diff] [blame] | 21 | return response["value"] |
| 22 | |
| 23 | async def test_pr(self, version, pkgarch, checksum): |
| 24 | response = await self.invoke( |
| 25 | {"test-pr": {"version": version, "pkgarch": pkgarch, "checksum": checksum}} |
| 26 | ) |
| 27 | if response: |
| 28 | return response["value"] |
| 29 | |
| 30 | async def test_package(self, version, pkgarch): |
| 31 | response = await self.invoke( |
| 32 | {"test-package": {"version": version, "pkgarch": pkgarch}} |
| 33 | ) |
| 34 | if response: |
| 35 | return response["value"] |
| 36 | |
| 37 | async def max_package_pr(self, version, pkgarch): |
| 38 | response = await self.invoke( |
| 39 | {"max-package-pr": {"version": version, "pkgarch": pkgarch}} |
| 40 | ) |
| 41 | if response: |
| 42 | return response["value"] |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 43 | |
| 44 | async def importone(self, version, pkgarch, checksum, value): |
Patrick Williams | ac13d5f | 2023-11-24 18:59:46 -0600 | [diff] [blame] | 45 | response = await self.invoke( |
Patrick Williams | 44b3caf | 2024-04-12 16:51:14 -0500 | [diff] [blame] | 46 | {"import-one": {"version": version, "pkgarch": pkgarch, "checksum": checksum, "value": value}} |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 47 | ) |
| 48 | if response: |
Patrick Williams | 44b3caf | 2024-04-12 16:51:14 -0500 | [diff] [blame] | 49 | return response["value"] |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 50 | |
| 51 | async def export(self, version, pkgarch, checksum, colinfo): |
Patrick Williams | ac13d5f | 2023-11-24 18:59:46 -0600 | [diff] [blame] | 52 | response = await self.invoke( |
Patrick Williams | 44b3caf | 2024-04-12 16:51:14 -0500 | [diff] [blame] | 53 | {"export": {"version": version, "pkgarch": pkgarch, "checksum": checksum, "colinfo": colinfo}} |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 54 | ) |
| 55 | if response: |
Patrick Williams | 44b3caf | 2024-04-12 16:51:14 -0500 | [diff] [blame] | 56 | return (response["metainfo"], response["datainfo"]) |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 57 | |
| 58 | async def is_readonly(self): |
Patrick Williams | ac13d5f | 2023-11-24 18:59:46 -0600 | [diff] [blame] | 59 | response = await self.invoke( |
Patrick Williams | 44b3caf | 2024-04-12 16:51:14 -0500 | [diff] [blame] | 60 | {"is-readonly": {}} |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 61 | ) |
| 62 | if response: |
Patrick Williams | 44b3caf | 2024-04-12 16:51:14 -0500 | [diff] [blame] | 63 | return response["readonly"] |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 64 | |
| 65 | class PRClient(bb.asyncrpc.Client): |
| 66 | def __init__(self): |
| 67 | super().__init__() |
Patrick Williams | 44b3caf | 2024-04-12 16:51:14 -0500 | [diff] [blame] | 68 | self._add_methods("getPR", "test_pr", "test_package", "importone", "export", "is_readonly") |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 69 | |
| 70 | def _get_async_client(self): |
| 71 | return PRAsyncClient() |