manager Module

Manager Class

class tallypi.manager.Manager(config_filename: Optional[pathlib.Path] = PosixPath('/home/docs/.config/tallypi.yaml'), readonly: Optional[bool] = False)[source]

Bases: object

Manager for tally inputs and outputs

inputs: tallypi.manager.Inputs

All configured inputs

outputs: tallypi.manager.Outputs

All configured outputs

config: tallypi.config.Config

Configuration storage

config_write_evt: asyncio.locks.Event

An asyncio.events.Event that is set when config changes are written

readonly_override: tallypi.manager.ReadonlyOverride

A context manager that can temporarily disable readonly mode

For details, see the ReadonlyOverride class

property readonly

If True config changes are not written to disk (unless overridden)

This is the immutable “readonly” state

async open()[source]

Opens all inputs and outputs

Reads configuration data if necessary with a call to read_config(), then calls open() on the inputs and outputs

async close()[source]

Closes all inputs and outputs

async add_input(obj: tallypi.common.BaseInput)[source]

Add an input

Shortcut for calling IOContainer.add() on inputs

async add_output(obj: tallypi.common.BaseOutput)[source]

Add an input

Shortcut for calling IOContainer.add() on outputs

async read_config()[source]

Read configuration stored in config and deserialize() the inputs and outputs

async write_config()[source]

Write the current configuration to config using serialize() on inputs and outputs

class tallypi.manager.ReadonlyOverride(config_write_evt: asyncio.locks.Event)[source]

Bases: object

An asynchronous context manager used to override the readonly mode of Manager

While the context is acquired, the Manager is temporarily allowed to write config changes. The config_write_evt event is returned so it will be available as the as clause of the async with statement:

async with manager.readonly_override as config_write_evt:
    await manager.remove_input('foo')
    await config_write_evt.wait()

This allows code to await for config changes to be written before exiting the async with context.

config_write_evt: asyncio.locks.Event

Alias for Manager.config_write_evt

override: bool

True if currently being overridden

state_lock: asyncio.locks.Lock

A lock used while changing states

(during acquire() and release() stages)

locked()[source]

True if the context is acquired or if state_lock is locked

async acquire()[source]

Acquire the context and set override to True

Also clears config_write_evt so it can be awaited

async release()[source]

Set override to False and exit the context

Container Classes

class tallypi.manager.IOContainer(*args, **kwargs)[source]

Bases: pydispatch.dispatch.Dispatcher

Container for BaseIO instances

Events
object_added(key: str, obj: tallypi.common.BaseIO)

Fired when an instance is added by either deserialize() or add()

object_removed(key: str, obj: tallypi.common.BaseIO)

Fired when an instance has been removed

update()

Fired when any change happens that requires a config update

async open()[source]

Call the open() method on all instances

async close()[source]

Call the close() method on all instances

async add(obj: tallypi.common.BaseIO, key: Optional[str] = None)[source]

Add an instance to the container

Parameters
  • obj (BaseIO) – The instance to add

  • key (str, optional) – The key for the instance. If not given, one will be created by key_for_object()

async replace(key: str, obj: tallypi.common.BaseIO)[source]

Replace an instance by the given key

async remove(key: str)[source]

Remove an instance by the given key

key_for_object(obj: tallypi.common.BaseIO)[source]

Create a unique key based on the class namespace

async deserialize(data: Dict)[source]

Deserialize instances from config data using common.BaseIO.deserialize()

serialize()Dict[source]

Serialize instances to store in the config using common.BaseIO.serialize()

class tallypi.manager.Inputs(*args, **kwargs)[source]

Bases: tallypi.manager.IOContainer

Container for BaseInput instances

Events
on_tally_added(tally: tslumd.tallyobj.Tally)

Fired when the common.BaseInput.on_tally_added event received from any of the inputs in the container

on_tally_updated(tally: tslumd.tallyobj.Tally)

Fired when the common.BaseInput.on_tally_updated event received from any of the inputs in the container

async add(obj: tallypi.common.BaseInput, key: Optional[str] = None)[source]

Add an instance to the container

Parameters
  • obj (BaseIO) – The instance to add

  • key (str, optional) – The key for the instance. If not given, one will be created by key_for_object()

async deserialize(data: Dict)[source]

Deserialize instances from config data using common.BaseIO.deserialize()

class tallypi.manager.Outputs(*args, **kwargs)[source]

Bases: tallypi.manager.IOContainer

Container for BaseOutput instances

async bind_all_to_input(inp: tallypi.common.BaseInput)[source]

Attach all outputs to the given input

Calls common.BaseOutput.bind_to_input() for each output instance