Skip to content

Commit

Permalink
artiq_coreconfig: better arg parsing
Browse files Browse the repository at this point in the history
fallen committed Jun 18, 2015
1 parent d25a07f commit 77ca8bb
Showing 2 changed files with 12 additions and 8 deletions.
6 changes: 3 additions & 3 deletions artiq/frontend/artiq_coreconfig.py
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ def get_argparser():
subparsers.required = True
p_read = subparsers.add_parser("read",
help="read key from core device config")
p_read.add_argument("-k", "--key", type=to_bytes, required=True,
p_read.add_argument("key", type=to_bytes,
help="key to be read from core device config")
p_write = subparsers.add_parser("write",
help="write key-value records to core "
@@ -34,8 +34,8 @@ def get_argparser():
subparsers.add_parser("erase", help="erase core device config")
p_delete = subparsers.add_parser("delete",
help="delete key from core device config")
p_delete.add_argument("-k", "--key", action="append", default=[],
type=to_bytes, required=True,
p_delete.add_argument("key", nargs=argparse.REMAINDER,
default=[], type=to_bytes,
help="key to be deleted from core device config")
parser.add_argument("--ddb", default="ddb.pyon",
help="device database file")
14 changes: 9 additions & 5 deletions doc/manual/utilities.rst
Original file line number Diff line number Diff line change
@@ -109,18 +109,18 @@ When not specified, the artiq_coreconfig tool will assume that there is a file n

To read the record whose key is ``mac``::

$ artiq_coreconfig read -k mac
$ artiq_coreconfig read mac

To write the value ``test_value`` in the key ``my_key``::

$ artiq_coreconfig write -s my_key test_value
$ artiq_coreconfig read -k my_key
$ artiq_coreconfig read my_key
b'test_value'

You can also write entire files in a record using the ``-f`` parameter. This is useful for instance to write the ``idle`` kernel in the flash storage::

$ artiq_coreconfig write -f idle_kernel idle.elf
$ artiq_coreconfig read -k idle_kernel | head -c9
$ artiq_coreconfig read idle_kernel | head -c9
b'\x7fELF

You can write several records at once::
@@ -129,7 +129,11 @@ You can write several records at once::

To remove the previously written key ``my_key``::

$ artiq_coreconfig delete -k my_key
$ artiq_coreconfig delete my_key

You can remove several keys at once::

$ artiq_coreconfig delete key1 key2

To erase the entire flash storage area::

@@ -140,7 +144,7 @@ it::

$ artiq_coreconfig write -s my_key some_value
$ artiq_coreconfig write -s my_key some_other_value
$ artiq_coreconfig read -k my_key
$ artiq_coreconfig read my_key
b'some_other_value'

.. argparse::

0 comments on commit 77ca8bb

Please sign in to comment.