Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 1 | # |
| 2 | # SPDX-License-Identifier: GPL-2.0-only |
| 3 | # |
| 4 | |
| 5 | import logging |
| 6 | import bb.asyncrpc |
| 7 | |
| 8 | logger = logging.getLogger("BitBake.PRserv") |
| 9 | |
| 10 | class PRAsyncClient(bb.asyncrpc.AsyncClient): |
| 11 | def __init__(self): |
| 12 | super().__init__('PRSERVICE', '1.0', logger) |
| 13 | |
| 14 | async def getPR(self, version, pkgarch, checksum): |
| 15 | response = await self.send_message( |
| 16 | {'get-pr': {'version': version, 'pkgarch': pkgarch, 'checksum': checksum}} |
| 17 | ) |
| 18 | if response: |
| 19 | return response['value'] |
| 20 | |
| 21 | async def importone(self, version, pkgarch, checksum, value): |
| 22 | response = await self.send_message( |
| 23 | {'import-one': {'version': version, 'pkgarch': pkgarch, 'checksum': checksum, 'value': value}} |
| 24 | ) |
| 25 | if response: |
| 26 | return response['value'] |
| 27 | |
| 28 | async def export(self, version, pkgarch, checksum, colinfo): |
| 29 | response = await self.send_message( |
| 30 | {'export': {'version': version, 'pkgarch': pkgarch, 'checksum': checksum, 'colinfo': colinfo}} |
| 31 | ) |
| 32 | if response: |
| 33 | return (response['metainfo'], response['datainfo']) |
| 34 | |
| 35 | async def is_readonly(self): |
| 36 | response = await self.send_message( |
| 37 | {'is-readonly': {}} |
| 38 | ) |
| 39 | if response: |
| 40 | return response['readonly'] |
| 41 | |
| 42 | class PRClient(bb.asyncrpc.Client): |
| 43 | def __init__(self): |
| 44 | super().__init__() |
| 45 | self._add_methods('getPR', 'importone', 'export', 'is_readonly') |
| 46 | |
| 47 | def _get_async_client(self): |
| 48 | return PRAsyncClient() |