From 4160d24abce3e7e5d33a6a3722c41514b1e0ab88 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Wed, 14 Jan 2015 11:36:04 +0800 Subject: [PATCH] management/sync_struct: export process_mod function --- artiq/management/sync_struct.py | 34 +++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/artiq/management/sync_struct.py b/artiq/management/sync_struct.py index 5c5761e61..265e686b2 100644 --- a/artiq/management/sync_struct.py +++ b/artiq/management/sync_struct.py @@ -8,6 +8,24 @@ from artiq.management.tools import AsyncioServer _init_string = b"ARTIQ sync_struct\n" +def process_mod(target, mod): + for key in mod["path"]: + target = getitem(target, key) + action = mod["action"] + if action == "append": + target.append(mod["x"]) + elif action == "insert": + target.insert(mod["i"], mod["x"]) + elif action == "pop": + target.pop(mod["i"]) + elif action == "setitem": + target.__setitem__(mod["key"], mod["value"]) + elif action == "delitem": + target.__delitem__(mod["key"]) + else: + raise ValueError + + class Subscriber: def __init__(self, notifier_name, target_builder, notify_cb=None): self.notifier_name = notifier_name @@ -49,23 +67,11 @@ class Subscriber: if not line: return obj = pyon.decode(line.decode()) - action = obj["action"] - if action == "init": + if obj["action"] == "init": target = self.target_builder(obj["struct"]) else: - for key in obj["path"]: - target = getitem(target, key) - if action == "append": - target.append(obj["x"]) - elif action == "insert": - target.insert(obj["i"], obj["x"]) - elif action == "pop": - target.pop(obj["i"]) - elif action == "setitem": - target.__setitem__(obj["key"], obj["value"]) - elif action == "delitem": - target.__delitem__(obj["key"]) + process_mod(target, obj) if self.notify_cb is not None: self.notify_cb()