runtime/__init__.py
author Edouard Tisserant
Tue, 23 Oct 2018 16:19:20 +0200
changeset 2323 33a0dbabccd3
parent 2309 d8fb90a2e11f
child 2327 569d7fbc0bd4
permissions -rw-r--r--
Runtime : Ensure that a random PSK secret compatible with stunnel is generated if -s commandline switch is used. Stunnel service is restarted after generation, using spawn_subprocess. TODO : give stunnel restart command as a commandline parameter.
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import absolute_import
from __future__ import print_function
import traceback
import sys

from runtime.Worker import worker
MainWorker = worker()

from runtime.PLCObject import PLCObject  # noqa # pylint: disable=wrong-import-position


_PLCObjectSingleton = None


def GetPLCObjectSingleton():
    assert _PLCObjectSingleton is not None
    return _PLCObjectSingleton


def LogMessageAndException(msg, exp=None):
    if exp is None:
        exp = sys.exc_info()
    if _PLCObjectSingleton is not None:
        _PLCObjectSingleton.LogMessage(0, msg + '\n'.join(traceback.format_exception(*exp)))
    print(msg)
    traceback.print_exception(*exp)


def CreatePLCObjectSingleton(*args, **kwargs):
    global _PLCObjectSingleton
    _PLCObjectSingleton = PLCObject(*args, **kwargs)