datalogd package

The datalogd package contains the main DataLogDaemon, plus the plugin base classes DataSource, DataFilter, and DataSink, which must be extended to provide useful functionality.

The included data source/filter/sink plugins are contained separately in the plugins package.

class datalogd.DataFilter(sinks=[])[source]

Bases: datalogd.DataSource, datalogd.DataSink, pluginlib._parent.Plugin

The base class for all data filter plugins.

DataFilters are subclasses of both DataSources and DataSinks, thus are capable of both sending and receiving data. Typically, they are used to sit between a DataSource and a DataSink (or other DataFilters) in order to modify the data flowing between them in some way.

class datalogd.DataLogDaemon(configfile=None, plugindirs=[], graph_dot=None)[source]

Bases: object

The main datalogd class.

The DataLogDaemon reads configuration file(s), interprets the connection graph DOT specification, and initialises data source/filter/sink plugins and connections. The asyncio event loop must be started separately. For an example of this, see the main() method, which is the typical way the daemon is started.

Parameters:
  • configfile – Path to configuration file to load.
  • plugindirs – Directory, or list of directories from which to load additional plugins.
  • graph_dot – Connection graph specified in the DOT graph description language.
close()[source]

Notify nodes that the application is closing so they may shutdown gracefully.

class datalogd.DataSink[source]

Bases: pluginlib._parent.Plugin

The base class for all data sink plugins.

DataSinks have a receive() method which accepts data from connected DataSources.

close()[source]

Perform any cleanup required during application shutdown.

receive(data)[source]

Accept the provided data.

Parameters:data – Data received by this sink.
class datalogd.DataSource(sinks=[])[source]

Bases: pluginlib._parent.Plugin

The base class for all data sink plugins.

DataSource implements methods for connecting or disconnecting sinks, and for sending data to connected sinks. It has no intrinsic functionality (it does not actually produce any data) and is not itself considered a plugin, so can’t be instantiated using the connection graph.

Parameters:sinksDataSink or list of DataSinks to receive data produced by this DataSource.
close()[source]

Perform any cleanup required during application shutdown.

connect_sinks(sinks)[source]

Register the provided DataSink as a receiver of data produced by this DataSource. A list of sinks may also be provided.

Parameters:sinksDataSink or list of DataSinks.
disconnect_sinks(sinks)[source]

Unregister the provided DataSink so that it no longer receives data produced by this DataSource. A list of sinks may also be provided. It is not an error to provide a sink that is not currently connected.

Parameters:sinksDataSink or list of DataSinks.
send(data)[source]

Send the provided data to all connected DataSinks.

Parameters:data – Data to send to DataSinks.
class datalogd.NullDataFilter(sinks=[])[source]

Bases: datalogd.DataFilter

A DataFilter which accepts data and passes it unchanged to any connected DataSinks.

receive(data)[source]

Pass data unchanged to all connected DataSinks.

Parameters:data – Data received by this filter.
class datalogd.NullDataSink[source]

Bases: datalogd.DataSink

A DataSink which accepts data and does nothing with it.

Unlike the base DataSink, this can be instantiated using the connection graph, although it provides no additional functionality.

class datalogd.NullDataSource(sinks=[])[source]

Bases: datalogd.DataSource

A DataSource which produces no data.

Unlike the base DataSource, this can be instantiated using the connection graph, although it provides no additional functionality.

datalogd.listify(value)[source]

Convert value into a list.

Modifies the behaviour of the python builtin list() by accepting all types as value, not just iterables. Additionally, the behaviour of iterables is changed:

  • list('str') == ['s', 't', 'r'], while listify('str') == ['str']
  • list({'key': 'value'}) == ['key'], while listify({'key': 'value'}) == [{'key': 'value'}]
Parameters:value – Input value to convert to a list.
Returns:value as a list.
datalogd.main()[source]

Read command line parameters, instantiate a new DataLogDaemon and begin execution of the event loop.

datalogd.parse_dot_json(value)[source]

Interpret the value of a DOT attribute as JSON data.

DOT syntax requires double quotes around values which contain DOT punctuation (space, comma, {}, [] etc), and, if used, these quotes will also be present in the obtained value string. Unfortunately, JSON also uses double quotes for string values, which are then in conflict. This method will strip any double quotes from the passed value, then will attempt to interpret as JSON after replacing single quotes with double quotes.

Note that the use of this workaround means that single quotes must be used in any JSON data contained in the DOT attribute values.

Although not strictly correct JSON, some special values will be interpreted as their python equivalents. These are:

  • None or null (with any capitalisation) will be read as a python None.
  • True (with any capitalisation) will be read as a python True.
  • False (with any capitalisation) will be read as a python False.
  • NotImplemented (with any capitalisation) will be read as a python NotImplemented.
  • NaN (with any capitalisation) will be read as the python float nan.
  • Inf or Infinity (with any capitalisation) will be read as the python float inf.
  • -Inf or -Infinity (with any capitalisation) will be read as the python float -inf.
Parameters:value – string to interpret.
Returns:value, possibly as a new type.