utilities.GeneralUtils module

class utilities.GeneralUtils.GeneralUtils[source]

Bases: object

This class contains some general utils to ben used by any module.

static configure_logging()[source]

This method configures the logging to be used by all modules. It specifies different colors to improve the readability of the console and adds new levels to the printouts related to ACL and interaction messages.

class ColoredFormatter(fmt=None, datefmt=None, style='%', validate=True, *, defaults=None)[source]

Bases: Formatter

This class contains the format of all the levels of the logging, including the color of each of them.

FORMAT_SIMPLE = '%(asctime)s [%(name)s] [%(levelname)s] %(message)s'
FORMAT_COMPLEX = '%(asctime)s [%(name)s] [%(levelname)s] %(message)s line:%(lineno)d'
RESET = '\x1b[0m'
COLORS = {10: '\x1b[94m%(asctime)s [%(name)s] [%(levelname)s] %(message)s\x1b[0m', 20: '\x1b[39;20m%(asctime)s [%(name)s] [%(levelname)s] %(message)s\x1b[0m', 30: '\x1b[93m%(asctime)s [%(name)s] [%(levelname)s] %(message)s line:%(lineno)d\x1b[0m', 35: '\x1b[38;2;255;150;20m%(asctime)s [%(name)s] [%(levelname)s] %(message)s\x1b[0m', 36: '\x1b[38;2;0;255;255m%(asctime)s [%(name)s] [%(levelname)s] %(message)s\x1b[0m', 40: '\x1b[91m%(asctime)s [%(name)s] [%(levelname)s] %(message)s line:%(lineno)d\x1b[0m', 50: '\x1b[41m%(asctime)s [%(name)s] [%(levelname)s] %(message)s line:%(lineno)d\x1b[0m'}
format(record)[source]

Format the specified record as text.

The record’s attribute dictionary is used as the operand to a string formatting operation which yields the returned string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using LogRecord.getMessage(). If the formatting string uses the time (as determined by a call to usesTime(), formatTime() is called to format the event time. If there is exception information, it is formatted using formatException() and appended to the message.

static create_acl_template(performative, ontology)[source]

This method creates a template aligned with FIPA-ACL standard.

Parameters:
  • performative (str) – The performative of the template.

  • ontology (str) – The ontology of the template.

Returns:

a SPADE template object.

Return type:

spade.template.Template

static create_acl_msg(receiver, thread, performative, ontology, body)[source]

This method creates an FIPA-ACL message.

Parameters:
  • receiver (str) – The SPADE agent receiver of the ACL message.

  • thread (str) – The thread of the ACL message.:

  • performative (str) – The performative of the ACL message.

  • ontology (str) – The ontology of the ACL message.

  • body – The body of the ACL message.

Returns:

SPADE message object FIPA-ACL-compliant.

Return type:

spade.message.Message

static get_current_timestamp()[source]

This method returns the current timestamp of the AAS Manager.

Returns:

current timestamp in milliseconds

Return type:

int