From 39c6bc940cc5dc388d25031c8b0653983db1765d Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Fri, 17 Jul 2015 10:49:55 +0200 Subject: [PATCH] coreconfig: use new database API (closes #75) --- artiq/frontend/artiq_coreconfig.py | 43 ++++++++++++++++-------------- artiq/master/worker_db.py | 4 +-- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/artiq/frontend/artiq_coreconfig.py b/artiq/frontend/artiq_coreconfig.py index 9eb39d7fc..301657117 100755 --- a/artiq/frontend/artiq_coreconfig.py +++ b/artiq/frontend/artiq_coreconfig.py @@ -2,7 +2,7 @@ import argparse -from artiq.master.worker_db import create_device +from artiq.master.worker_db import DeviceManager from artiq.protocols.file_db import FlatFileDB @@ -44,26 +44,29 @@ def get_argparser(): def main(): args = get_argparser().parse_args() - ddb = FlatFileDB(args.ddb) - comm = create_device(ddb.request("comm"), None) + dmgr = DeviceManager(FlatFileDB(args.ddb)) + try: + comm = dmgr.get("comm") - if args.action == "read": - value = comm.flash_storage_read(args.key) - if not value: - print("Key {} does not exist".format(args.key)) - else: - print(value) - elif args.action == "erase": - comm.flash_storage_erase() - elif args.action == "delete": - for key in args.key: - comm.flash_storage_remove(key) - elif args.action == "write": - for key, value in args.string: - comm.flash_storage_write(key, value) - for key, filename in args.file: - with open(filename, "rb") as fi: - comm.flash_storage_write(key, fi.read()) + if args.action == "read": + value = comm.flash_storage_read(args.key) + if not value: + print("Key {} does not exist".format(args.key)) + else: + print(value) + elif args.action == "erase": + comm.flash_storage_erase() + elif args.action == "delete": + for key in args.key: + comm.flash_storage_remove(key) + elif args.action == "write": + for key, value in args.string: + comm.flash_storage_write(key, value) + for key, filename in args.file: + with open(filename, "rb") as fi: + comm.flash_storage_write(key, fi.read()) + finally: + dmgr.close_devices() if __name__ == "__main__": main() diff --git a/artiq/master/worker_db.py b/artiq/master/worker_db.py index bd6d008b3..0da07dcf7 100644 --- a/artiq/master/worker_db.py +++ b/artiq/master/worker_db.py @@ -103,7 +103,7 @@ class ResultDB: result_dict_to_hdf5(f, self.nrt) -def create_device(desc, dmgr): +def _create_device(desc, dmgr): ty = desc["type"] if ty == "local": module = importlib.import_module(desc["module"]) @@ -139,7 +139,7 @@ class DeviceManager: while isinstance(desc, str): # alias desc = self.ddb.get(desc) - dev = create_device(desc, self) + dev = _create_device(desc, self) self.active_devices[name] = dev return dev