|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +import argparse |
| 4 | + |
| 5 | +from artiq.master.worker_db import create_device |
| 6 | +from artiq.protocols.file_db import FlatFileDB |
| 7 | + |
| 8 | + |
| 9 | +def to_bytes(string): |
| 10 | + return bytes(string, encoding="ascii") |
| 11 | + |
| 12 | + |
| 13 | +def get_argparser(): |
| 14 | + parser = argparse.ArgumentParser(description="ARTIQ core device config " |
| 15 | + "remote access") |
| 16 | + parser.add_argument("-r", "--read", type=to_bytes, |
| 17 | + help="read key from core device config") |
| 18 | + parser.add_argument("-w", "--write", nargs=2, action="append", default=[], |
| 19 | + metavar=("KEY", "STRING"), type=to_bytes, |
| 20 | + help="write key-value records to core device config") |
| 21 | + parser.add_argument("-f", "--write-file", nargs=2, action="append", |
| 22 | + type=to_bytes, default=[], metavar=("KEY", "FILENAME"), |
| 23 | + help="write the content of a file into core device " |
| 24 | + "config") |
| 25 | + parser.add_argument("-e", "--erase", action="store_true", |
| 26 | + help="erase core device config") |
| 27 | + parser.add_argument("-d", "--delete", action="append", default=[], |
| 28 | + type=to_bytes, |
| 29 | + help="delete key from core device config") |
| 30 | + parser.add_argument("--ddb", default="ddb.pyon", |
| 31 | + help="device database file") |
| 32 | + return parser |
| 33 | + |
| 34 | + |
| 35 | +def main(): |
| 36 | + args = get_argparser().parse_args() |
| 37 | + ddb = FlatFileDB(args.ddb) |
| 38 | + comm = create_device(ddb.request("comm"), None) |
| 39 | + |
| 40 | + if args.read: |
| 41 | + value = comm.flash_storage_read(args.read) |
| 42 | + if not value: |
| 43 | + print("Key {} does not exist".format(args.read)) |
| 44 | + else: |
| 45 | + print(value) |
| 46 | + elif args.erase: |
| 47 | + comm.flash_storage_erase() |
| 48 | + elif args.delete: |
| 49 | + for key in args.delete: |
| 50 | + comm.flash_storage_remove(key) |
| 51 | + else: |
| 52 | + if args.write: |
| 53 | + for key, value in args.write: |
| 54 | + comm.flash_storage_write(key, value) |
| 55 | + if args.write_file: |
| 56 | + for key, filename in args.write_file: |
| 57 | + with open(filename, "rb") as fi: |
| 58 | + comm.flash_storage_write(key, fi.read()) |
| 59 | + |
| 60 | +if __name__ == "__main__": |
| 61 | + main() |
0 commit comments