spinetoolbox.project_items.importer

Importer plugin.

author:
  1. Marin (KTH)
date:

12.9.2019

Package Contents

class spinetoolbox.project_items.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
static item_type()

See base class.

static category()

See base class.

_handle_file_model_item_changed(self, item)
make_signal_handler_dict(self)

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)
set_cancel_on_error(self, cancel_on_error)
restore_selections(self)

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

save_selections(self)

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

update_name_label(self)

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

_handle_import_editor_clicked(self, checked=False)

Opens Import editor for the file selected in list view.

_handle_files_double_clicked(self, index)

Opens Import editor for the double clicked index.

open_import_editor(self, index)

Opens Import editor for the given index.

get_connector(self, importee)

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)

Opens dialog to select connector type for the given index.

_connection_failed(self, msg, importee)
get_settings(self, importee)

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)
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)

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)

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)

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)

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)

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)

See base class.

execute_forward(self, resources)

See base class.

stop_execution(self)

Stops executing this Importer.

_do_handle_dag_changed(self, resources)

See base class.

item_dict(self)

Returns a dictionary corresponding to this item.

notify_destination(self, source_item)

See base class.

static default_name_prefix()

see base class

tear_down(self)

Closes all preview widgets.

_notify_if_duplicate_file_paths(self, file_list)

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)

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)

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)

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

class spinetoolbox.project_items.importer.ImporterIcon(toolbox, x, y, w, h, name)[source]

Bases: spinetoolbox.graphics_items.ProjectItemIcon

Importer icon for the Design View.

Parameters:
  • toolbox (ToolBoxUI) – QMainWindow instance
  • x (float) – Icon x coordinate
  • y (float) – Icon y coordinate
  • w (float) – Width of master icon
  • h (float) – Height of master icon
  • name (str) – Item name
class spinetoolbox.project_items.importer.ImporterPropertiesWidget(toolbox)[source]

Bases: PySide2.QtWidgets.QWidget

Widget for the Importer Item Properties.

Parameters:toolbox (ToolboxUI) – The toolbox instance where this widget should be embedded
connect_signals(self)

Connect signals to slots.

show_files_context_menu(self, pos)

Create and show a context-menu in Importer properties source files view.

Parameters:pos (QPoint) – Mouse position
class spinetoolbox.project_items.importer.AddImporterWidget(toolbox, x, y)[source]

Bases: spinetoolbox.widgets.add_project_item_widget.AddProjectItemWidget

A widget to query user’s preferences for a new item.

Parameters:
  • toolbox (ToolboxUI) – Parent widget
  • x (float) – X coordinate of new item
  • y (float) – Y coordinate of new item
call_add_item(self)

Creates new Item according to user’s selections.

spinetoolbox.project_items.importer.item_rank = 4[source]
spinetoolbox.project_items.importer.item_category[source]
spinetoolbox.project_items.importer.item_type[source]
spinetoolbox.project_items.importer.item_icon = :/icons/project_item_icons/database-import.svg[source]
spinetoolbox.project_items.importer.item_maker[source]
spinetoolbox.project_items.importer.icon_maker[source]
spinetoolbox.project_items.importer.properties_widget_maker[source]
spinetoolbox.project_items.importer.add_form_maker[source]