spinetoolbox.headless

Contains facilities to open and execute projects without GUI.

Module Contents

Classes

HeadlessLogger

A LoggerInterface compliant logger that uses Python's standard logging facilities.

ModifiableProject

A simple project that is available for modification script.

ActionsWithProject

A 'task' which opens Toolbox project and operates on it.

Status

Status codes returned from headless execution.

Functions

headless_main(args)

Executes a project using QCoreApplication.

open_project(project_dict, project_dir, logger)

Opens a project.

_specification_dicts(project_dict, project_dir, logger)

Loads project item specification dictionaries.

solve_project_dir(pd)

Makes given path object OS independent.

class spinetoolbox.headless.HeadlessLogger[source]

Bases: PySide6.QtCore.QObject

A LoggerInterface compliant logger that uses Python’s standard logging facilities.

msg[source]

Emits a notification message.

msg_success[source]

Emits a message on success

msg_warning[source]

Emits a warning message.

msg_error[source]

Emits an error message.

msg_proc[source]

Emits a message originating from a subprocess (usually something printed to stdout).

msg_proc_error[source]

Emits an error message originating from a subprocess (usually something printed to stderr).

information_box[source]

Requests an ‘information message box’ (e.g. a message window) to be opened with a given title and message.

error_box[source]

Requests an ‘error message box’ to be opened with a given title and message.

_log_message(message)[source]

Prints an information message.

_log_warning(message)[source]

Prints a warning message.

_log_error(message)[source]

Prints an error message.

_show_information_box(title, message)[source]

Prints an information message with a title.

_show_error_box(title, message)[source]

Prints an error message with a title.

_print(message, out_stream)[source]

Filters HTML tags from message before printing it to given file.

class spinetoolbox.headless.ModifiableProject(project_dir, items_dict, connection_dicts)[source]

A simple project that is available for modification script.

Parameters:
  • project_dir (Path) – project directory

  • items_dict (dict) – project item dictionaries

  • connection_dicts (list of dict) – connection dictionaries

property project_dir[source]
find_connection(source_name, destination_name)[source]

Searches for a connection between given items.

Parameters:
  • source_name (str) – source item’s name

  • destination_name (str) – destination item’s name

Returns:

connection instance or None if there is no connection

Return type:

Connection

find_item(name)[source]

Searches for a project item.

Parameters:

name (str) – item’s name

Returns:

item dict or None if no such item exists

Return type:

dict

items_to_dict()[source]

Stores project items back to dictionaries.

Returns:

item dictionaries

Return type:

dict

connections_to_dict()[source]

Stores connections back to dictionaries.

Returns:

connection dictionaries

Return type:

list of dict

class spinetoolbox.headless.ActionsWithProject(args, startup_event_type, parent)[source]

Bases: PySide6.QtCore.QObject

A ‘task’ which opens Toolbox project and operates on it.

The execution of this task is triggered by sending it a ‘startup’ QEvent using e.g. QCoreApplication.postEvent()

Parameters:
  • args (argparse.Namespace) – parsed command line arguments

  • startup_event_type (int) – expected type id for the event that starts this task

  • parent (QObject) – a parent object

_start[source]

A private signal to actually start execution. Not to be used directly. Post a startup event instead.

_dags()[source]
_execute()[source]

Executes this task.

_open_project()[source]

Opens a project.

Returns:

status code

Return type:

Status

_check_project_version(project_dict)[source]

Checks project dict version.

Parameters:

project_dict (dict) – project dict

Returns:

status code

Return type:

Status

_exec_mod_script()[source]

Executes project modification script given in command line arguments.

Returns:

status code

Return type:

Status

_execute_project()[source]

Executes all DAGs in a project.

Returns:

status code

Return type:

Status

_process_engine_event(event_type, data)[source]
event(e)[source]
_handle_node_execution_started(data)[source]

Starts collecting messages from given node.

Parameters:

data (dict) – execution start data

_handle_node_execution_finished(data)[source]

Prints messages for finished nodes.

Parameters:

data (dict) – execution end data

_handle_event_msg(data)[source]

Stores event messages for later printing.

Parameters:

data (dict) – event message data

_handle_process_msg(data)[source]

Stores process messages for later printing.

Parameters:

data (dict) – process message data

_handle_standard_execution_msg(data)[source]

Handles standard execution messages.

Currently, these messages are ignored.

Parameters:

data (dict) – execution message data

_handle_persistent_execution_msg(data)[source]

Handles persistent execution messages.

Parameters:

data (dict) – execution message data

_handle_kernel_execution_msg(data)[source]

Handles kernel messages.

Currently, these messages are ignored.

Parameters:

data (dict) – message data

_handle_server_status_msg(data)[source]

Handles received remote execution messages.

_read_server_config()[source]

Reads the user provided server settings file that the client requires to establish connection.

Returns:

Dictionary containing the EngineClient settings or None if the given config file does not exist.

Return type:

dict

_insert_remote_engine_settings(settings)[source]

Inserts remote engine client settings into the settings dictionary that is delivered to the engine.

Parameters:

settings (dict) – Original settings dictionary

Returns:

Settings dictionary containing remote engine client settings

Return type:

dict

_prepare_remote_execution()[source]

If remote execution is enabled, makes an EngineClient for pinging and uploading the project. If ping is successful, the project is uploaded to the server. If the upload is successful, the server responds with a Job id, which is later used by the client to make a ‘start execution’ request.

Returns:

Job id if server is ready for remote execution, empty string if something went wrong

or “1” if local execution is enabled.

Return type:

str

spinetoolbox.headless.headless_main(args)[source]

Executes a project using QCoreApplication.

Parameters:

args (argparser.Namespace) – parsed command line arguments.

Returns:

exit status code; 0 for success, everything else for failure

Return type:

int

spinetoolbox.headless.open_project(project_dict, project_dir, logger)[source]

Opens a project.

Parameters:
  • project_dict (dict) – a serialized project dictionary

  • project_dir (Path) – path to a directory containing the .spinetoolbox dir

  • logger (LoggerInterface) – a logger

Returns:

item dicts, specification dicts, connection dicts, jump dicts and a DagHandler object

Return type:

tuple

spinetoolbox.headless._specification_dicts(project_dict, project_dir, logger)[source]

Loads project item specification dictionaries.

Parameters:
  • project_dict (dict) – a serialized project dictionary

  • project_dir (str) – path to a directory containing the .spinetoolbox dir

  • logger (LoggerInterface) – a logger

Returns:

a mapping from item type to a list of specification dicts

Return type:

dict

spinetoolbox.headless.solve_project_dir(pd)[source]

Makes given path object OS independent.

Parameters:

pd (Path) – Path Object

Returns:

OS independent path as string.

Return type:

str

class spinetoolbox.headless.Status[source]

Bases: enum.IntEnum

Status codes returned from headless execution.

Initialize self. See help(type(self)) for accurate signature.

OK = 0[source]
ERROR = 1[source]
ARGUMENT_ERROR = 2[source]