spinetoolbox.headless

Contains facilities to open and execute projects without GUI.

authors
  1. Soininen (VTT)

date

29.4.2020

Module Contents

Classes

HeadlessLogger

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

ExecuteProject

A ‘task’ which opens and executes a Toolbox project when triggered to do so.

_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.

class spinetoolbox.headless.HeadlessLogger[source]

Bases: PySide2.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(self, message)[source]

Writes an information message to Python’s logging system.

_log_warning(self, message)[source]

Writes a warning message to Python’s logging system.

_log_error(self, message)[source]

Writes an error message to Python’s logging system.

_show_information_box(self, title, message)[source]

Writes an information message with a title to Python’s logging system.

_show_error_box(self, title, message)[source]

Writes an error message with a title to Python’s logging system.

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

Bases: PySide2.QtCore.QObject

A ‘task’ which opens and executes a Toolbox project when triggered to do so.

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.

_execute(self)[source]

Executes this task.

_open_and_execute_project(self)[source]

Opens a project and executes all DAGs in that project.

Returns

status code

Return type

_Status

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

Starts collecting messages from given node.

Parameters

data (dict) – execution start data

_handle_node_execution_finished(self, data)[source]

Prints messages for finished nodes.

Parameters

data (dict) – execution end data

_handle_event_msg(self, data)[source]

Stores event messages for later printing.

Parameters

data (dict) – event message data

_handle_process_msg(self, data)[source]

Stores process messages for later printing.

Parameters

data (dict) – process message data

_handle_standard_execution_msg(self, data)[source]

Handles standard execution messages.

Currently, these messages are ignored.

Parameters

data (dict) – execution message data

_handle_kernel_execution_msg(self, data)[source]

Handles kernel messages.

Currently, these messages are ignored.

Parameters

data (dict) – execution message data

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 (str) – path to a directory containing the .spinetoolbox dir

  • logger (LoggerInterface) – a logger

Returns

item dicts, specification dicts, connection 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

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]