spinetoolbox.project_items.tool.utils

Utility functions for the Tool project item.

author:
  1. Soininen (VTT)
date:

1.4.2020

Module Contents

Classes

_LatestOutputFile A class to hold information on a latest output file.

Functions

flatten_file_path_duplicates(file_paths, logger, log_duplicates=False) Flattens the extra duplicate dimension in file_paths.
file_paths_from_resources(resources) Returns file paths from given resources.
find_file(filename, resources) Returns all occurrences of full paths to given file name in resources available.
find_last_output_files(output_files, output_dir) Returns latest output files.
is_pattern(file_name) Returns True if file_name is actually a file pattern.
spinetoolbox.project_items.tool.utils.flatten_file_path_duplicates(file_paths, logger, log_duplicates=False)[source]

Flattens the extra duplicate dimension in file_paths.

spinetoolbox.project_items.tool.utils.file_paths_from_resources(resources)[source]

Returns file paths from given resources.

Parameters:resources (list) – resources available
Returns:a list of file paths, possibly including patterns
spinetoolbox.project_items.tool.utils.find_file(filename, resources)[source]

Returns all occurrences of full paths to given file name in resources available.

Parameters:
  • filename (str) – Searched file name (no path)
  • resources (list) – list of resources available from upstream items
Returns:

Full paths to file if found, None if not found

Return type:

list

spinetoolbox.project_items.tool.utils.find_last_output_files(output_files, output_dir)[source]

Returns latest output files.

Parameters:
  • output_files (list) – output file patterns from tool specification
  • output_dir (str) – path to the execution output directory
Returns:

a mapping from a file name pattern to the path of the most recent files in the results archive.

Return type:

dict

spinetoolbox.project_items.tool.utils.is_pattern(file_name)[source]

Returns True if file_name is actually a file pattern.

class spinetoolbox.project_items.tool.utils._LatestOutputFile(label, path)[source]

A class to hold information on a latest output file.

label

file label, e.g. file pattern or relative path

Type:str
path

absolute path to the file

Type:str

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

static from_paths(path, archive_dir)[source]

Constructs a _LatestOutputFile object from an absolute path and archive directory.