fetched mlz version
- before some chamges in the gerrit pipline Change-Id: I33eb2d75f83345a7039d0fb709e66defefb1c3e0
This commit is contained in:
@ -29,8 +29,8 @@ from os import path
|
||||
# Add import path for inplace usage
|
||||
sys.path.insert(0, path.abspath(path.join(path.dirname(__file__), '..')))
|
||||
|
||||
from secop.gui.qt import QApplication
|
||||
from secop.gui.cfg_editor.mainwindow import MainWindow
|
||||
from frappy.gui.qt import QApplication
|
||||
from frappy.gui.cfg_editor.mainwindow import MainWindow
|
||||
|
||||
|
||||
def main(argv=None):
|
||||
@ -40,7 +40,7 @@ def main(argv=None):
|
||||
app = QApplication(argv)
|
||||
window = MainWindow(args.file)
|
||||
window.show()
|
||||
return app.exec_()
|
||||
return app.exec()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
106
bin/frappy-cli
Executable file
106
bin/frappy-cli
Executable file
@ -0,0 +1,106 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# *****************************************************************************
|
||||
# Copyright (c) 2015-2016 by the authors, see LICENSE
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it under
|
||||
# the terms of the GNU General Public License as published by the Free Software
|
||||
# Foundation; either version 2 of the License, or (at your option) any later
|
||||
# version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
# details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with
|
||||
# this program; if not, write to the Free Software Foundation, Inc.,
|
||||
# 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>
|
||||
#
|
||||
# *****************************************************************************
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import sys
|
||||
import argparse
|
||||
from os import path
|
||||
|
||||
# Add import path for inplace usage
|
||||
sys.path.insert(0, path.abspath(path.join(path.dirname(__file__), '..')))
|
||||
|
||||
from frappy.client.interactive import Client, watch, Console
|
||||
|
||||
|
||||
def parseArgv(argv):
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('-i', '--include',
|
||||
help='file to execute after connecting to the clients', metavar='file',
|
||||
type=str, action='append', default=[])
|
||||
parser.add_argument('-o', '--only-execute',
|
||||
help='Do not go into interactive mode after executing files. \
|
||||
Has no effect without --include.', action='store_true')
|
||||
parser.add_argument('node',
|
||||
help='Nodes the client should connect to.\n', metavar='host:port',
|
||||
nargs='*', type=str, default=[])
|
||||
return parser.parse_args(argv)
|
||||
|
||||
|
||||
_USAGE = """
|
||||
Usage:
|
||||
%s
|
||||
# for all SECoP modules objects are created in the main namespace
|
||||
|
||||
<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
|
||||
|
||||
|
||||
args = parseArgv(sys.argv[1:])
|
||||
if not args.node:
|
||||
_usage_args = ("\ncli = Client('localhost:5000')\n", 'cli')
|
||||
success = True
|
||||
else:
|
||||
_usage_args = ('', '_c0')
|
||||
success = False
|
||||
|
||||
for _idx, _node in enumerate(args.node):
|
||||
_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))
|
||||
|
||||
|
||||
file_success = False
|
||||
try:
|
||||
for file in args.include:
|
||||
with open(file, 'r') as f:
|
||||
exec(f.read())
|
||||
file_success = True
|
||||
except Exception as e:
|
||||
print('Error while executing %s: %s' % (file, e))
|
||||
|
||||
if success:
|
||||
if args.include and file_success and args.only_execute:
|
||||
print('skipping interactive mode')
|
||||
exit()
|
||||
print(_USAGE % _usage_args)
|
||||
Console(sys.modules['__main__'].__dict__)
|
@ -26,45 +26,53 @@
|
||||
from __future__ import print_function
|
||||
|
||||
import sys
|
||||
import argparse
|
||||
from os import path
|
||||
|
||||
# Add import path for inplace usage
|
||||
sys.path.insert(0, path.abspath(path.join(path.dirname(__file__), '..')))
|
||||
|
||||
import mlzlog
|
||||
import logging
|
||||
from mlzlog import ColoredConsoleHandler
|
||||
|
||||
from secop.gui.qt import QApplication
|
||||
from secop.gui.mainwindow import MainWindow
|
||||
from frappy.gui.qt import QApplication
|
||||
from frappy.gui.mainwindow import MainWindow
|
||||
|
||||
def parseArgv(argv):
|
||||
parser = argparse.ArgumentParser()
|
||||
loggroup = parser.add_mutually_exclusive_group()
|
||||
loggroup.add_argument('-d', '--debug',
|
||||
help='Enable debug output',
|
||||
action='store_true', default=False)
|
||||
loggroup.add_argument('-q', '--quiet',
|
||||
help='Supress everything but errors',
|
||||
action='store_true', default=False)
|
||||
parser.add_argument('node',
|
||||
help='Nodes the Gui should connect to.\n', metavar='host[:port]',
|
||||
nargs='*', type=str, default=[])
|
||||
return parser.parse_args(argv)
|
||||
|
||||
|
||||
def main(argv=None):
|
||||
if argv is None:
|
||||
argv = sys.argv
|
||||
|
||||
if '-h' in argv or '--help' in argv:
|
||||
print("Usage: secop-gui [-d] [-h] [host:[port]]")
|
||||
print()
|
||||
print("Option GNU long option Meaning")
|
||||
print("-h --help Show this message")
|
||||
print("-d --debug Enable debug output")
|
||||
print()
|
||||
print("if not given, host defaults to 'localhost' and port to 10767")
|
||||
sys.exit(0)
|
||||
args = parseArgv(argv[1:])
|
||||
|
||||
if '-d' in argv or '--debug' in argv:
|
||||
mlzlog.initLogging('gui', 'debug')
|
||||
else:
|
||||
mlzlog.initLogging('gui', 'info')
|
||||
loglevel = logging.DEBUG if args.debug else (logging.ERROR if args.quiet else logging.INFO)
|
||||
logger = logging.getLogger('gui')
|
||||
logger.setLevel(logging.DEBUG)
|
||||
console = ColoredConsoleHandler()
|
||||
console.setLevel(loglevel)
|
||||
logger.addHandler(console)
|
||||
|
||||
app = QApplication(argv)
|
||||
|
||||
hosts = [host for host in argv[1:] if not host.startswith('-')]
|
||||
if not hosts:
|
||||
hosts = ['localhost:10767']
|
||||
win = MainWindow(hosts)
|
||||
win = MainWindow(args.node, logger)
|
||||
app.aboutToQuit.connect(win._onQuit)
|
||||
win.show()
|
||||
|
||||
return app.exec_()
|
||||
return app.exec()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
39
bin/frappy-play
Executable file
39
bin/frappy-play
Executable file
@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# *****************************************************************************
|
||||
# Copyright (c) 2015-2016 by the authors, see LICENSE
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it under
|
||||
# the terms of the GNU General Public License as published by the Free Software
|
||||
# Foundation; either version 2 of the License, or (at your option) any later
|
||||
# version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
# details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with
|
||||
# this program; if not, write to the Free Software Foundation, Inc.,
|
||||
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
# Module authors:
|
||||
# Markus Zolliker <markus.zolliker@psi.ch>
|
||||
#
|
||||
# *****************************************************************************
|
||||
|
||||
import sys
|
||||
from os import path
|
||||
|
||||
# Add import path for inplace usage
|
||||
sys.path.insert(0, path.abspath(path.join(path.dirname(__file__), '..')))
|
||||
|
||||
from frappy.client.interactive import Console
|
||||
from frappy.playground import play, USAGE
|
||||
|
||||
if len(sys.argv) > 1:
|
||||
play(sys.argv[1])
|
||||
else:
|
||||
print(USAGE)
|
||||
|
||||
Console(sys.modules['__main__'].__dict__, 'play')
|
@ -30,9 +30,9 @@ from os import path
|
||||
# Add import path for inplace usage
|
||||
sys.path.insert(0, path.abspath(path.join(path.dirname(__file__), '..')))
|
||||
|
||||
from secop.lib import generalConfig
|
||||
from secop.logging import logger
|
||||
from secop.server import Server
|
||||
from frappy.lib import generalConfig
|
||||
from frappy.logging import logger
|
||||
from frappy.server import Server
|
||||
|
||||
|
||||
def parseArgv(argv):
|
||||
@ -90,8 +90,9 @@ def main(argv=None):
|
||||
args = parseArgv(argv[1:])
|
||||
|
||||
loglevel = 'debug' if args.verbose else ('error' if args.quiet else 'info')
|
||||
generalConfig.defaults = {k: args.relaxed for k in (
|
||||
'lazy_number_validation', 'disable_value_range_check', 'legacy_hasiodev', 'tolerate_poll_property')}
|
||||
generalConfig.set_default('lazy_number_validation', args.relaxed)
|
||||
generalConfig.set_default('legacy_hasiodev', args.relaxed)
|
||||
generalConfig.set_default('tolerate_poll_property', args.relaxed)
|
||||
generalConfig.init(args.gencfg)
|
||||
logger.init(loglevel)
|
||||
|
@ -34,15 +34,17 @@ Use cases, mainly for test purposes:
|
||||
"""
|
||||
|
||||
import sys
|
||||
import argparse
|
||||
from os import path
|
||||
import asyncore
|
||||
import socket
|
||||
import ast
|
||||
import time
|
||||
|
||||
# Add import path for inplace usage
|
||||
sys.path.insert(0, path.abspath(path.join(path.dirname(__file__), '..')))
|
||||
|
||||
from secop.lib import get_class, formatException
|
||||
from frappy.lib import get_class, formatException, mkthread
|
||||
|
||||
|
||||
class LineHandler(asyncore.dispatcher_with_send):
|
||||
|
||||
@ -51,6 +53,9 @@ class LineHandler(asyncore.dispatcher_with_send):
|
||||
asyncore.dispatcher_with_send.__init__(self, sock)
|
||||
self.crlf = 0
|
||||
|
||||
def handle_line(self, line):
|
||||
raise NotImplementedError
|
||||
|
||||
def handle_read(self):
|
||||
data = self.recv(8192)
|
||||
if data:
|
||||
@ -74,20 +79,22 @@ class LineHandler(asyncore.dispatcher_with_send):
|
||||
|
||||
class LineServer(asyncore.dispatcher):
|
||||
|
||||
def __init__(self, host, port, lineHandlerClass):
|
||||
def __init__(self, port, line_handler_cls, handler_args):
|
||||
asyncore.dispatcher.__init__(self)
|
||||
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
self.set_reuse_addr()
|
||||
self.bind((host, port))
|
||||
self.bind(('0.0.0.0', port))
|
||||
self.listen(5)
|
||||
self.lineHandlerClass = lineHandlerClass
|
||||
print('accept connections at port', port)
|
||||
self.line_handler_cls = line_handler_cls
|
||||
self.handler_args = handler_args
|
||||
|
||||
def handle_accept(self):
|
||||
pair = self.accept()
|
||||
if pair is not None:
|
||||
sock, addr = pair
|
||||
print("Incoming connection from %s" % repr(addr))
|
||||
self.lineHandlerClass(sock)
|
||||
self.line_handler_cls(sock, self.handler_args)
|
||||
|
||||
def loop(self):
|
||||
asyncore.loop()
|
||||
@ -108,47 +115,73 @@ class Server(LineServer):
|
||||
|
||||
|
||||
class Handler(LineHandler):
|
||||
def __init__(self, sock, handler_args):
|
||||
super().__init__(sock)
|
||||
self.module = handler_args['module']
|
||||
self.verbose = handler_args['verbose']
|
||||
|
||||
def handle_line(self, line):
|
||||
try:
|
||||
reply = module.do_communicate(line.strip())
|
||||
if verbose:
|
||||
reply = self.module.communicate(line.strip())
|
||||
if self.verbose:
|
||||
print('%-40s | %s' % (line, reply))
|
||||
except Exception:
|
||||
print(formatException(verbose=True))
|
||||
return
|
||||
self.send_line(reply)
|
||||
|
||||
|
||||
class Logger:
|
||||
def debug(self, *args):
|
||||
print(*args)
|
||||
info = exception = debug
|
||||
|
||||
|
||||
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)
|
||||
|
||||
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()
|
||||
def log(self, level, *args):
|
||||
pass
|
||||
|
||||
def info(self, *args):
|
||||
print(*args)
|
||||
|
||||
exception = error = warn = info
|
||||
|
||||
|
||||
def parse_argv(argv):
|
||||
parser = argparse.ArgumentParser(description="Simulate HW with a serial interface")
|
||||
parser.add_argument("-v", "--verbose",
|
||||
help="output full communication",
|
||||
action='store_true', default=False)
|
||||
parser.add_argument("cls",
|
||||
type=str,
|
||||
help="simulator class.\n",)
|
||||
parser.add_argument('-p',
|
||||
'--port',
|
||||
action='store',
|
||||
help='server port or uri',
|
||||
default=2089)
|
||||
return parser.parse_args(argv)
|
||||
|
||||
|
||||
def poller(pollfunc):
|
||||
while True:
|
||||
time.sleep(1.0)
|
||||
pollfunc()
|
||||
|
||||
|
||||
def main(argv=None):
|
||||
if argv is None:
|
||||
argv = sys.argv
|
||||
|
||||
args = parse_argv(argv[1:])
|
||||
|
||||
opts = {'description': 'simulator'}
|
||||
|
||||
handler_args = {'verbose': args.verbose}
|
||||
srv = Server(int(args.port), Handler, handler_args)
|
||||
module = get_class(args.cls)(args.cls, Logger(), opts, srv)
|
||||
handler_args['module'] = module
|
||||
module.earlyInit()
|
||||
mkthread(poller, module.doPoll)
|
||||
srv.loop()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main(sys.argv))
|
Reference in New Issue
Block a user