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.
_specifications(project_dict, project_dir, specification_factories, app_settings, logger) Creates project item specifications.
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.

event(self, e)[source]
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:

a list of executable items, a dict of item specifications, and a DagHandler object

Return type:

tuple

spinetoolbox.headless._specifications(project_dict, project_dir, specification_factories, app_settings, logger)[source]

Creates project item specifications.

Parameters:
  • project_dict (dict) – a serialized project dictionary
  • project_dir (str) – path to a directory containing the .spinetoolbox dir
  • specification_factories (dict) – a mapping from item type to specification factory
  • app_settings (QSettings) – Toolbox settings
  • logger (LoggerInterface) – a logger
Returns:

a mapping from item type and specification name to specification

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]