Beispiel #1
0
 def log_setLevel(self, level):
     """ Local override of log_setLevel fo handing the propagation of the
     level setting to the child service objects."""
     Loggable.log_setLevel(self, level)
     for so in [
             o for o in self._objects
             if isinstance(o, Loggable) and o is not self
     ]:
         so.log_setLevel(level)
Beispiel #2
0
    def __init__(self, channel, dao): #pylint: disable=E1002
        """
        :param str channel: the event channel
        """
        super(EventDatabaseObject, self).__init__()

        self._channel = channel
        self._dao = dao

        Loggable.__init__(self, logname='SO:%s' % self._channel)
Beispiel #3
0
    def __init__(self, channel):
        """
        :param str channel: the event channel
        """
        super(EventManagerObject, self).__init__()

        self._emitLock = threading.Lock()
        self._channel = channel

        Loggable.__init__(self, logname='SO:%s' % self._channel)
Beispiel #4
0
    def __init__(self, channel):
        """
        :param str channel: the event channel
        """
        super(EventManagerObject, self).__init__()

        self._emitLock = threading.Lock()
        self._channel = channel

        Loggable.__init__(self, logname='SO:%s' % self._channel)
Beispiel #5
0
    def log_setLevel(self, level):
        """
        Defines the logging level for the container and its service objects.

        :param level: logging level (see module :py:mod:`logging`)
        """
        Loggable.log_setLevel(self, level)
        if self._polling_thread:
            self._polling_thread.log_setLevel(level)
        for haldev in (e.haldev for e in self._devices.itervalues() if isinstance(e.haldev, Loggable)):
            haldev.log_setLevel(self.log_getEffectiveLevel())
Beispiel #6
0
    def __init__(self, owner):
        """
        :param CoordinatorServiceObject owner: the owning coordinator
        """
        threading.Thread.__init__(self)

        self._owner = owner
        self._serial_port = owner.serial_port
        self.name = 'ser-' + owner.coordinator_id
        self._terminate = False

        Loggable.__init__(self, logname='SerRX:%s' % owner.coordinator_id)
Beispiel #7
0
    def __init__(self, owner):
        """
        :param CoordinatorServiceObject owner: the owning coordinator
        """
        threading.Thread.__init__(self)

        self._owner = owner
        self._serial_port = owner.serial_port
        self.name = 'ser-' + owner.coordinator_id
        self._terminate = False

        Loggable.__init__(self, logname='SerRX:%s' % owner.coordinator_id)
Beispiel #8
0
    def log_setLevel(self, level):
        """
        Defines the logging level for the container and its service objects.

        :param level: logging level (see module :py:mod:`logging`)
        """
        Loggable.log_setLevel(self, level)
        if self._polling_thread:
            self._polling_thread.log_setLevel(level)
        for haldev in (e.haldev for e in self._devices.itervalues()
                       if isinstance(e.haldev, Loggable)):
            haldev.log_setLevel(self.log_getEffectiveLevel())
Beispiel #9
0
    def __init__(self, rules=None):
        """ Initializes the rules list by compiling their specifications.

        :param rules: optional rules list
        :raises ValueError: if invalid regex, or if the topic format contains replaceable parameters
            not found in the regex
        """
        Loggable.__init__(self)

        # cache for speeding up computations
        self._cache = {}

        # filtering and transformation transformation rules
        self.rules = rules[:] if rules else []
Beispiel #10
0
    def __init__(self, owner, tasks):
        """
        :param CoordinatorServiceObject owner: the coordinator in charge of the polling tasks
        :param tasks: the list of tasks corresponding to polling actions to be managed
        """
        threading.Thread.__init__(self)

        self._owner = owner
        self._tasks = tasks
        self._terminate = False
        self._task_trigger_checking_period = self.DFLT_TASK_CHECKING_PERIOD
        self._stats_file_path = self.STATS_STORAGE_PATH % self._owner.coordinator_id

        Loggable.__init__(self, logname='Poll:%s' % self._owner.coordinator_id)
Beispiel #11
0
    def __init__(self, cid):
        """
        :param str cid: coordinator id
        """
        dbus.service.Object.__init__(self)
        self._cid = cid
        self._cfg = None
        self._evtmgr = None
        self._polling_thread = None
        self._poll_req_interval = None
        self._devices = {}
        self._error_count = 0

        Loggable.__init__(self, logname='%s' % str(self))
Beispiel #12
0
    def __init__(self, cid):
        """
        :param str cid: coordinator id
        """
        dbus.service.Object.__init__(self)
        self._cid = cid
        self._cfg = None
        self._evtmgr = None
        self._polling_thread = None
        self._poll_req_interval = None
        self._devices = {}
        self._error_count = 0

        Loggable.__init__(self, logname='%s' % str(self))
