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
|
from os import path
|
||||||
import asyncore
|
import asyncore
|
||||||
import socket
|
import socket
|
||||||
|
import ast
|
||||||
|
|
||||||
# Add import path for inplace usage
|
# Add import path for inplace usage
|
||||||
sys.path.insert(0, path.abspath(path.join(path.dirname(__file__), '..')))
|
sys.path.insert(0, path.abspath(path.join(path.dirname(__file__), '..')))
|
||||||
@ -85,7 +86,7 @@ class LineServer(asyncore.dispatcher):
|
|||||||
pair = self.accept()
|
pair = self.accept()
|
||||||
if pair is not None:
|
if pair is not None:
|
||||||
sock, addr = pair
|
sock, addr = pair
|
||||||
print ("Incoming connection from %s" % repr(addr))
|
print("Incoming connection from %s" % repr(addr))
|
||||||
self.lineHandlerClass(sock)
|
self.lineHandlerClass(sock)
|
||||||
|
|
||||||
def loop(self):
|
def loop(self):
|
||||||
@ -110,32 +111,44 @@ class Handler(LineHandler):
|
|||||||
def handle_line(self, line):
|
def handle_line(self, line):
|
||||||
try:
|
try:
|
||||||
reply = module.do_communicate(line.strip())
|
reply = module.do_communicate(line.strip())
|
||||||
print('%-40s | %s' % (line, reply))
|
if verbose:
|
||||||
|
print('%-40s | %s' % (line, reply))
|
||||||
except Exception:
|
except Exception:
|
||||||
print(formatException(verbose=True))
|
print(formatException(verbose=True))
|
||||||
self.send_line(reply)
|
self.send_line(reply)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Logger:
|
class Logger:
|
||||||
def debug(self, *args):
|
def debug(self, *args):
|
||||||
print(*args)
|
print(*args)
|
||||||
info = exception = debug
|
info = exception = debug
|
||||||
|
|
||||||
|
|
||||||
if len(sys.argv) < 2:
|
opts = {'description': 'simulator'}
|
||||||
sys.argv.append('secop_psi.ls370sim.Ls370Sim')
|
args = []
|
||||||
if len(sys.argv) < 3:
|
for arg in sys.argv[1:]:
|
||||||
sys.argv.append('4567')
|
k, sep, v = arg.partition('=')
|
||||||
communicatorname = sys.argv[1]
|
if not k:
|
||||||
serverport = int(sys.argv[2])
|
args.append(v)
|
||||||
opts = {'.description':'simulator'}
|
try:
|
||||||
for arg in sys.argv[3:]:
|
v = ast.literal_eval(v)
|
||||||
k, v = arg.split('=',1)
|
except Exception:
|
||||||
|
pass
|
||||||
opts[k] = v
|
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)
|
cls = opts.pop('cls')
|
||||||
module = get_class(communicatorname)(communicatorname, Logger(), opts, srv)
|
port = opts.pop('port')
|
||||||
|
srv = Server('localhost', int(port), Handler)
|
||||||
|
module = get_class(cls)(cls, Logger(), opts, srv)
|
||||||
module.earlyInit()
|
module.earlyInit()
|
||||||
srv.loop()
|
srv.loop()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user