From 7ad32d903a42ce4687eaf4c4f18c5e6c4a6747ea Mon Sep 17 00:00:00 2001 From: Florian Agbuya Date: Tue, 6 Jun 2023 18:59:01 +0800 Subject: [PATCH] browser: add update method to dataset controller --- artiq/browser/datasets.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/artiq/browser/datasets.py b/artiq/browser/datasets.py index 76da6340e..2e4ed3884 100644 --- a/artiq/browser/datasets.py +++ b/artiq/browser/datasets.py @@ -28,21 +28,34 @@ class DatasetCtl: self.master_host = master_host self.master_port = master_port - async def set(self, key, value, persist=None): - logger.info("Uploading dataset '%s' to master...", key) + async def _execute_rpc(self, op_name, key_or_mod, value=None, persist=None): + logger.info("Starting %s operation on %s", op_name, key_or_mod) try: remote = RPCClient() await remote.connect_rpc(self.master_host, self.master_port, "master_dataset_db") try: - await remote.set(key, value, persist) + if op_name == "set": + await remote.set(key_or_mod, value, persist) + elif op_name == "update": + await remote.update(key_or_mod) + else: + logger.error("Invalid operation: %s", op_name) + return finally: remote.close_rpc() except: - logger.error("Failed uploading dataset '%s'", - key, exc_info=True) + logger.error("Failed %s operation on %s", op_name, + key_or_mod, exc_info=True) else: - logger.info("Finished uploading dataset '%s'", key) + logger.info("Finished %s operation on %s", op_name, + key_or_mod) + + async def set(self, key, value, persist=None): + await self._execute_rpc("set", key, value, persist) + + async def update(self, mod): + await self._execute_rpc("update", mod) class DatasetsDock(QtWidgets.QDockWidget):