spinetoolbox.project_items.importer.importer

Contains Importer project item class.

authors:
  1. Savolainen (VTT), P. Vennström (VTT), A. Soininen (VTT)
date:

10.6.2019

Module Contents

spinetoolbox.project_items.importer.importer._CONNECTOR_NAME_TO_CLASS[source]
class spinetoolbox.project_items.importer.importer.Importer(name, description, mappings, x, y, toolbox, project, logger, cancel_on_error=True)[source]

Bases: spinetoolbox.project_item.ProjectItem

Importer class.

Parameters:
  • name (str) – Project item name
  • description (str) – Project item description
  • mappings (list) – List where each element contains two dicts (path dict and mapping dict)
  • x (float) – Initial icon scene X coordinate
  • y (float) – Initial icon scene Y coordinate
  • toolbox (ToolboxUI) – QMainWindow instance
  • project (SpineToolboxProject) – the project this item belongs to
  • logger (LoggerInterface) – a logger instance
  • cancel_on_error (bool) – if True the item’s execution will stop on import error
importing_finished[source]
static item_type()[source]

See base class.

static category()[source]

See base class.

_handle_file_model_item_changed(self, item)[source]
make_signal_handler_dict(self)[source]

Returns a dictionary of all shared signals and their handlers. This is to enable simpler connecting and disconnecting.

_handle_cancel_on_error_changed(self, _state)[source]
set_cancel_on_error(self, cancel_on_error)[source]
restore_selections(self)[source]

Restores selections into shared widgets when this project item is selected.

save_selections(self)[source]

Saves selections in shared widgets for this project item into instance variables.

update_name_label(self)[source]

Update Importer properties tab name label. Used only when renaming project items.

_handle_import_editor_clicked(self, checked=False)[source]

Opens Import editor for the file selected in list view.

_handle_files_double_clicked(self, index)[source]

Opens Import editor for the double clicked index.

open_import_editor(self, index)[source]

Opens Import editor for the given index.

get_connector(self, importee)[source]

Shows a QDialog to select a connector for the given source file. Mimics similar routine in spine_io.widgets.import_widget.ImportDialog

Parameters:importee (str) – Path to file acting as an importee
Returns:Asynchronous data reader class for the given importee
select_connector_type(self, index)[source]

Opens dialog to select connector type for the given index.

_connection_failed(self, msg, importee)[source]
get_settings(self, importee)[source]

Returns the mapping dictionary for the file in given path.

Parameters:importee (str) – Absolute path to a file, whose mapping is queried
Returns:Mapping dictionary for the requested importee or an empty dict if not found
Return type:dict
save_settings(self, settings, importee)[source]
Updates an existing mapping or adds a new mapping
(settings) after closing the import preview window.
Parameters:
  • settings (dict) – Updated mapping (settings) dictionary
  • importee (str) – Absolute path to a file, whose mapping has been updated
_preview_destroyed(self, importee)[source]

Destroys preview widget instance for the given importee.

Parameters:importee (str) – Absolute path to a file, whose preview widget is destroyed
update_file_model(self, items)[source]

Adds given list of items to the file model. If None or an empty list is given, the model is cleared.

Parameters:items (set) – Set of absolute file paths
_prepare_importer_program(self, importer_args)[source]

Prepares an execution manager instance for running importer_process.py in a QProcess.

If app is not frozen, the Python to run it is the python that was used in starting the app.

If app is frozen, we are running the importer_program application found in application install directory.

Parameters:importer_args (list) – Arguments for the importer_program. Source file paths, their mapping specs, URLs downstream, logs directory, cancel_on_error
Returns:True if preparing the program succeeded, False otherwise.
Return type:bool
_handle_importer_program_process_finished(self, exit_code)[source]

Handles the return value from importer program when it has finished. Emits a signal to indicate that this Importer has been executed.

Parameters:exit_code (int) – Process return value. 0: success, !0: failure
python_exists(self, program)[source]

Checks that Python is set up correctly in Settings. This executes ‘python -V’ in a QProcess and if the process finishes successfully, the python is ready to be used.

Parameters:program (str) – Python executable that is currently set in Settings
Returns:True if Python is found, False otherwise
Return type:bool
execute_backward(self, resources)[source]

See base class.

execute_forward(self, resources)[source]

See base class.

stop_execution(self)[source]

Stops executing this Importer.

_do_handle_dag_changed(self, resources)[source]

See base class.

item_dict(self)[source]

Returns a dictionary corresponding to this item.

notify_destination(self, source_item)[source]

See base class.

static default_name_prefix()[source]

see base class

tear_down(self)[source]

Closes all preview widgets.

_notify_if_duplicate_file_paths(self, file_list)[source]

Adds a notification if file_list contains duplicate entries.

static upgrade_from_no_version_to_version_1(item_name, old_item_dict, old_project_dir)[source]

Converts mappings to a list, where each element contains two dictionaries, the serialized path dictionary and the mapping dictionary for the file in that path.

static deserialize_mappings(mappings, project_path)[source]

Returns mapping settings as dict with absolute paths as keys.

Parameters:
  • mappings (list) – List where each element contains two dictionaries (path dict and mapping dict)
  • project_path (str) – Path to project directory
Returns:

Dictionary with absolute paths as keys and mapping settings as values

Return type:

dict

static serialize_mappings(mappings, project_path)[source]

Returns a list of mappings, where each element contains two dictionaries, the ‘serialized’ path in a dictionary and the mapping dictionary.

Parameters:
  • mappings (dict) – Dictionary with mapping specifications
  • project_path (str) – Path to project directory
Returns:

List where each element contains two dictionaries.

Return type:

list

spinetoolbox.project_items.importer.importer._fix_csv_connector_settings(settings)[source]

CSVConnector saved the table names as the filepath, change that to ‘csv’ instead. This function will mutate the dictionary.

Parameters:settings (dict) – Mapping settings that should be updated