spinetoolbox.tool_specifications

Contains Tool specification classes.

authors:
  1. Savolainen (VTT), E. Rinne (VTT), M. Marin (KTH)
date:

24.1.2018

Module Contents

spinetoolbox.tool_specifications.CMDLINE_TAG_EDGE = @@[source]
class spinetoolbox.tool_specifications.CmdlineTag[source]
URL[source]
URL_INPUTS[source]
URL_OUTPUTS[source]
OPTIONAL_INPUTS[source]
class spinetoolbox.tool_specifications.ToolSpecification(name, tooltype, path, includes, settings, logger, description=None, inputfiles=None, inputfiles_opt=None, outputfiles=None, cmdline_args=None, execute_in_work=True)[source]

Bases: spinetoolbox.metaobject.MetaObject

Super class for all tool specifications.

Parameters:
  • name (str) – Name of the tool
  • tooltype (str) – Type of Tool (e.g. Python, Julia, ..)
  • path (str) – Path to tool
  • includes (list) – List of files belonging to the tool specification (relative to ‘path’)
  • settings (QSettings) – Toolbox settings
  • logger (LoggerInterface) – a logger instance
  • description (str) – Description of the Tool specification
  • inputfiles (list) – List of required data files
  • inputfiles_opt (list, optional) – List of optional data files (wildcards may be used)
  • outputfiles (list, optional) – List of output files (wildcards may be used)
  • cmdline_args (str, optional) – Tool command line arguments (read from tool definition file)
  • execute_in_work (bool) – Execute in work folder
set_return_code(self, code, description)[source]

Sets a return code and an associated text description for the tool specification.

Parameters:
  • code (int) – Return code
  • description (str) – Description
set_def_path(self, path)[source]

Sets the file path for this tool specification.

Parameters:path (str) – Absolute path to the specification file.
get_def_path(self)[source]

Returns tool specification file path.

static check_definition(data, logger)[source]

Checks that a tool specification contains the required keys and that it is in correct format.

Parameters:
  • data (dict) – Tool specification
  • logger (LoggerInterface) – A logger instance
Returns:

Dictionary or None if there was a problem in the tool definition.

get_cmdline_args(self, optional_input_files, input_urls, output_urls)[source]

Returns tool specification’s command line args as list.

Replaces special tags in arguments:

  • @@optional_inputs@@ expands to a space-separated list of Tool’s optional input files
  • @@url:<Data Store name>@@ expands to the URL provided by a named data store
  • @@url_inputs@@ expands to a space-separated list of Tool’s input database URLs
  • @@url_outputs@@ expands to a space-separated list of Tool’s output database URLs
Parameters:
  • optional_input_files (list) – a list of Tool’s optional input file names
  • input_urls (dict) – a mapping from URL provider (input Data Store name) to URL string
  • output_urls (dict) – a mapping from URL provider (output Data Store name) to URL string
Returns:

a list of expanded command line arguments

Return type:

list

create_tool_instance(self, basedir)[source]

Returns an instance of the tool specification configured to run in the given directory. Needs to be implemented in subclasses.

Parameters:basedir (str) – Path to directory where the instance will run
static split_cmdline_args(arg_string)[source]

Splits a string of command line into a list of tokens.

Things in single (‘’) and double (“”) quotes are kept as single tokens while the quotes themselves are stripped away. Thus, –file=”a long quoted ‘file’ name.txt becomes [“–file=a long quoted ‘file’ name.txt”]

Parameters:arg_string (str) – command line arguments as a string
Returns:a list of tokens
Return type:list
static _expand_tags(args, optional_input_files, input_urls, output_urls)[source]

” Expands first @@ tags found in given list of command line arguments.

Parameters:
  • args (list) – a list of command line arguments
  • optional_input_files (list) – a list of Tool’s optional input file names
  • input_urls (dict) – a mapping from URL provider (input Data Store name) to URL string
  • output_urls (dict) – a mapping from URL provider (output Data Store name) to URL string
Returns:

a boolean flag, if True, indicates that tags were expanded and a list of

expanded command line arguments

Return type:

tuple

class spinetoolbox.tool_specifications.GAMSTool(name, tooltype, path, includes, settings, logger, description=None, inputfiles=None, inputfiles_opt=None, outputfiles=None, cmdline_args=None, execute_in_work=True)[source]

Bases: spinetoolbox.tool_specifications.ToolSpecification

Class for GAMS tool specifications.

Parameters:
  • name (str) – GAMS Tool name
  • tooltype (str) – Tool specification type
  • path (str) – Path to model main file
  • includes (list) – List of files belonging to the tool (relative to ‘path’). # TODO: Change to src_files
  • settings (QSettings) – Toolbox settings
  • logger (LoggerInterface) – a logger instance
  • file in the list is the main GAMS program. (First) –
  • description (str) – GAMS Tool description
  • inputfiles (list) – List of required data files
  • inputfiles_opt (list, optional) – List of optional data files (wildcards may be used)
  • outputfiles (list, optional) – List of output files (wildcards may be used)
  • cmdline_args (str, optional) – GAMS tool command line arguments (read from tool definition file)
__repr__(self)[source]

[OBSOLETE]. Returns instance of this class as a string.

update_gams_options(self, key, value)[source]

[OBSOLETE?] Updates GAMS command line options. Only ‘cerr and ‘logoption’ keywords supported.

Parameters:
  • key (str) – Option name
  • value (int, float) – Option value
static load(path, data, settings, logger)[source]

Creates a GAMSTool according to a tool specification file.

Parameters:
  • path (str) – Base path to tool files
  • data (dict) – Dictionary of tool definitions
  • settings (QSettings) – Toolbox settings
  • logger (LoggerInterface) – A logger instance
Returns:

