smia.utilities.general_utils module¶
- class smia.utilities.general_utils.GeneralUtils[source]¶
Bases:
objectThis 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:
FormatterThis 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 print_smia_banner()[source]¶
This method prints the SMIA banner as a string. The banner has been created with Python ‘art’ library.
- static update_aas_model(new_aas_model_file)[source]¶
This method updates the AAS model file defined for the SMIA. It updates the global variable for the AAS model file name and the value within the properties file of the SMIA Archive.
- Parameters:
new_aas_model_file (str) – name of the file of the new AAS model to update SMIA.
- 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_sender_from_acl_msg(acl_msg)[source]¶
This method returns the identifier of an agent from an ACL message, considering the suffixes that can be added by the XMPP server.
- Parameters:
acl_msg (spade.message.Message) – ACL message object.
- Returns:
identifier of the sender of the message.
- Return type:
str
- class smia.utilities.general_utils.CLIUtils[source]¶
Bases:
objectThis class contains utility methods related to the Command Line Interface.
- static get_information_from_cli(cli_args)[source]¶
This method gets all the information from the Command Line Interface (CLI). This information includes the initial configuration properties or the AAS model or. None of them is mandatory, but they must be consistent (i.e., if only the AAS model is offered, it must be an AASX which include the configuration file).
- Parameters:
cli_args (list) – arguments of the command line interface
- Returns:
init_config, aas_model and ontology values (None if not specified).
- Return type:
str, str, str
- static check_and_save_cli_information(init_config, aas_model)[source]¶
This method checks the information added in the CLI and, depending on the result of the check, it gets the necessary information and saves it in the appropriate variable.
- Parameters:
init_config (str) – path to the initialization configuration properties file.
aas_model (str) – path to the AAS model file.