Beispiel #13
0
    def __init__(self, owner, tasks):
        """
        :param CoordinatorServiceObject owner: the coordinator in charge of the polling tasks
        :param tasks: the list of tasks corresponding to polling actions to be managed
        """
        threading.Thread.__init__(self)

        self._owner = owner
        self._tasks = tasks
        self._terminate = False
        self._task_trigger_checking_period = self.DFLT_TASK_CHECKING_PERIOD
        self._stats_file_path = self.STATS_STORAGE_PATH % self._owner.coordinator_id

        Loggable.__init__(self, logname='Poll:%s' % self._owner.coordinator_id)
Beispiel #14
0
    def __init__(self, rules=None):
        """ Initializes the rules list by compiling their specifications.

        :param rules: optional rules list
        :raises ValueError: if invalid regex, or if the topic format contains replaceable parameters
            not found in the regex
        """
        Loggable.__init__(self)

        # cache for speeding up computations
        self._cache = {}

        # filtering and transformation transformation rules
        self.rules = rules[:] if rules else []
Beispiel #15
0
    def __init__(self, cfg):
        """
        The service object is configured based on the content of the configuration data, provided as
        a dictionary by the process which instantiates it.

        See :py:meth:`configure` method documentation for specifications of the configuration data.

        Note that providing no filter at all is invalid, since it would make the gateway useless.

        :param dict cfg: the configuration data
        :raises ValueError: if both filters are unset
        """
        super(MQTTGatewayServiceObject, self).__init__()
        Loggable.__init__(self, logname='SO')

        self._lock = threading.Lock()

        self.configure(cfg, self.logger)
Beispiel #16
0
    def __init__(self, name, conn=None, svc_objects=None, auto_fw_object=True):
        """
        :param str name:
            the container's name. It is used to build the well-known name which will
            be claimed (see pycstbox.commons.make_bus_name())

        :param dbus_connection conn:
            the connection to the bus used by the service.
            Set to the session bus if not provided.

        :param list svc_objects:
            an optional list of service objects, which will be automatically added to
            the container during its initialization. The items of this list are tuples
            containing the service object instance and the path to be associated for it

        :param bool auto_fw_object:
            if True (the default) a service object implementing framework level functions
            is automatically created and added. If False, it is the responsibility of
            the application to provide it and adding it if framework level functions are
            required.
        """
        self._name = name
        self._conn = conn if conn else dbus.SessionBus()
        self._objects = []

        # claim our "well known" name on the conn
        self._wkn = dbus.service.BusName(dbuslib.make_bus_name(name),
                                         self._conn)

        self._loop = None
        self._terminate_lock = threading.Lock()

        Loggable.__init__(self, logname='SC:%s' % self._name)

        # adds a service controller object if asked for
        if auto_fw_object:
            fwobj = _FrameworkServiceObject(self)
            self.add(fwobj, SYSTEM_OBJECT_PATH)

        # add provided service objects
        self.add_objects(svc_objects)
Beispiel #17
0
    def __init__(self, port, unit_id, logname, retries=DEFAULT_RETRIES):
        """
        :param str port: serial port on which the RS485 interface is connected
        :param int unit_id: the address of the device
        :param str logname: the (short) root for the name of the log
        :param int retries: number of retries in case of communication errors
        """
        super(RTUModbusHWDevice, self).__init__(port=port, slaveaddress=int(unit_id))

        self._first_poll = True
        self.poll_req_interval = 0
        self.retries = retries
        self.terminate = False
        self.communication_error = False

        self.total_reads = 0
        self.total_errors = 0

        Loggable.__init__(self, logname='%s-%03d' % (logname, self.unit_id))

        self.log_info('created %s instance with unit id=%d on port %s', self.__class__.__name__, unit_id, port)
Beispiel #18
0
    def __init__(self, name, conn=None, svc_objects=None, auto_fw_object=True):
        """
        :param str name:
            the container's name. It is used to build the well-known name which will
            be claimed (see pycstbox.commons.make_bus_name())

        :param dbus_connection conn:
            the connection to the bus used by the service.
            Set to the session bus if not provided.

        :param list svc_objects:
            an optional list of service objects, which will be automatically added to
            the container during its initialization. The items of this list are tuples
            containing the service object instance and the path to be associated for it

        :param bool auto_fw_object:
            if True (the default) a service object implementing framework level functions
            is automatically created and added. If False, it is the responsibility of
            the application to provide it and adding it if framework level functions are
            required.
        """
        self._name = name
        self._conn = conn if conn else dbus.SessionBus()
        self._objects = []

        # claim our "well known" name on the conn
        self._wkn = dbus.service.BusName(dbuslib.make_bus_name(name), self._conn)

        self._loop = None
        self._terminate_lock = threading.Lock()

        Loggable.__init__(self, logname='SC:%s' % self._name)

        # adds a service controller object if asked for
        if auto_fw_object:
            fwobj = _FrameworkServiceObject(self)
            self.add(fwobj, SYSTEM_OBJECT_PATH)

        # add provided service objects
        self.add_objects(svc_objects)
