migrated secop_psi drivers to new syntax

- includes all changes up to 'fix inheritance order' from git_mlz
  6a32ecf342

Change-Id: Ie3ceee3dbd0a9284b47b1d5b5dbe262eebe8f283
This commit is contained in:
2021-02-24 16:15:23 +01:00
parent bc5edec06f
commit 41baf5805f
79 changed files with 2610 additions and 3952 deletions

View File

@ -23,13 +23,17 @@
# *****************************************************************************
"""Define helpers"""
import os
from os.path import join, exists, dirname, isdir
import ast
import time
import threading
import configparser
import os
import threading
import time
from collections import OrderedDict
from secop.errors import ConfigError
from secop.lib import formatException, get_class, getGeneralConfig
from secop.modules import Attached
try:
from daemon import DaemonContext
try:
@ -39,10 +43,6 @@ try:
except ImportError:
DaemonContext = None
from secop.errors import ConfigError
from secop.lib import formatException, get_class, getGeneralConfig
from secop.modules import Attached
from secop.params import PREDEFINED_ACCESSIBLES
try:
import systemd.daemon
@ -95,7 +95,11 @@ class Server:
merged_cfg = OrderedDict()
ambiguous_sections = set()
for cfgfile in cfgfiles.split(','):
cfgdict = self.loadCfgFile(cfgfile)
if cfgfile.endswith('.cfg') and os.path.exists(cfgfile):
filename = cfgfile
else:
filename = os.path.join(cfg['confdir'], cfgfile + '.cfg')
cfgdict = self.loadCfgFile(filename)
ambiguous_sections |= set(merged_cfg) & set(cfgdict)
merged_cfg.update(cfgdict)
self.node_cfg = merged_cfg.pop('NODE', {})
@ -112,22 +116,9 @@ class Server:
if ambiguous_sections:
self.log.warning('ambiguous sections in %s: %r' % (cfgfiles, tuple(ambiguous_sections)))
self._cfgfiles = cfgfiles
self._pidfile = join(cfg['piddir'], name + '.pid')
self._pidfile = os.path.join(cfg['piddir'], name + '.pid')
def loadCfgFile(self, cfgfile):
if not cfgfile.endswith('.cfg'):
cfgfile += '.cfg'
if '/' in cfgfile: # specified as full path
filename = cfgfile if exists(cfgfile) else None
else:
cfg = getGeneralConfig()
for filename in [join(d, cfgfile) for d in cfg['confdir'].split(':')]:
if exists(filename):
break
else:
filename = None
if filename is None:
raise ConfigError("Couldn't find cfg file %r in %s" % (cfgfile, cfg['confdir']))
def loadCfgFile(self, filename):
self.log.debug('Parse config file %s ...' % filename)
result = OrderedDict()
parser = configparser.ConfigParser()
@ -165,8 +156,8 @@ class Server:
def start(self):
if not DaemonContext:
raise ConfigError('can not daemonize, as python-daemon is not installed')
piddir = dirname(self._pidfile)
if not isdir(piddir):
piddir = os.path.dirname(self._pidfile)
if not os.path.isdir(piddir):
os.makedirs(piddir)
pidfile = pidlockfile.TimeoutPIDLockFile(self._pidfile)
@ -238,7 +229,7 @@ class Server:
# all objs created, now start them up and interconnect
for modname, modobj in self.modules.items():
self.log.info('registering module %r' % modname)
self.dispatcher.register_module(modobj, modname, modobj.properties['export'])
self.dispatcher.register_module(modobj, modname, modobj.export)
if modobj.pollerClass is not None:
# a module might be explicitly excluded from polling by setting pollerClass to None
modobj.pollerClass.add_to_table(poll_table, modobj)
@ -247,14 +238,16 @@ class Server:
# handle attached modules
for modname, modobj in self.modules.items():
for propname, propobj in modobj.__class__.properties.items():
for propname, propobj in modobj.propertyDict.items():
if isinstance(propobj, Attached):
setattr(modobj, propobj.attrname or '_' + propname,
self.dispatcher.get_module(modobj.properties[propname]))
self.dispatcher.get_module(getattr(modobj, propname)))
# call init on each module after registering all
for modname, modobj in self.modules.items():
modobj.initModule()
if self._testonly:
return
start_events = []
for modname, modobj in self.modules.items():
event = threading.Event()
@ -271,10 +264,3 @@ class Server:
if not event.wait(timeout=max(0, deadline - time.time())):
self.log.info('WARNING: timeout when starting %s' % name)
self.log.info('all modules and pollers started')
history_path = os.environ.get('FRAPPY_HISTORY')
if history_path:
from secop.histwriter import HistWriter
writer = HistWriter(history_path, PREDEFINED_ACCESSIBLES.keys(), self.dispatcher)
# treat writer as a connection
self.dispatcher.add_connection(writer)
writer.init(self.dispatcher.handle_describe(writer, None, None))