improve online help of frappy-cli

- help text shown exactly once (even with no or more arguments)
- automatically generated client object names
+ stay in interactive mode even when not all clients succeded

Change-Id: Iefcac66df92f47363e43bc9b97bb2082f153e5df
Reviewed-on: https://forge.frm2.tum.de/review/c/secop/frappy/+/30583
Tested-by: Jenkins Automated Tests <pedersen+jenkins@frm2.tum.de>
Reviewed-by: Alexander Zaft <a.zaft@fz-juelich.de>
Reviewed-by: Enrico Faulhaber <enrico.faulhaber@frm2.tum.de>
Reviewed-by: Markus Zolliker <markus.zolliker@psi.ch>
This commit is contained in:
2023-02-17 07:25:37 +01:00
parent 494960a2ac
commit 746df2eb94
2 changed files with 84 additions and 30 deletions

View File

@ -18,7 +18,6 @@
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Module authors:
# Alexander Lenz <alexander.lenz@frm2.tum.de>
# Markus Zolliker <markus.zolliker@psi.ch>
#
# *****************************************************************************
@ -34,7 +33,43 @@ sys.path.insert(0, path.abspath(path.join(path.dirname(__file__), '..')))
from frappy.client.interactive import Client, watch
for node in sys.argv[1:]:
Client(node)
_USAGE = """
Usage:
%s
# for all SECoP modules objects are created in the main namespace
code.interact(banner='', local=sys.modules['__main__'].__dict__)
<module> # list all parameters
<module>.<param> = <value> # change parameter
<module>(<target>) # set target and wait until not busy
# 'status' and 'value' changes are shown every 1 sec
%s.mininterval = 0.2 # change minimal update interval to 0.2 sec (default is 1 second)
watch(T) # watch changes of T.status and T.value (stop with ctrl-C)
watch(T='status target') # watch status and target parameters
watch(io, T=True) # watch io and all parameters of T
"""
_CLIENT_USAGE = """
c = Client('localhost:5000')
"""
Client.show_usage = False
if len(sys.argv) < 2:
_usage_args = ("\ncli = Client('localhost:5000')\n", 'cli')
success = True
else:
_usage_args = ('', '_c0')
success = False
for _idx, _node in enumerate(sys.argv[1:]):
_client_name = '_c%d' % _idx
try:
setattr(sys.modules['__main__'], _client_name, Client(_node, name=_client_name))
success = True
except Exception as e:
print(repr(e))
if success:
print(_USAGE % _usage_args)
code.interact(banner='', local=sys.modules['__main__'].__dict__)