forked from M-Labs/artiq
coreconfig: use new database API (closes #75)
This commit is contained in:
parent
9649e1837a
commit
39c6bc940c
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
from artiq.master.worker_db import create_device
|
from artiq.master.worker_db import DeviceManager
|
||||||
from artiq.protocols.file_db import FlatFileDB
|
from artiq.protocols.file_db import FlatFileDB
|
||||||
|
|
||||||
|
|
||||||
|
@ -44,26 +44,29 @@ def get_argparser():
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
args = get_argparser().parse_args()
|
args = get_argparser().parse_args()
|
||||||
ddb = FlatFileDB(args.ddb)
|
dmgr = DeviceManager(FlatFileDB(args.ddb))
|
||||||
comm = create_device(ddb.request("comm"), None)
|
try:
|
||||||
|
comm = dmgr.get("comm")
|
||||||
|
|
||||||
if args.action == "read":
|
if args.action == "read":
|
||||||
value = comm.flash_storage_read(args.key)
|
value = comm.flash_storage_read(args.key)
|
||||||
if not value:
|
if not value:
|
||||||
print("Key {} does not exist".format(args.key))
|
print("Key {} does not exist".format(args.key))
|
||||||
else:
|
else:
|
||||||
print(value)
|
print(value)
|
||||||
elif args.action == "erase":
|
elif args.action == "erase":
|
||||||
comm.flash_storage_erase()
|
comm.flash_storage_erase()
|
||||||
elif args.action == "delete":
|
elif args.action == "delete":
|
||||||
for key in args.key:
|
for key in args.key:
|
||||||
comm.flash_storage_remove(key)
|
comm.flash_storage_remove(key)
|
||||||
elif args.action == "write":
|
elif args.action == "write":
|
||||||
for key, value in args.string:
|
for key, value in args.string:
|
||||||
comm.flash_storage_write(key, value)
|
comm.flash_storage_write(key, value)
|
||||||
for key, filename in args.file:
|
for key, filename in args.file:
|
||||||
with open(filename, "rb") as fi:
|
with open(filename, "rb") as fi:
|
||||||
comm.flash_storage_write(key, fi.read())
|
comm.flash_storage_write(key, fi.read())
|
||||||
|
finally:
|
||||||
|
dmgr.close_devices()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
|
@ -103,7 +103,7 @@ class ResultDB:
|
||||||
result_dict_to_hdf5(f, self.nrt)
|
result_dict_to_hdf5(f, self.nrt)
|
||||||
|
|
||||||
|
|
||||||
def create_device(desc, dmgr):
|
def _create_device(desc, dmgr):
|
||||||
ty = desc["type"]
|
ty = desc["type"]
|
||||||
if ty == "local":
|
if ty == "local":
|
||||||
module = importlib.import_module(desc["module"])
|
module = importlib.import_module(desc["module"])
|
||||||
|
@ -139,7 +139,7 @@ class DeviceManager:
|
||||||
while isinstance(desc, str):
|
while isinstance(desc, str):
|
||||||
# alias
|
# alias
|
||||||
desc = self.ddb.get(desc)
|
desc = self.ddb.get(desc)
|
||||||
dev = create_device(desc, self)
|
dev = _create_device(desc, self)
|
||||||
self.active_devices[name] = dev
|
self.active_devices[name] = dev
|
||||||
return dev
|
return dev
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue