cowbird.database.stores

Stores to read/write data to from/to MongoDB using pymongo.

Attributes

LOGGER

Exceptions

MonitorException

Error indicating that a Monitor cannot be started because of an invalid path or callback.

Classes

Monitor

Implementation of the watchdog FileSystemEventHandler class Allows to start/stop directory monitoring and

StoreInterface

Check that the store implementation defines its type and index_fields.

MongodbStore

Base class extended by all concrete store implementations.

MonitoringStore

Registry for monitoring instances.

Module Contents

class cowbird.database.stores.Monitor(path: str, recursive: bool, callback: cowbird.monitoring.fsmonitor.FSMonitor | Type[cowbird.monitoring.fsmonitor.FSMonitor] | str)[source]

Bases: watchdog.events.FileSystemEventHandler

Implementation of the watchdog FileSystemEventHandler class Allows to start/stop directory monitoring and send events to FSMonitor callback.

Initialize the path monitoring and ready to be started.

Parameters:
  • path – Path to monitor

  • recursive – Monitor subdirectory recursively?

  • callback – Events are sent to this FSMonitor. Can be an object, a class type implementing FSMonitor or a string containing module and class name. The class type or string is used to instantiate an object using the class method FSMonitor.get_instance()

static get_fsmonitor_instance(callback: cowbird.monitoring.fsmonitor.FSMonitor | Type[cowbird.monitoring.fsmonitor.FSMonitor] | str) cowbird.monitoring.fsmonitor.FSMonitor[source]

Return a FSMonitor instance from multiple possible forms including the FSMonitor type, the FSMonitor full qualified class name or a direct instance which is returned as is.

static get_qualified_class_name(monitor: cowbird.monitoring.fsmonitor.FSMonitor) str[source]

Returns the full qualified class name of the FSMonitor object (string of the form module.class_name)

property recursive: bool
property path: str
property callback: str
property callback_instance: cowbird.monitoring.fsmonitor.FSMonitor
property key: MonitorKey

Return a dict that can be used as a unique key to identify this Monitor in a BD.

property is_alive: bool

Returns true if the monitor observer exists and is currently running.

params() MonitorParameters[source]

Return a dict serializing this object from which a new Monitor can be recreated using the init function.

start() None[source]

Start the monitoring so that events can be fired.

stop() None[source]

Stop the monitoring so that events stop to be fired.

on_moved(event: watchdog.events.DirMovedEvent | watchdog.events.FileMovedEvent) None[source]

Called when a file or a directory is moved or renamed.

Parameters:

event – Event representing file/directory movement.

on_created(event: watchdog.events.DirCreatedEvent | watchdog.events.FileCreatedEvent) None[source]

Called when a file or directory is created.

Parameters:

event – Event representing file/directory creation.

on_deleted(event: watchdog.events.DirDeletedEvent | watchdog.events.FileDeletedEvent) None[source]

Called when a file or directory is deleted.

Parameters:

event – Event representing file/directory deletion.

on_modified(event: watchdog.events.DirModifiedEvent | watchdog.events.FileModifiedEvent) None[source]

Called when a file or directory is modified.

Parameters:

event – Event representing file/directory modification.

exception cowbird.database.stores.MonitorException[source]

Bases: Exception

Error indicating that a Monitor cannot be started because of an invalid path or callback.

Initialize self. See help(type(self)) for accurate signature.

cowbird.database.stores.LOGGER[source]
class cowbird.database.stores.StoreInterface[source]

Bases: object

Check that the store implementation defines its type and index_fields.

type: str = None[source]
index_fields: List[str] = [][source]
class cowbird.database.stores.MongodbStore(collection: pymongo.collection.Collection, *_: Any, **__: Any)[source]

Base class extended by all concrete store implementations.

Validate and hold the collection for all the implementation.

classmethod get_args_kwargs(*args: Any, **kwargs: Any) Tuple[Tuple[Any, Ellipsis], Dict[str, Any]][source]

Filters MongodbStore-specific arguments to safely pass them down its __init__.

class cowbird.database.stores.MonitoringStore(*args: Any, **kwargs: Any)[source]

Bases: StoreInterface, MongodbStore

Registry for monitoring instances.

Uses MongoDB to store what is monitored and by whom.

Init the store used to save monitors.

type = 'monitors'[source]
index_fields = ['callback', 'path'][source]
save_monitor(monitor: cowbird.monitoring.monitor.Monitor) None[source]

Stores Monitor in MongoDB storage.

delete_monitor(monitor: cowbird.monitoring.monitor.Monitor) None[source]

Removes Monitor from MongoDB storage.

list_monitors() List[cowbird.monitoring.monitor.Monitor][source]

Lists all Monitor in MongoDB storage.

clear_services(drop: bool = True) None[source]

Removes all Monitor from MongoDB storage.