frappy/bin/secop-console
Markus Zolliker 9825b9c135 new generic secop client
new client intended as base class for all clients

- based on Ennos secop client in nicos ([WIP] provide secop client)
- self healing connection singletons
- extension for other than TCP is foreseen (by extending new uri schemes)
- extensible name mangling
- seperate rx and tx threads supporting events
- internal cache
- extensible error handling
- callback for unhandled messages
- callback for descriptive data change
- callback for node stat change (connected, disconnected)
- a short close down and reconnect without change in descriptive data
  does not disturb the client side

works with secop-gui (change follows), planned to be used for Frappy
internal secop proxy and as a replacement for secop.client.baseclient.Client
in the nicos secop device.

-> secop/client/baseclient.py to be removed after planned changes

moved secop/client/__init__.py to secop/client/console.py because secop.client
would be the natural place to put the new base class.

Change-Id: I1a7b1f1ded2221a8f9fcdd52f9cc7414e8fbe035
Reviewed-on: https://forge.frm2.tum.de/review/c/sine2020/secop/playground/+/22218
Tested-by: JenkinsCodeReview <bjoern_pedersen@frm2.tum.de>
Reviewed-by: Markus Zolliker <markus.zolliker@psi.ch>
2020-01-30 08:51:47 +01:00

77 lines
2.5 KiB
Python
Executable File

#!/usr/bin/env python3
# pylint: disable=invalid-name
# -*- coding: utf-8 -*-
# *****************************************************************************
#
# 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:
# Enrico Faulhaber <enrico.faulhaber@frm2.tum.de>
#
# *****************************************************************************
import sys
import argparse
from os import path
# Path magic to make python find our stuff.
# also remember our basepath (for etc, pid lookup, etc)
basepath = path.abspath(path.join(sys.path[0], '..'))
etc_path = path.join(basepath, 'etc')
pid_path = path.join(basepath, 'pid')
log_path = path.join(basepath, 'log')
# sys.path[0] = path.join(basepath, 'src')
sys.path[0] = basepath
# do not move above!
import mlzlog
from secop.client.console import ClientConsole
def parseArgv(argv):
parser = argparse.ArgumentParser(description="Connect to a SECoP server")
loggroup = parser.add_mutually_exclusive_group()
loggroup.add_argument("-v", "--verbose",
help="Output lots of diagnostic information",
action='store_true', default=False)
loggroup.add_argument("-q", "--quiet", help="suppress non-error messages",
action='store_true', default=False)
parser.add_argument("name",
type=str,
help="Name of the instance.\n"
" Uses etc/name.cfg for configuration\n",)
return parser.parse_args()
def main(argv=None):
if argv is None:
argv = sys.argv
args = parseArgv(argv[1:])
loglevel = 'debug' if args.verbose else ('error' if args.quiet else 'info')
mlzlog.initLogging('console', loglevel, log_path)
console = ClientConsole(args.name, basepath)
try:
console.run()
except KeyboardInterrupt:
console.close()
if __name__ == '__main__':
sys.exit(main(sys.argv))