evennia.scripts.monitorhandler

Monitors - catch changes to model fields and Attributes.

The MONITOR_HANDLER singleton from this module offers the following functionality:

  • Field-monitor - track a object’s specific database field and perform

    an action whenever that field changes for whatever reason.

  • Attribute-monitor tracks an object’s specific Attribute and perform

    an action whenever that Attribute changes for whatever reason.

class evennia.scripts.monitorhandler.MonitorHandler[源代码]

基类:object

This is a resource singleton that allows for registering callbacks for when a field or Attribute is updated (saved).

__init__()[源代码]

Initialize the handler.

save()[源代码]

Store our monitors to the database. This is called by the server process.

Since dbserialize can’t handle defaultdicts, we convert to an intermediary save format ((obj,fieldname, idstring, callback, kwargs), …)

restore(server_reload=True)[源代码]

Restore our monitors after a reload. This is called by the server process.

参数

server_reload (bool, optional) – If this is False, it means the server went through a cold reboot and all non-persistent tickers must be killed.

at_update(obj, fieldname)[源代码]

Called by the field/attribute as it saves.

add(obj, fieldname, callback, idstring='', persistent=False, category=None, **kwargs)[源代码]

Add monitoring to a given field or Attribute. A field must be specified with the full db_* name or it will be assumed to be an Attribute (so db_key, not just key).

参数
  • obj (Typeclassed Entity) – The entity on which to monitor a field or Attribute.

  • fieldname (str) – Name of field (db_*) or Attribute to monitor.

  • callback (callable) – A callable on the form **callable(**kwargs), where kwargs holds keys fieldname and obj.

  • idstring (str, optional) – An id to separate this monitor from other monitors of the same field and object.

  • persistent (bool, optional) – If False, the monitor will survive a server reload but not a cold restart. This is default.

  • category (str, optional) – This is only used if fieldname refers to an Attribute (i.e. it does not start with db_). You must specify this if you want to target an Attribute with a category.

关键字参数
  • session (Session) – If this keyword is given, the monitorhandler will correctly analyze it and remove the monitor if after a reload/reboot the session is no longer valid.

  • any (any) – Any other kwargs are passed on to the callback. Remember that all kwargs must be possible to pickle!

remove(obj, fieldname, idstring='', category=None)[源代码]

Remove a monitor.

clear()[源代码]

Delete all monitors.

all(obj=None)[源代码]

List all monitors or all monitors of a given object.

参数

obj (Object) – The object on which to list all monitors.

返回

monitors (list) – The handled monitors.