various improvements
- servman.cfg moved to home directory - changed mechanism to retrieve frappy cfg in list - fixed bin/sea to accept also foreign instruments for gui / cli
This commit is contained in:
62
sicsclient.py
Normal file
62
sicsclient.py
Normal file
@ -0,0 +1,62 @@
|
||||
import socket
|
||||
|
||||
|
||||
def raw_sics_client(hostport):
|
||||
if ':' in hostport:
|
||||
host, port = hostport.split(':')
|
||||
hostport = (host, int(port))
|
||||
sock = socket.create_connection(hostport, timeout=3)
|
||||
bbuf = b''
|
||||
while True:
|
||||
try:
|
||||
reply = sock.recv(8192)
|
||||
# print(reply.decode('latin-1'), end='')
|
||||
if not reply:
|
||||
sock.close()
|
||||
return
|
||||
except socket.timeout:
|
||||
sock.close()
|
||||
return
|
||||
bbuf += reply
|
||||
blist = bbuf.split(b'\n')
|
||||
bbuf = blist.pop()
|
||||
for bline in blist:
|
||||
request = yield bline.decode('latin-1')
|
||||
if request is not None:
|
||||
sock.sendall(request.encode('latin-1') + b'\n')
|
||||
|
||||
|
||||
def check(sics, command, expected):
|
||||
reply = sics.send(command)
|
||||
if reply != expected:
|
||||
raise ValueError('expected %r but got %r' % (expected, reply))
|
||||
|
||||
|
||||
def sics_coroutine(hostport, login):
|
||||
sics = raw_sics_client(hostport)
|
||||
check(sics, None, 'OK')
|
||||
check(sics, login, 'Login OK')
|
||||
request = yield
|
||||
while True:
|
||||
reply = sics.send('fulltransact %s' % request)
|
||||
while not reply.startswith('TRANSACTIONSTART'):
|
||||
reply = next(sics)
|
||||
reply = next(sics)
|
||||
result = []
|
||||
while not reply.startswith('TRANSACTIONFINISHED'):
|
||||
result.append(reply)
|
||||
reply = next(sics)
|
||||
request = yield '\n'.join(result)
|
||||
|
||||
|
||||
def sics_client(hostport, login='Spy 007'):
|
||||
sics = sics_coroutine(hostport, login)
|
||||
next(sics) # start generator
|
||||
return sics
|
||||
|
||||
|
||||
def sics_command(hostport, command, login='Spy 007'):
|
||||
sics = sics_client(hostport, login)
|
||||
result = sics.send(command)
|
||||
sics.close()
|
||||
return result
|
Reference in New Issue
Block a user