GAMSTool instance or None if there was a problem in the tool specification file.

create_tool_instance(self, basedir)[source]

Returns an instance of this tool specification that is configured to run in the given directory.

Parameters:basedir (str) – the path to the directory where the instance will run
class spinetoolbox.tool_specifications.JuliaTool(toolbox, name, tooltype, path, includes, settings, logger, description=None, inputfiles=None, inputfiles_opt=None, outputfiles=None, cmdline_args=None, execute_in_work=True)[source]

Bases: spinetoolbox.tool_specifications.ToolSpecification

Class for Julia tool specifications.

Parameters:
  • toolbox (ToolboxUI) – QMainWindow instance
  • name (str) – Julia Tool name
  • tooltype (str) – Tool specification type
  • path (str) – Path to model main file
  • includes (list) – List of files belonging to the tool (relative to ‘path’). # TODO: Change to src_files
  • file in the list is the main Julia program. (First) –
  • settings (QSettings) – Toolbox settings
  • logger (LoggerInterface) – A logger instance
  • description (str) – Julia Tool description
  • inputfiles (list) – List of required data files
  • inputfiles_opt (list, optional) – List of optional data files (wildcards may be used)
  • outputfiles (list, optional) – List of output files (wildcards may be used)
  • cmdline_args (str, optional) – Julia tool command line arguments (read from tool definition file)
__repr__(self)[source]

[OBSOLETE]. Returns instance of this class as a string.

update_julia_options(self, key, value)[source]

[OBSOLETE?] Updates Julia command line options.

Parameters:
  • key (str) – Option name
  • value (int, float) – Option value
static load(toolbox, path, data, settings, logger)[source]

Creates a JuliaTool according to a tool specification file.

Parameters:
  • toolbox (ToolboxUI) – QMainWindow instance
  • path (str) – Base path to tool files
  • data (dict) – Dictionary of tool definitions
  • settings (QSetting) – Toolbox settings
  • logger (LoggerInterface) – A logger instance
Returns:

JuliaTool instance or None if there was a problem in the tool definition file.

create_tool_instance(self, basedir)[source]

Returns an instance of this tool specification that is configured to run in the given directory.

Parameters:basedir (str) – the path to the directory where the instance will run
class spinetoolbox.tool_specifications.PythonTool(toolbox, name, tooltype, path, includes, settings, logger, description=None, inputfiles=None, inputfiles_opt=None, outputfiles=None, cmdline_args=None, execute_in_work=True)[source]

Bases: spinetoolbox.tool_specifications.ToolSpecification

Class for Python tool specifications.

Parameters:
  • toolbox (ToolboxUI) – QMainWindow instance
  • name (str) – Python Tool name
  • tooltype (str) – Tool specification type
  • path (str) – Path to model main file
  • includes (list) – List of files belonging to the tool (relative to ‘path’). # TODO: Change to src_files
  • settings (QSettings) – Toolbox settings
  • logger (LoggerInterface) – A logger instance
  • file in the list is the main Python program. (First) –
  • description (str) – Python Tool description
  • inputfiles (list) – List of required data files
  • inputfiles_opt (list, optional) – List of optional data files (wildcards may be used)
  • outputfiles (list, optional) – List of output files (wildcards may be used)
  • cmdline_args (str, optional) – Python tool command line arguments (read from tool definition file)
__repr__(self)[source]

[OBSOLETE]. Returns instance of this class as a string.

update_python_options(self, key, value)[source]

[OBSOLETE?] Updates Python command line options.

Parameters:
  • key (str) – Option name
  • value (int, float) – Option value
static load(toolbox, path, data, settings, logger)[source]

Creates a PythonTool according to a tool specification file.

Parameters:
  • toolbox (ToolboxUI) – Toolbox main window
  • path (str) – Base path to tool files
  • data (dict) – Dictionary of tool definitions
  • settings (QSettings) – Toolbox settings
  • logger (LoggerInterface) – A logger instance
Returns:

PythonTool instance or None if there was a problem in the tool definition file.

create_tool_instance(self, basedir)[source]

Returns an instance of this tool specification that is configured to run in the given directory.

Parameters:basedir (str) – the path to the directory where the instance will run
class spinetoolbox.tool_specifications.ExecutableTool(name, tooltype, path, includes, settings, logger, description=None, inputfiles=None, inputfiles_opt=None, outputfiles=None, cmdline_args=None, execute_in_work=True)[source]

Bases: spinetoolbox.tool_specifications.ToolSpecification

Class for Executable tool specifications.

Parameters:
  • name (str) – Tool name
  • tooltype (str) – Tool specification type
  • path (str) – Path to main script file
  • includes (list) – List of files belonging to the tool (relative to ‘path’). # TODO: Change to src_files
  • file in the list is the main script file. (First) –
  • settings (QSettings) – Toolbox settings
  • logger (LoggerInterface) – A logger instance
  • description (str) – Tool description
  • inputfiles (list) – List of required data files
  • inputfiles_opt (list, optional) – List of optional data files (wildcards may be used)
  • outputfiles (list, optional) – List of output files (wildcards may be used)
  • cmdline_args (str, optional) – Tool command line arguments (read from tool definition file)
__repr__(self)[source]

[OBSOLETE]. Returns instance of this class as a string.

static load(path, data, settings, logger)[source]

Creates an ExecutableTool according to a tool specification file.

Parameters:
  • path (str) – Base path to tool files
  • data (dict) – Tool specification
  • settings (QSettings) – Toolbox settings
  • logger (LoggerInterface) – A logger instance
Returns:

ExecutableTool instance or None if there was a problem in the tool specification.

create_tool_instance(self, basedir)[source]

Returns an instance of this tool specification that is configured to run in the given directory.

Parameters:basedir (str) – the path to the directory where the instance will run