forked from M-Labs/artiq
1
0
Fork 0

browser: decouple dataset controller from dataset dock

This commit is contained in:
Sebastien Bourdeauducq 2023-05-31 21:57:54 +08:00
parent c6b29b30fb
commit c8dc2cbf09
2 changed files with 32 additions and 27 deletions

View File

@ -23,8 +23,30 @@ class Model(DictSyncTreeSepModel):
return short_format(v[1])
class DatasetCtl:
def __init__(self, master_host, master_port):
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)
try:
remote = RPCClient()
await remote.connect_rpc(self.master_host, self.master_port,
"master_dataset_db")
try:
await remote.set(key, value, persist)
finally:
remote.close_rpc()
except:
logger.error("Failed uploading dataset '%s'",
key, exc_info=True)
else:
logger.info("Finished uploading dataset '%s'", key)
class DatasetsDock(QtWidgets.QDockWidget):
def __init__(self, dataset_sub, master_host, master_port):
def __init__(self, dataset_sub, dataset_ctl):
QtWidgets.QDockWidget.__init__(self, "Datasets")
self.setObjectName("Datasets")
self.setFeatures(QtWidgets.QDockWidget.DockWidgetMovable |
@ -64,8 +86,7 @@ class DatasetsDock(QtWidgets.QDockWidget):
self.set_model(Model(dict()))
dataset_sub.add_setmodel_callback(self.set_model)
self.master_host = master_host
self.master_port = master_port
self.dataset_ctl = dataset_ctl
def _search_datasets(self):
if hasattr(self, "table_model_filter"):
@ -82,22 +103,6 @@ class DatasetsDock(QtWidgets.QDockWidget):
self.table_model_filter.setSourceModel(self.table_model)
self.table.setModel(self.table_model_filter)
async def _upload_dataset(self, name, value,):
logger.info("Uploading dataset '%s' to master...", name)
try:
remote = RPCClient()
await remote.connect_rpc(self.master_host, self.master_port,
"master_dataset_db")
try:
await remote.set(name, value)
finally:
remote.close_rpc()
except:
logger.error("Failed uploading dataset '%s'",
name, exc_info=True)
else:
logger.info("Finished uploading dataset '%s'", name)
def upload_clicked(self):
idx = self.table.selectedIndexes()
if idx:
@ -105,7 +110,7 @@ class DatasetsDock(QtWidgets.QDockWidget):
key = self.table_model.index_to_key(idx)
if key is not None:
persist, value = self.table_model.backing_store[key]
asyncio.ensure_future(self._upload_dataset(key, value))
asyncio.ensure_future(self.dataset_ctl.set(key, value))
def save_state(self):
return bytes(self.table.header().saveState())

View File

@ -48,8 +48,8 @@ def get_argparser():
class Browser(QtWidgets.QMainWindow):
def __init__(self, smgr, dataset_sub, browse_root,
master_host, master_port, *, loop=None):
def __init__(self, smgr, dataset_sub, dataset_ctl, browse_root,
*, loop=None):
QtWidgets.QMainWindow.__init__(self)
smgr.register(self)
@ -81,12 +81,11 @@ class Browser(QtWidgets.QMainWindow):
self.files.dataset_changed.connect(
self.experiments.dataset_changed)
self.applets = applets.AppletsDock(self, dataset_sub, loop=loop)
self.applets = applets.AppletsDock(self, dataset_sub, dataset_ctl, loop=loop)
smgr.register(self.applets)
atexit_register_coroutine(self.applets.stop, loop=loop)
self.datasets = datasets.DatasetsDock(
dataset_sub, master_host, master_port)
self.datasets = datasets.DatasetsDock(dataset_sub, dataset_ctl)
smgr.register(self.datasets)
self.files.metadata_changed.connect(self.datasets.metadata_changed)
@ -151,8 +150,9 @@ def main():
smgr = state.StateManager(args.db_file)
browser = Browser(smgr, dataset_sub, args.browse_root,
args.server, args.port, loop=loop)
dataset_ctl = datasets.DatasetCtl(args.server, args.port)
browser = Browser(smgr, dataset_sub, dataset_ctl, args.browse_root,
loop=loop)
widget_log_handler.callback = browser.log.model.append
if os.name == "nt":