cowbird.handlers.impl.catalog

Attributes

HANDLER_URL_PARAM

HANDLER_WORKSPACE_DIR_PARAM

AnyHandlerParameter

SettingsType

LOGGER

Classes

Handler

Helper class that provides a standard way to create an ABC using

FSMonitor

Interface being called when something changes on the filesystem.

Monitoring

Class handling file system monitoring and registering listeners.

Permission

Define every property required to set a permission in Magpie.

Catalog

Keep the catalog index in sync when files are created/deleted/updated.

Functions

get_logger(→ logging.Logger)

Immediately sets the logger level to avoid duplicate log outputs from the root logger and this logger when

Module Contents

cowbird.handlers.impl.catalog.HANDLER_URL_PARAM: AnyHandlerParameter = 'url'[source]
cowbird.handlers.impl.catalog.HANDLER_WORKSPACE_DIR_PARAM: AnyHandlerParameter = 'workspace_dir'[source]
cowbird.handlers.impl.catalog.AnyHandlerParameter[source]
class cowbird.handlers.impl.catalog.Handler(settings: cowbird.typedefs.SettingsType, name: str, **kwargs: Any)[source]

Bases: abc.ABC

Helper class that provides a standard way to create an ABC using inheritance.

Parameters:
  • settings – Cowbird settings for convenience

  • name – Handler name

  • kwargs – The base class handle, but doesn’t require the following variables:

  • url – Location of the web service represented by the cowbird handler

  • workspace_dir – Workspace directory

  • priority – Relative priority between handlers while handling events. Lower value has higher priority, default value is last.

__slots__

Handler interface used to notify implemented handlers of users/permissions changes.

Todo

At some point we will need a consistency function that goes through all Magpie users and make sure that handlers are up-to-date.

property required_params: List[AnyHandlerParameter]
Abstractmethod:

json() cowbird.typedefs.JSON[source]
_user_workspace_dir(user_name: str) str[source]
abstract user_created(user_name: str) None[source]
abstract user_deleted(user_name: str) None[source]
abstract permission_created(permission: cowbird.permissions_synchronizer.Permission) None[source]
abstract permission_deleted(permission: cowbird.permissions_synchronizer.Permission) None[source]
abstract resync() None[source]
class cowbird.handlers.impl.catalog.FSMonitor[source]

Bases: abc.ABC

Interface being called when something changes on the filesystem.

static get_instance() FSMonitor | None[source]
Abstractmethod:

Must return an instance of the class implementing FSMonitor.

abstract on_created(path: str) None[source]

Called when a new path is found.

Parameters:

path – Absolute path of a new file/directory

abstract on_deleted(path: str) None[source]

Called when a path is deleted.

Parameters:

path – Absolute path of a new file/directory

abstract on_modified(path: str) None[source]

Called when a path is updated.

Parameters:

path – Absolute path of a new file/directory

class cowbird.handlers.impl.catalog.Monitoring(config: cowbird.typedefs.AnySettingsContainer = None)[source]

Class handling file system monitoring and registering listeners.

Todo

At some point we will need a consistency function that goes through all monitored folder and make sure that monitoring handlers are up to date.

Initialize the monitoring instance from configured application settings.

Parameters:

config – AnySettingsContainer object from which the db can be retrieved. The default value of None is only there to disable pylint E1120. The singleton instance must be initialized with a proper config and after that the init function should not be hit.

start() None[source]

Load existing monitors and start the monitoring.

register(path: str, recursive: bool, cb_monitor: cowbird.monitoring.fsmonitor.FSMonitor | Type[cowbird.monitoring.fsmonitor.FSMonitor] | str) cowbird.monitoring.monitor.Monitor | None[source]

Register a monitor for a specific path and start it. If a monitor already exists for the specific path/cb_monitor combination it is directly returned. If this monitor was not recursively monitoring its path and the recursive flag is now true, this one take precedence and the monitor is updated accordingly. If the recursive flag was true, and now it is false it has no effect.

Parameters:
  • path – Path to monitor

  • recursive – Monitor subdirectory recursively?

  • cb_monitor – FSMonitor for which an instance is created and events are sent Can be an object, a class type implementing FSMonitor or a string containing module and class name.

Returns:

The monitor registered or already existing for the specific path/cb_monitor combination. Note that the monitor is not created/returned if a MonitorException occurs.

unregister(path: str, cb_monitor: cowbird.monitoring.fsmonitor.FSMonitor | Type[cowbird.monitoring.fsmonitor.FSMonitor] | str) bool[source]

Stop a monitor and unregister it.

Parameters:
  • path – Path used by the monitor

  • cb_monitor – FSMonitor object to remove Can be an object, a class type implementing FSMonitor or a string containing module and class name.

Returns:

True if the monitor is found and successfully stopped, False otherwise

unregister_all() None[source]

Stops and unregisters all monitors.

class cowbird.handlers.impl.catalog.Permission(service_name: str, service_type: str, resource_id: int, resource_full_name: str, name: str, access: str, scope: str, user: str = None, group: str = None, resource_display_name: str = None)[source]

Define every property required to set a permission in Magpie.

__eq__(other: Permission) bool[source]

Return self==value.

get_full_permission_value() str[source]

Returns the full permission value, consisting of the name-access-scope values.

cowbird.handlers.impl.catalog.SettingsType[source]
cowbird.handlers.impl.catalog.get_logger(name: str, level: int | None = None, force_stdout: bool = None, message_format: str | None = None, datetime_format: str | None = None) logging.Logger[source]

Immediately sets the logger level to avoid duplicate log outputs from the root logger and this logger when level is logging.NOTSET.

cowbird.handlers.impl.catalog.LOGGER[source]
class cowbird.handlers.impl.catalog.Catalog(settings: cowbird.typedefs.SettingsType, name: str, **kwargs: Any)[source]

Bases: cowbird.handlers.handler.Handler, cowbird.monitoring.fsmonitor.FSMonitor

Keep the catalog index in sync when files are created/deleted/updated.

Create the catalog instance.

Parameters:
  • settings – Cowbird settings for convenience

  • name – Handler name

required_params: List[cowbird.handlers.handler.AnyHandlerParameter][source]
user_created(user_name: str) None[source]
user_deleted(user_name: str) None[source]
abstract permission_created(permission: cowbird.permissions_synchronizer.Permission) None[source]
abstract permission_deleted(permission: cowbird.permissions_synchronizer.Permission) None[source]
static get_instance() Catalog | None[source]

Return the Catalog singleton instance from the class name used to retrieve the FSMonitor from the DB.

on_created(path: str) None[source]

Called when a new path is found.

Parameters:

path – Absolute path of a new file/directory

on_deleted(path: str) None[source]

Called when a path is deleted.

Parameters:

path – Absolute path of a new file/directory

on_modified(path: str) None[source]

Called when a path is updated.

Parameters:

path – Absolute path of a new file/directory

abstract resync() None[source]