From 0e3927b01adb007024ae14000b57497137b0d77b Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Sun, 4 Oct 2015 17:38:07 +0800 Subject: [PATCH] master: support DDB rescan --- artiq/frontend/artiq_client.py | 38 ++++++++++++---------------------- artiq/frontend/artiq_master.py | 3 ++- artiq/master/ddb.py | 21 +++++++++++++++++++ 3 files changed, 36 insertions(+), 26 deletions(-) create mode 100644 artiq/master/ddb.py diff --git a/artiq/frontend/artiq_client.py b/artiq/frontend/artiq_client.py index 216c09809..f3a15fa24 100755 --- a/artiq/frontend/artiq_client.py +++ b/artiq/frontend/artiq_client.py @@ -61,16 +61,6 @@ def get_argparser(): parser_delete.add_argument("rid", type=int, help="run identifier (RID)") - parser_set_device = subparsers.add_parser( - "set-device", help="add or modify a device") - parser_set_device.add_argument("name", help="name of the device") - parser_set_device.add_argument("description", - help="description in PYON format") - - parser_del_device = subparsers.add_parser( - "del-device", help="delete a device") - parser_del_device.add_argument("name", help="name of the device") - parser_set_parameter = subparsers.add_parser( "set-parameter", help="add or modify a parameter") parser_set_parameter.add_argument("name", help="name of the parameter") @@ -87,11 +77,14 @@ def get_argparser(): "what", help="select object to show: schedule/log/devices/parameters") - parser_scan = subparsers.add_parser("scan-repository", - help="trigger a repository (re)scan") - parser_scan.add_argument("revision", default=None, nargs="?", - help="use a specific repository revision " - "(defaults to head)") + subparsers.add_parser( + "scan-ddb", help="trigger a device database (re)scan") + + parser_scan_repos = subparsers.add_parser( + "scan-repository", help="trigger a repository (re)scan") + parser_scan_repos.add_argument("revision", default=None, nargs="?", + help="use a specific repository revision " + "(defaults to head)") return parser @@ -131,14 +124,6 @@ def _action_delete(remote, args): remote.delete(args.rid) -def _action_set_device(remote, args): - remote.set(args.name, pyon.decode(args.description)) - - -def _action_del_device(remote, args): - remote.delete(args.name) - - def _action_set_parameter(remote, args): remote.set(args.name, pyon.decode(args.value)) @@ -147,6 +132,10 @@ def _action_del_parameter(remote, args): remote.delete(args.name) +def _action_scan_ddb(remote, args): + remote.scan() + + def _action_scan_repository(remote, args): remote.scan_async(args.revision) @@ -275,10 +264,9 @@ def main(): target_name = { "submit": "master_schedule", "delete": "master_schedule", - "set_device": "master_ddb", - "del_device": "master_ddb", "set_parameter": "master_pdb", "del_parameter": "master_pdb", + "scan_ddb": "master_ddb", "scan_repository": "master_repository" }[action] remote = Client(args.server, port, target_name) diff --git a/artiq/frontend/artiq_master.py b/artiq/frontend/artiq_master.py index 2d6fffd18..0373873f9 100755 --- a/artiq/frontend/artiq_master.py +++ b/artiq/frontend/artiq_master.py @@ -7,6 +7,7 @@ import os from artiq.protocols.pc_rpc import Server from artiq.protocols.sync_struct import Notifier, Publisher, process_mod +from artiq.master.ddb import DDB from artiq.protocols.file_db import FlatFileDB from artiq.master.scheduler import Scheduler from artiq.master.worker_db import get_last_rid @@ -64,7 +65,7 @@ def main(): loop = asyncio.get_event_loop() atexit.register(lambda: loop.close()) - ddb = FlatFileDB(args.ddb) + ddb = DDB(args.ddb) pdb = FlatFileDB(args.pdb) rtr = Notifier(dict()) log = Log(1000) diff --git a/artiq/master/ddb.py b/artiq/master/ddb.py new file mode 100644 index 000000000..9a2a1b34d --- /dev/null +++ b/artiq/master/ddb.py @@ -0,0 +1,21 @@ +from artiq.protocols.sync_struct import Notifier +from artiq.protocols import pyon + + +class DDB: + def __init__(self, backing_file): + self.backing_file = backing_file + self.data = Notifier(pyon.load_file(self.backing_file)) + + def scan(self): + new_data = pyon.load_file(self.backing_file) + + for k in list(self.data.read.keys()): + if k not in new_data: + del self.data[k] + for k in new_data.keys(): + if k not in self.data.read or self.data.read[k] != new_data[k]: + self.data[k] = new_data[k] + + def get(self, key): + return self.data.read[key]