Masterpiece Plugin

Description

A simple demonstration plugin designed to extend masterpiece applications.

class masterpiece_plugin.HelloWorld(name='noname', description='hello')[source]

Bases: Plugin

An object with a description.

classmethod classattrs_from_dict(attributes)

Set class attributes from a dictionary.

Return type:

None

classmethod classattrs_to_dict()

Convert class attributes to a dictionary.

Return type:

dict

copy()

Create and return a copy of the current object.

This method serializes the current object to a dictionary using the to_dict method, creates a new instance of the object’s class, and populates it with the serialized data using the from_dict method.

This method uses class identifier based instantiation (see factory method pattern) to create a new instance of the object, and ‘to_dict’ and ‘from_dict’ methods to initialize object’s state.

Return type:

MasterPiece

Returns:

A new instance of the object’s class with the same state as the original object.

Example:

clone_of_john = john.copy()
debug(msg, details='')

Logs the given debug message to the application log.

Parameters:
  • msg (str) – The information message to be logged.

  • details (str) – Additional detailed information for the message to be logged

Return type:

None

do(action, context)

Execute the given action to the object, by calling the provided action.

Parameters:
  • action (Callable[["MasterPiece", Dict[str, Any]], bool]) – A callable that takes

  • (node

  • boolean. (context) and returns a)

  • context (Dict[str, Any]) – Any context data that the action may use.

Return type:

bool

Returns:

The return value from the executed action.

error(msg, details='')

Logs the given error message to the application log.

Parameters:
  • msg (str) – The message to be logged.

  • details (str) – Additional detailed information for the message to be logged

Return type:

None

classmethod factory()

Fetch the dictionary holding class names and associated classes.

Returns:

with class names and associated classes

Return type:

factory

classmethod find_class(class_id)

Create an instance of the class corresponding to the given class identifier.

Parameters:
  • class_id (str) – Identifier of the class to instantiate.

  • *args – Optional arguments to pass to the class constructor.

Returns:

An instance of the class corresponding to the given class identifier.

Return type:

MasterPiece

from_dict(data)[source]

Update instance attributes from a dictionary.

classmethod get_class_id()

Return the class id of the class. Each class has an unique name that can be used for instantiating the class via Object.instantiate() method.

Parameters:

cls (class) – class

Returns:

unique class identifier through which the class can be instantiated by factory method pattern.

Return type:

id (str)

classmethod has_class_method_directly(method_name)

Check if the method is defined directly in the class (not inherited).

Return type:

bool

info(msg, details='')

Logs the given information message to the application log.

Parameters:
  • msg (str) – The information message to be logged.

  • details (str) – Additional detailed information for the message to be logged

Return type:

None

classmethod init_class(clazz)

Initialize class. Updates the class factory and sets up exit hook to create class configuration file on program exit.

Parameters:

clazz (class) – class to be initialized

Return type:

None

install(app)[source]
Return type:

None

classmethod instantiate(class_id, *args)

Create an instance of the class corresponding to the given class identifier.

Parameters:
  • class_id (str) – Identifier of the class to instantiate.

  • *args (Any) – Optional arguments to pass to the class constructor.

Returns:

An instance of the class corresponding to the given class identifier.

Return type:

MasterPiece

classmethod is_abstract()

Check whether the class is abstract or real. Override in the derived sub-classes. The default is False.

Return type:

bool

Returns:

True (bool) if abstract

classmethod log_debug(msg, details='')

Logs the given debug message to the application log.

Parameters:
  • msg (str) – The message to be logged.

  • details (str) – Additional detailed information for the message to be logged

Return type:

None

classmethod log_error(msg, details='')

Logs the given message to the application log.

Parameters:
  • msg (str) – The message to be logged.

  • details (str) – Additional detailed information for the message to be logged

Return type:

None

classmethod log_info(msg, details='')

Logs the given message to the application log.

Parameters:
  • msg (str) – The message to be logged.

  • details (str) – Additional detailed information for the message to be logged

Return type:

None

classmethod log_warning(msg, details='')

Logs the given debug message to the application log.

Parameters:
  • msg (str) – The message to be logged.

  • details (str) – Additional detailed information for the message to be logged

Return type:

None

classmethod register()

Register the class.

Called immediately upon class initialization, right before the class attributes are loaded from the class specific configuration files.

Subclasses can extend this with custom register functionality:

class MyMasterPiece(MasterPiece):

    @classmethod
    def register(cls):
        super().register()  # Don't forget
        cls._custom_field = True
Return type:

None

run()

Run the masterpiece. Dispatches the call to payload object and returns the control to the caller.

Return type:

None

run_forever()

Run the payload forever. This method will return only when violently terminated. If the object does not have playload object, or it is not instance of ‘MasterPiece’ class then returns immediately and this method has no effect.

Return type:

None

classmethod set_log(l)

Set logger.

Parameters:

l (logger) – logger object

Return type:

None

shutdown()

Shutdown the payload object. If the payload object is None, or is not instance of MasterPiece, then the call has no effect.

Return type:

None

to_dict()[source]

Convert instance attributes to a dictionary.

warning(msg, details='')

Logs the given warning message to the application log.

Parameters:
  • msg (str) – The message to be logged.

  • details (str) – Additional detailed information for the message to be logged

Return type:

None