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=None, ontology=None, thread=None, protocol=None)[source]¶
This method creates a template aligned with FIPA-ACL standard.
- Parameters:
performative (str) – The performative of the ACL message template.
ontology (str) – The ontology of the ACL message template.
thread (str) – The thread of the ACL message template.
protocol (str) – The protocol of the ACL message 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 SMIA.
- Returns:
current timestamp in milliseconds
- Return type:
int
- static get_current_timestamp_microsecs()[source]¶
This method returns the current timestamp of the SMIA in microseconds.
- Returns:
current timestamp in microseconds
- Return type:
int
- 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, aas_id)[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.
- class smia.utilities.general_utils.DockerUtils[source]¶
Bases:
objectThis class contains utility methods related to SMIA execution in Docker containers.
- static get_aas_model_from_env_var()[source]¶
This method returns the AAS model path, obtained from the required ‘AAS_MODEL_NAME’ environmental variable.
- Returns:
path to the AAS model to be loaded.
- Return type:
str
- static get_aas_id_from_env_var()[source]¶
This method returns the AAS identifier, obtained from the required ‘AAS_ID’ environmental variable.
- Returns:
path to the AAS model to be loaded.
- Return type:
str