forked from M-Labs/artiq
1
0
Fork 0

rpctool: change call syntax

This commit is contained in:
Yann Sionneau 2015-02-11 18:13:16 +01:00 committed by Sebastien Bourdeauducq
parent 39dfbb4162
commit af4be9a2e2
2 changed files with 6 additions and 22 deletions

View File

@ -71,18 +71,7 @@ def list_methods(remote):
def call_method(remote, method_name, args): def call_method(remote, method_name, args):
method = getattr(remote, method_name) method = getattr(remote, method_name)
if args != []: ret = method(*[eval(arg) for arg in args])
args = eval(" ".join(args))
try:
iter(args)
except TypeError:
# not iterable
ret = method(args)
else:
# iterable
ret = method(*args)
else:
ret = method()
if ret is not None: if ret is not None:
print("{}".format(ret)) print("{}".format(ret))

View File

@ -56,20 +56,15 @@ in order to call remote functions of an ARTIQ controller.
$ artiq_rpctool.py ::1 3253 call -t lda set_attenuation 5 $ artiq_rpctool.py ::1 3253 call -t lda set_attenuation 5
In general, to call a function named ``f`` with N arguments named In general, to call a function named ``f`` with N arguments named
respectively ``x1, x2, ..., xN``. respectively ``x1, x2, ..., xN`` you can do::
You must pass them as a Python iterable object:: $ artiq_rpctool.py hostname port call -t target f x1 x2 ... xN
$ artiq_rpctool.py hostname port call -t target f '(x1, x2, ..., xN)'
You can use Python syntax to compute arguments as they will be passed You can use Python syntax to compute arguments as they will be passed
to the ``eval()`` primitive:: to the ``eval()`` primitive. But beware to use quotes to separate
arguments which use spaces::
$ artiq_rpctool.py hostname port call -t target f '(x*3+5 for x in range(8))' $ artiq_rpctool.py hostname port call -t target f '3 * 4 + 2' True '[1, 2]'
$ artiq_rpctool.py hostname port call -t target f 'range(5)'
If you only need one argument, you don't need to pass an iterable, a
single value is accepted.
If the called function has a return value, it will get printed to If the called function has a return value, it will get printed to
the standard output if the value is not None like in the standard the standard output if the value is not None like in the standard