change arguments of stringio-server
+ add verbosity flag Change-Id: I0425efb11f03f8a59d3d81e8f2eeb95aca22e138 Reviewed-on: https://forge.frm2.tum.de/review/c/sine2020/secop/playground/+/23032 Tested-by: JenkinsCodeReview <bjoern_pedersen@frm2.tum.de> Reviewed-by: Enrico Faulhaber <enrico.faulhaber@frm2.tum.de> Reviewed-by: Markus Zolliker <markus.zolliker@psi.ch>
This commit is contained in:
parent
7616153392
commit
4411707f6a
@ -37,6 +37,7 @@ import sys
|
||||
from os import path
|
||||
import asyncore
|
||||
import socket
|
||||
import ast
|
||||
|
||||
# Add import path for inplace usage
|
||||
sys.path.insert(0, path.abspath(path.join(path.dirname(__file__), '..')))
|
||||
@ -85,7 +86,7 @@ class LineServer(asyncore.dispatcher):
|
||||
pair = self.accept()
|
||||
if pair is not None:
|
||||
sock, addr = pair
|
||||
print ("Incoming connection from %s" % repr(addr))
|
||||
print("Incoming connection from %s" % repr(addr))
|
||||
self.lineHandlerClass(sock)
|
||||
|
||||
def loop(self):
|
||||
@ -110,32 +111,44 @@ class Handler(LineHandler):
|
||||
def handle_line(self, line):
|
||||
try:
|
||||
reply = module.do_communicate(line.strip())
|
||||
print('%-40s | %s' % (line, reply))
|
||||
if verbose:
|
||||
print('%-40s | %s' % (line, reply))
|
||||
except Exception:
|
||||
print(formatException(verbose=True))
|
||||
self.send_line(reply)
|
||||
|
||||
|
||||
|
||||
|
||||
class Logger:
|
||||
def debug(self, *args):
|
||||
print(*args)
|
||||
info = exception = debug
|
||||
|
||||
|
||||
if len(sys.argv) < 2:
|
||||
sys.argv.append('secop_psi.ls370sim.Ls370Sim')
|
||||
if len(sys.argv) < 3:
|
||||
sys.argv.append('4567')
|
||||
communicatorname = sys.argv[1]
|
||||
serverport = int(sys.argv[2])
|
||||
opts = {'.description':'simulator'}
|
||||
for arg in sys.argv[3:]:
|
||||
k, v = arg.split('=',1)
|
||||
opts = {'description': 'simulator'}
|
||||
args = []
|
||||
for arg in sys.argv[1:]:
|
||||
k, sep, v = arg.partition('=')
|
||||
if not k:
|
||||
args.append(v)
|
||||
try:
|
||||
v = ast.literal_eval(v)
|
||||
except Exception:
|
||||
pass
|
||||
opts[k] = v
|
||||
verbose = opts.pop('verbose', False)
|
||||
opts['cls'] = 'secop_psi.ls370sim.Ls370Sim'
|
||||
opts['port'] = 4567
|
||||
if len(args) > 2:
|
||||
raise ValueError('do not know about: %s' % ' '.join(args[2:]))
|
||||
if len(args) == 2:
|
||||
opts['port'] = int(args[1])
|
||||
if len(args) > 0:
|
||||
opts['cls'] = args[0]
|
||||
args.append(opts)
|
||||
|
||||
srv = Server('localhost', serverport, Handler)
|
||||
module = get_class(communicatorname)(communicatorname, Logger(), opts, srv)
|
||||
cls = opts.pop('cls')
|
||||
port = opts.pop('port')
|
||||
srv = Server('localhost', int(port), Handler)
|
||||
module = get_class(cls)(cls, Logger(), opts, srv)
|
||||
module.earlyInit()
|
||||
srv.loop()
|
||||
|
Loading…
x
Reference in New Issue
Block a user