Beispiel #19
0
    def __init__(self, rules=None):
        """ Initializes the rules list by compiling their specifications.

        The specifications are provided as an iterable of 3 parts tuples, which items are :

            - a string containing the regex to be applied to fully qualified variable names,
            which can contain capture groups intended to be used for the topic string expansion
            - the MQTT topic string (or topic format string) to be used for publication
            - the callable used to build the MQTT message payload

        :param rules: an iterable of tuples, as described above
        :param logger: optional logging object
        :raises ValueError: if invalid regex, or if the topic format contains replaceable parameters
            not found in the regex
        """
        Loggable.__init__(self)

        # cache for speeding up computations
        self._cache = {}

        # filtering and  transformation rules
        self.rules = rules or []
Beispiel #20
0
    def __init__(self, rules=None):
        """ Initializes the rules list by compiling their specifications.

        The specifications are provided as an iterable of 3 parts tuples, which items are :

            - a string containing the regex to be applied to fully qualified variable names,
            which can contain capture groups intended to be used for the topic string expansion
            - the MQTT topic string (or topic format string) to be used for publication
            - the callable used to build the MQTT message payload

        :param rules: an iterable of tuples, as described above
        :param logger: optional logging object
        :raises ValueError: if invalid regex, or if the topic format contains replaceable parameters
            not found in the regex
        """
        Loggable.__init__(self)

        # cache for speeding up computations
        self._cache = {}

        # filtering and  transformation rules
        self.rules = rules or []
Beispiel #21
0
    def __init__(self, jobname, jobid, parms, logger=None):
        """
        :param str jobname: job name (should be unique across the application)
        :param str jobid: the job id.
            Must be unique and allow sorting a job list and reflect their chronology
        :param parms: the execution parameters
        :param logger: (optional) message logger
        :raises ValueError: if mandatory parameters are not all non empty
        """
        if not jobname or not jobid or parms is None:
            raise ValueError("missing mandatory parameter")

        self._name = jobname

        Loggable.__init__(self, logname=jobname)

        self._id = jobid
        self._parms = parms

        self._error = None

        self.log_info('- job %s:%s created :', jobname, jobid)
        self.log_info('  + parameters : %s', self._format_parms())
Beispiel #22
0
    def __init__(self, jobname, jobid, parms, logger=None):
        """
        :param str jobname: job name (should be unique across the application)
        :param str jobid: the job id.
            Must be unique and allow sorting a job list and reflect their chronology
        :param parms: the execution parameters
        :param logger: (optional) message logger
        :raises ValueError: if mandatory parameters are not all non empty
        """
        if not jobname or not jobid or parms is None:
            raise ValueError("missing mandatory parameter")

        self._name = jobname

        Loggable.__init__(self, logname=jobname)

        self._id = jobid
        self._parms = parms

        self._error = None

        self.log_info('- job %s:%s created :', jobname, jobid)
        self.log_info('  + parameters : %s', self._format_parms())
Beispiel #23
0
 def __init__(self):
     Loggable.__init__(self, logname='evt-expproc')
     self._failed_jobs = {}
Beispiel #24
0
 def log_setLevel(self, level):
     """ Local override of log_setLevel fo handing the propagation of the
     level setting to the child service objects."""
     Loggable.log_setLevel(self, level)
     for so in [o for o in self._objects if isinstance(o, Loggable) and o is not self]:
         so.log_setLevel(level)
Beispiel #25
0
 def __init__(self, logger, *args, **kwargs):
     Loggable.__init__(self, logger)
     self.log_warning('using a simulated connector')
     mqtt_client.Client.__init__(self, *args, **kwargs)
Beispiel #26
0
 def __init__(self, port, unit_id):
     self._first_poll = True
     self.url = port
     self.address = int(unit_id)
     Loggable.__init__(self, logname='zwave%03d' % self.address)
Beispiel #27
0
 def __init__(self):
     Loggable.__init__(self, logname='cfg-proc')
     self.data = None
Beispiel #28
0
 def __init__(self, *args, **kwargs):
     unittest.TestCase.__init__(self, *args, **kwargs)
     Loggable.__init__(self)
Beispiel #29
0
 def __init__(self):
     Loggable.__init__(self, logname='cfg-expproc')
Beispiel #30
0
 def __init__(self, logger, *args, **kwargs):
     Loggable.__init__(self, logger)
     self.log_warning('using a simulated connector')
     mqtt_client.Client.__init__(self, *args, **kwargs)